comparison src/com/tmate/hgkit/console/Log.java @ 48:e34f90b9ded1

Limit option for history/log
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 14 Jan 2011 23:22:20 +0100
parents b01500fe2604
children 26e3eeaa3962
comparison
equal deleted inserted replaced
47:b01500fe2604 48:e34f90b9ded1
30 final Dump dump = new Dump(hgRepo); 30 final Dump dump = new Dump(hgRepo);
31 dump.complete = false; //cmdLineOpts; 31 dump.complete = false; //cmdLineOpts;
32 dump.reverseOrder = true; 32 dump.reverseOrder = true;
33 if (cmdLineOpts.files.isEmpty()) { 33 if (cmdLineOpts.files.isEmpty()) {
34 // no revisions and no limit 34 // no revisions and no limit
35 hgRepo.getChangelog().all(dump); 35 if (cmdLineOpts.limit == -1) {
36 hgRepo.getChangelog().all(dump);
37 } else {
38 int[] r = new int[] { 0, hgRepo.getChangelog().getRevisionCount() };
39 if (fixRange(r, dump.reverseOrder, cmdLineOpts.limit) == 0) {
40 System.out.println("No changes");
41 return;
42 }
43 hgRepo.getChangelog().range(r[0], r[1], dump);
44 }
36 dump.complete(); 45 dump.complete();
37 } else { 46 } else {
38 for (String fname : cmdLineOpts.files) { 47 for (String fname : cmdLineOpts.files) {
39 HgDataFile f1 = hgRepo.getFileNode(fname); 48 HgDataFile f1 = hgRepo.getFileNode(fname);
40 System.out.println("History of the file: " + f1.getPath()); 49 System.out.println("History of the file: " + f1.getPath());
41 f1.history(dump); 50 if (cmdLineOpts.limit == -1) {
51 f1.history(dump);
52 } else {
53 int[] r = new int[] { 0, f1.getRevisionCount() };
54 if (fixRange(r, dump.reverseOrder, cmdLineOpts.limit) == 0) {
55 System.out.println("No changes");
56 continue;
57 }
58 f1.history(r[0], r[1], dump);
59 }
42 dump.complete(); 60 dump.complete();
43 } 61 }
44 } 62 }
45 // 63 //
46 // System.out.println("\n\n========================="); 64 // System.out.println("\n\n=========================");
47 // System.out.println("Range 1-3:"); 65 // System.out.println("Range 1-3:");
48 // f1.history(1,3, callback); 66 // f1.history(1,3, callback);
49 // 67 //
50 //new ChangelogWalker().setFile("hello.c").setRevisionRange(1, 4).accept(new Visitor); 68 //new ChangelogWalker().setFile("hello.c").setRevisionRange(1, 4).accept(new Visitor);
69 }
70
71 private static int fixRange(int[] start_end, boolean reverse, int limit) {
72 assert start_end.length == 2;
73 if (limit < start_end[1]) {
74 if (reverse) {
75 // adjust left boundary of the range
76 start_end[0] = start_end[1] - limit;
77 } else {
78 start_end[1] = limit; // adjust right boundary
79 }
80 }
81 int rv = start_end[1] - start_end[0];
82 start_end[1]--; // range needs index, not length
83 return rv;
51 } 84 }
52 85
53 private static final class Dump implements Changeset.Inspector { 86 private static final class Dump implements Changeset.Inspector {
54 // params 87 // params
55 boolean complete = false; 88 boolean complete = false;
84 private String print(int revNumber, Nodeid csetNodeid, Changeset cset) { 117 private String print(int revNumber, Nodeid csetNodeid, Changeset cset) {
85 StringBuilder sb = new StringBuilder(); 118 StringBuilder sb = new StringBuilder();
86 Formatter f = new Formatter(sb); 119 Formatter f = new Formatter(sb);
87 f.format("changeset: %d:%s\n", revNumber, complete ? csetNodeid : csetNodeid.shortNotation()); 120 f.format("changeset: %d:%s\n", revNumber, complete ? csetNodeid : csetNodeid.shortNotation());
88 if (complete) { 121 if (complete) {
89 f.format("parent: %s\nparent: %s\nmanifest: %s", "-1", "-1", cset.manifest()); 122 f.format("parent: %s\nparent: %s\nmanifest: %s\n", "-1", "-1", cset.manifest());
90 } 123 }
91 f.format("user: %s\ndate: %s\n", cset.user(), cset.dateString()); 124 f.format("user: %s\ndate: %s\n", cset.user(), cset.dateString());
92 if (complete) { 125 if (complete) {
93 final List<String> files = cset.files(); 126 final List<String> files = cset.files();
94 sb.append("files: "); 127 sb.append("files: ");
95 for (String s : files) { 128 for (String s : files) {
96 sb.append(' '); 129 sb.append(' ');
97 sb.append(s); 130 sb.append(s);
98 } 131 }
99 f.format("description:\n%s\n\n", cset.comment()); 132 f.format("\ndescription:\n%s\n\n", cset.comment());
100 } else { 133 } else {
101 f.format("summary: %s\n\n", cset.comment()); 134 f.format("summary: %s\n\n", cset.comment());
102 } 135 }
103 if (cset.extras() != null) { 136 if (cset.extras() != null) {
104 f.format("extra: " + cset.extras()); // TODO 137 f.format("extra: " + cset.extras()); // TODO