1
2
3
4
5
6
7
8
9
10
11
12
13 package org.eclipse.jgit.pgm;
14
15 import java.io.IOException;
16 import java.util.List;
17
18 import org.eclipse.jgit.lib.AnyObjectId;
19 import org.eclipse.jgit.lib.Ref;
20 import org.eclipse.jgit.lib.RefComparator;
21
22 @Command(usage = "usage_ShowRef")
23 class ShowRef extends TextBuiltin {
24
25 @Override
26 protected void run() {
27 try {
28 for (Ref r : getSortedRefs()) {
29 show(r.getObjectId(), r.getName());
30 if (r.getPeeledObjectId() != null) {
31 show(r.getPeeledObjectId(), r.getName() + "^{}");
32 }
33 }
34 } catch (IOException e) {
35 throw die(e.getMessage(), e);
36 }
37 }
38
39 private Iterable<Ref> getSortedRefs() throws IOException {
40 List<Ref> all = db.getRefDatabase().getRefs();
41
42
43 return RefComparator.sort(all);
44 }
45
46 private void show(AnyObjectId id, String name)
47 throws IOException {
48 outw.print(id.name());
49 outw.print('\t');
50 outw.print(name);
51 outw.println();
52 }
53 }