You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Glog.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (C) 2010, Robin Rosenberg <robin.rosenberg@dewire.com>
  3. * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> and others
  4. *
  5. * This program and the accompanying materials are made available under the
  6. * terms of the Eclipse Distribution License v. 1.0 which is available at
  7. * https://www.eclipse.org/org/documents/edl-v10.php.
  8. *
  9. * SPDX-License-Identifier: BSD-3-Clause
  10. */
  11. package org.eclipse.jgit.pgm;
  12. import java.awt.BorderLayout;
  13. import java.awt.FlowLayout;
  14. import java.awt.event.ActionEvent;
  15. import java.awt.event.WindowAdapter;
  16. import java.awt.event.WindowEvent;
  17. import java.io.File;
  18. import javax.swing.JButton;
  19. import javax.swing.JFrame;
  20. import javax.swing.JPanel;
  21. import javax.swing.JScrollPane;
  22. import org.eclipse.jgit.awtui.CommitGraphPane;
  23. import org.eclipse.jgit.lib.Constants;
  24. import org.eclipse.jgit.pgm.internal.CLIText;
  25. import org.eclipse.jgit.revplot.PlotWalk;
  26. import org.eclipse.jgit.revwalk.RevCommit;
  27. import org.eclipse.jgit.revwalk.RevSort;
  28. import org.eclipse.jgit.revwalk.RevWalk;
  29. @Command(usage = "usage_Glog")
  30. class Glog extends RevWalkTextBuiltin {
  31. final JFrame frame;
  32. final CommitGraphPane graphPane;
  33. Glog() {
  34. frame = new JFrame();
  35. frame.addWindowListener(new WindowAdapter() {
  36. @Override
  37. public void windowClosing(WindowEvent e) {
  38. frame.dispose();
  39. }
  40. });
  41. graphPane = new CommitGraphPane();
  42. final JScrollPane graphScroll = new JScrollPane(graphPane);
  43. final JPanel buttons = new JPanel(new FlowLayout());
  44. final JButton repaint = new JButton();
  45. repaint.setText(CLIText.get().repaint);
  46. repaint.addActionListener((ActionEvent e) -> {
  47. graphPane.repaint();
  48. });
  49. buttons.add(repaint);
  50. final JPanel world = new JPanel(new BorderLayout());
  51. world.add(buttons, BorderLayout.SOUTH);
  52. world.add(graphScroll, BorderLayout.CENTER);
  53. frame.getContentPane().add(world);
  54. }
  55. /** {@inheritDoc} */
  56. @Override
  57. protected int walkLoop() throws Exception {
  58. graphPane.getCommitList().source(walk);
  59. graphPane.getCommitList().fillTo(Integer.MAX_VALUE);
  60. frame.setTitle("[" + repoName() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
  61. frame.pack();
  62. frame.setVisible(true);
  63. return graphPane.getCommitList().size();
  64. }
  65. /** {@inheritDoc} */
  66. @Override
  67. protected void show(RevCommit c) throws Exception {
  68. throw new UnsupportedOperationException();
  69. }
  70. /** {@inheritDoc} */
  71. @Override
  72. protected RevWalk createWalk() {
  73. if (objects)
  74. throw die(CLIText.get().cannotUseObjectsWithGlog);
  75. final PlotWalk w = new PlotWalk(db);
  76. w.sort(RevSort.BOUNDARY, true);
  77. return w;
  78. }
  79. private String repoName() {
  80. final File gitDir = db.getDirectory();
  81. if (gitDir == null)
  82. return db.toString();
  83. String n = gitDir.getName();
  84. if (Constants.DOT_GIT.equals(n))
  85. n = gitDir.getParentFile().getName();
  86. return n;
  87. }
  88. }