1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.pgm;
11
12 import static org.eclipse.jgit.lib.Constants.OBJECT_ID_ABBREV_STRING_LENGTH;
13
14 import java.io.IOException;
15 import java.util.Collection;
16
17 import org.eclipse.jgit.api.Git;
18 import org.eclipse.jgit.api.ReflogCommand;
19 import org.eclipse.jgit.api.errors.GitAPIException;
20 import org.eclipse.jgit.lib.Constants;
21 import org.eclipse.jgit.lib.ReflogEntry;
22 import org.eclipse.jgit.lib.Repository;
23 import org.kohsuke.args4j.Argument;
24
25 @Command(common = true, usage = "usage_manageReflogInformation")
26 class Reflog extends TextBuiltin {
27
28 @Argument(metaVar = "metaVar_ref")
29 private String ref;
30
31
32 @Override
33 protected void run() {
34 try (Git git = new Git(db)) {
35 ReflogCommand cmd = git.reflog();
36 if (ref != null)
37 cmd.setRef(ref);
38 Collection<ReflogEntry> entries = cmd.call();
39 int i = 0;
40 for (ReflogEntry entry : entries) {
41 outw.println(toString(entry, i++));
42 }
43 } catch (GitAPIException | IOException e) {
44 throw die(e.getMessage(), e);
45 }
46 }
47
48 private String toString(ReflogEntry entry, int i) {
49 final StringBuilder s = new StringBuilder();
50 s.append(entry.getNewId().abbreviate(OBJECT_ID_ABBREV_STRING_LENGTH)
51 .name());
52 s.append(" ");
53 s.append(ref == null ? Constants.HEAD : Repository.shortenRefName(ref));
54 s.append("@{" + i + "}:");
55 s.append(" ");
56 s.append(entry.getComment());
57 return s.toString();
58 }
59 }