Mercurial > jhg
comparison src/com/tmate/hgkit/console/Log.java @ 47:b01500fe2604
Log command output to match 'hg log'
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 14 Jan 2011 20:03:14 +0100 |
parents | a78c980749e3 |
children | e34f90b9ded1 |
comparison
equal
deleted
inserted
replaced
46:4022c34a4804 | 47:b01500fe2604 |
---|---|
1 /** | 1 /* |
2 * Copyright (c) 2010 Artem Tikhomirov | 2 * Copyright (c) 2010, 2011 Artem Tikhomirov |
3 */ | 3 */ |
4 package com.tmate.hgkit.console; | 4 package com.tmate.hgkit.console; |
5 | |
6 import java.util.Formatter; | |
7 import java.util.LinkedList; | |
8 import java.util.List; | |
5 | 9 |
6 import com.tmate.hgkit.fs.RepositoryLookup; | 10 import com.tmate.hgkit.fs.RepositoryLookup; |
7 import com.tmate.hgkit.ll.Changeset; | 11 import com.tmate.hgkit.ll.Changeset; |
8 import com.tmate.hgkit.ll.HgDataFile; | 12 import com.tmate.hgkit.ll.HgDataFile; |
9 import com.tmate.hgkit.ll.HgRepository; | 13 import com.tmate.hgkit.ll.HgRepository; |
14 import com.tmate.hgkit.ll.Nodeid; | |
10 | 15 |
11 /** | 16 /** |
12 * @author artem | 17 * @author artem |
13 */ | 18 */ |
14 public class Log { | 19 public class Log { |
20 if (hgRepo.isInvalid()) { | 25 if (hgRepo.isInvalid()) { |
21 System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); | 26 System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation()); |
22 return; | 27 return; |
23 } | 28 } |
24 System.out.println(hgRepo.getLocation()); | 29 System.out.println(hgRepo.getLocation()); |
25 final Changeset.Inspector callback = new Changeset.Inspector() { | 30 final Dump dump = new Dump(hgRepo); |
26 | 31 dump.complete = false; //cmdLineOpts; |
27 public void next(Changeset cset) { | 32 dump.reverseOrder = true; |
28 System.out.println("==>"); | |
29 cset.dump(); | |
30 } | |
31 }; | |
32 if (cmdLineOpts.files.isEmpty()) { | 33 if (cmdLineOpts.files.isEmpty()) { |
33 System.out.println("Complete history of the repo:"); | 34 // no revisions and no limit |
34 hgRepo.getChangelog().all(callback); | 35 hgRepo.getChangelog().all(dump); |
36 dump.complete(); | |
35 } else { | 37 } else { |
36 for (String fname : cmdLineOpts.files) { | 38 for (String fname : cmdLineOpts.files) { |
37 HgDataFile f1 = hgRepo.getFileNode(fname); | 39 HgDataFile f1 = hgRepo.getFileNode(fname); |
38 System.out.println("History of the file: " + f1.getPath()); | 40 System.out.println("History of the file: " + f1.getPath()); |
39 f1.history(callback); | 41 f1.history(dump); |
42 dump.complete(); | |
40 } | 43 } |
41 } | 44 } |
42 // | 45 // |
43 // System.out.println("\n\n========================="); | 46 // System.out.println("\n\n========================="); |
44 // System.out.println("Range 1-3:"); | 47 // System.out.println("Range 1-3:"); |
45 // f1.history(1,3, callback); | 48 // f1.history(1,3, callback); |
46 // | 49 // |
47 //new ChangelogWalker().setFile("hello.c").setRevisionRange(1, 4).accept(new Visitor); | 50 //new ChangelogWalker().setFile("hello.c").setRevisionRange(1, 4).accept(new Visitor); |
48 } | 51 } |
52 | |
53 private static final class Dump implements Changeset.Inspector { | |
54 // params | |
55 boolean complete = false; | |
56 boolean reverseOrder = false; | |
57 // own | |
58 private LinkedList<String> l = new LinkedList<String>(); | |
59 private final HgRepository repo; | |
60 | |
61 public Dump(HgRepository hgRepo) { | |
62 this.repo = hgRepo; | |
63 } | |
64 | |
65 public void next(int revisionNumber, Nodeid nodeid, Changeset cset) { | |
66 final String s = print(revisionNumber, nodeid, cset); | |
67 if (reverseOrder) { | |
68 l.addFirst(s); | |
69 } else { | |
70 System.out.print(s); | |
71 } | |
72 } | |
73 | |
74 public void complete() { | |
75 if (!reverseOrder) { | |
76 return; | |
77 } | |
78 for (String s : l) { | |
79 System.out.print(s); | |
80 } | |
81 l.clear(); | |
82 } | |
83 | |
84 private String print(int revNumber, Nodeid csetNodeid, Changeset cset) { | |
85 StringBuilder sb = new StringBuilder(); | |
86 Formatter f = new Formatter(sb); | |
87 f.format("changeset: %d:%s\n", revNumber, complete ? csetNodeid : csetNodeid.shortNotation()); | |
88 if (complete) { | |
89 f.format("parent: %s\nparent: %s\nmanifest: %s", "-1", "-1", cset.manifest()); | |
90 } | |
91 f.format("user: %s\ndate: %s\n", cset.user(), cset.dateString()); | |
92 if (complete) { | |
93 final List<String> files = cset.files(); | |
94 sb.append("files: "); | |
95 for (String s : files) { | |
96 sb.append(' '); | |
97 sb.append(s); | |
98 } | |
99 f.format("description:\n%s\n\n", cset.comment()); | |
100 } else { | |
101 f.format("summary: %s\n\n", cset.comment()); | |
102 } | |
103 if (cset.extras() != null) { | |
104 f.format("extra: " + cset.extras()); // TODO | |
105 } | |
106 return sb.toString(); | |
107 } | |
108 } | |
49 } | 109 } |