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