comparison cmdline/org/tmatesoft/hg/console/Main.java @ 366:189dc6dc1c3e

Use exceptions to expose errors reading mercurial data
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 16 Dec 2011 04:43:18 +0100
parents 4937e35b805b
children 2fadf8695f8a
comparison
equal deleted inserted replaced
365:3572fcb06473 366:189dc6dc1c3e
118 private void buildFileLog() throws Exception { 118 private void buildFileLog() throws Exception {
119 HgLogCommand cmd = new HgLogCommand(hgRepo); 119 HgLogCommand cmd = new HgLogCommand(hgRepo);
120 cmd.file("file1", false); 120 cmd.file("file1", false);
121 cmd.execute(new HgChangesetTreeHandler() { 121 cmd.execute(new HgChangesetTreeHandler() {
122 public void next(HgChangesetTreeHandler.TreeElement entry) { 122 public void next(HgChangesetTreeHandler.TreeElement entry) {
123 StringBuilder sb = new StringBuilder(); 123 try {
124 HashSet<Nodeid> test = new HashSet<Nodeid>(entry.childRevisions()); 124 StringBuilder sb = new StringBuilder();
125 for (HgChangeset cc : entry.children()) { 125 HashSet<Nodeid> test = new HashSet<Nodeid>(entry.childRevisions());
126 sb.append(cc.getRevision()); 126 for (HgChangeset cc : entry.children()) {
127 sb.append(':'); 127 sb.append(cc.getRevision());
128 sb.append(cc.getNodeid().shortNotation()); 128 sb.append(':');
129 sb.append(", "); 129 sb.append(cc.getNodeid().shortNotation());
130 sb.append(", ");
131 }
132 final Pair<Nodeid, Nodeid> parents = entry.parentRevisions();
133 final boolean isJoin = !parents.first().isNull() && !parents.second().isNull();
134 final boolean isFork = entry.children().size() > 1;
135 final HgChangeset cset = entry.changeset();
136 System.out.printf("%d:%s - %s\n", cset.getRevision(), cset.getNodeid().shortNotation(), cset.getComment());
137 if (!isJoin && !isFork && !entry.children().isEmpty()) {
138 System.out.printf("\t=> %s\n", sb);
139 }
140 if (isJoin) {
141 HgChangeset p1 = entry.parents().first();
142 HgChangeset p2 = entry.parents().second();
143 System.out.printf("\tjoin <= (%d:%s, %d:%s)", p1.getRevision(), p1.getNodeid().shortNotation(), p2.getRevision(), p2.getNodeid().shortNotation());
144 if (isFork) {
145 System.out.print(", ");
146 }
147 }
148 if (isFork) {
149 if (!isJoin) {
150 System.out.print('\t');
151 }
152 System.out.printf("fork => [%s]", sb);
153 }
154 if (isJoin || isFork) {
155 System.out.println();
156 }
157 } catch (HgException ex) {
158 ex.printStackTrace();
130 } 159 }
131 final Pair<Nodeid, Nodeid> parents = entry.parentRevisions();
132 final boolean isJoin = !parents.first().isNull() && !parents.second().isNull();
133 final boolean isFork = entry.children().size() > 1;
134 final HgChangeset cset = entry.changeset();
135 System.out.printf("%d:%s - %s\n", cset.getRevision(), cset.getNodeid().shortNotation(), cset.getComment());
136 if (!isJoin && !isFork && !entry.children().isEmpty()) {
137 System.out.printf("\t=> %s\n", sb);
138 }
139 if (isJoin) {
140 HgChangeset p1 = entry.parents().first();
141 HgChangeset p2 = entry.parents().second();
142 System.out.printf("\tjoin <= (%d:%s, %d:%s)", p1.getRevision(), p1.getNodeid().shortNotation(), p2.getRevision(), p2.getNodeid().shortNotation());
143 if (isFork) {
144 System.out.print(", ");
145 }
146 }
147 if (isFork) {
148 if (!isJoin) {
149 System.out.print('\t');
150 }
151 System.out.printf("fork => [%s]", sb);
152 }
153 if (isJoin || isFork) {
154 System.out.println();
155 }
156 } 160 }
157 }); 161 });
158 } 162 }
159 163
160 private void buildFileLogOld() { 164 private void buildFileLogOld() throws Exception {
161 final HgDataFile fn = hgRepo.getFileNode("file1"); 165 final HgDataFile fn = hgRepo.getFileNode("file1");
162 final int[] fileChangesetRevisions = new int[fn.getRevisionCount()]; 166 final int[] fileChangesetRevisions = new int[fn.getRevisionCount()];
163 fn.history(new HgChangelog.Inspector() { 167 fn.history(new HgChangelog.Inspector() {
164 private int fileLocalRevisions = 0; 168 private int fileLocalRevisions = 0;
165 private int[] parentRevisions = new int[2]; 169 private int[] parentRevisions = new int[2];
166 170
167 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) { 171 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
168 fileChangesetRevisions[fileLocalRevisions] = revisionNumber; 172 try {
169 fn.parents(fileLocalRevisions, parentRevisions, null, null); 173 fileChangesetRevisions[fileLocalRevisions] = revisionNumber;
170 boolean join = parentRevisions[0] != -1 && parentRevisions[1] != -1; 174 fn.parents(fileLocalRevisions, parentRevisions, null, null);
171 if (join) { 175 boolean join = parentRevisions[0] != -1 && parentRevisions[1] != -1;
172 System.out.print("join["); 176 if (join) {
177 System.out.print("join[");
178 }
179 if (parentRevisions[0] != -1) {
180 System.out.printf("%2d->%2d, ", fileChangesetRevisions[parentRevisions[0]], revisionNumber);
181 }
182 if (parentRevisions[1] != -1) {
183 System.out.printf("%2d->%2d, ", fileChangesetRevisions[parentRevisions[1]], revisionNumber);
184 }
185 if (join) {
186 System.out.print("]");
187 }
188 fileLocalRevisions++;
189 } catch (HgException ex) {
190 ex.printStackTrace();
173 } 191 }
174 if (parentRevisions[0] != -1) {
175 System.out.printf("%2d->%2d, ", fileChangesetRevisions[parentRevisions[0]], revisionNumber);
176 }
177 if (parentRevisions[1] != -1) {
178 System.out.printf("%2d->%2d, ", fileChangesetRevisions[parentRevisions[1]], revisionNumber);
179 }
180 if (join) {
181 System.out.print("]");
182 }
183 fileLocalRevisions++;
184 } 192 }
185 }); 193 });
186 System.out.println(); 194 System.out.println();
187 } 195 }
188 196
305 * with sort (to order revisions from linkRev before use) 610 ms 313 * with sort (to order revisions from linkRev before use) 610 ms
306 * HgChangelog.range() - 92 calls 314 * HgChangelog.range() - 92 calls
307 * RevlogStream with separate iterate(int[] sortedRevisions,...) 315 * RevlogStream with separate iterate(int[] sortedRevisions,...)
308 * RevlogStream.ReaderN1.range(): 185 380 ms 316 * RevlogStream.ReaderN1.range(): 185 380 ms
309 */ 317 */
310 private void testEffectiveFileLog() { 318 private void testEffectiveFileLog() throws Exception {
311 for (String fname : cmdLineOpts.getList("")) { 319 for (String fname : cmdLineOpts.getList("")) {
312 System.out.println(fname); 320 System.out.println(fname);
313 final long start = System.currentTimeMillis(); 321 final long start = System.currentTimeMillis();
314 HgDataFile fn = hgRepo.getFileNode(fname); 322 HgDataFile fn = hgRepo.getFileNode(fname);
315 if (fn.exists()) { 323 if (fn.exists()) {
379 /* 387 /*
380 * Straightforward approach to collect branches, no use of branchheads.cache 388 * Straightforward approach to collect branches, no use of branchheads.cache
381 * First, single run - 18 563 389 * First, single run - 18 563
382 * 10 runs (after 1 warm up) of HgBranches.collect took 167391 ms, ~17 seconds per run. 390 * 10 runs (after 1 warm up) of HgBranches.collect took 167391 ms, ~17 seconds per run.
383 */ 391 */
384 private void dumpBranches() { 392 private void dumpBranches() throws Exception {
385 final long start0 = System.currentTimeMillis(); 393 final long start0 = System.currentTimeMillis();
386 HgBranches b = hgRepo.getBranches(); 394 HgBranches b = hgRepo.getBranches();
387 System.out.println("1:" + (System.currentTimeMillis() - start0)); 395 System.out.println("1:" + (System.currentTimeMillis() - start0));
388 for (HgBranches.BranchInfo bi : b.getAllBranches()) { 396 for (HgBranches.BranchInfo bi : b.getAllBranches()) {
389 System.out.print(bi.getName()); 397 System.out.print(bi.getName());
474 System.out.println(">>>Not found!"); 482 System.out.println(">>>Not found!");
475 } 483 }
476 } 484 }
477 } 485 }
478 486
479 private void dumpCompleteManifestLow() { 487 private void dumpCompleteManifestLow() throws Exception {
480 hgRepo.getManifest().walk(0, TIP, new ManifestDump()); 488 hgRepo.getManifest().walk(0, TIP, new ManifestDump());
481 } 489 }
482 490
483 public static final class ManifestDump implements HgManifest.Inspector2 { 491 public static final class ManifestDump implements HgManifest.Inspector2 {
484 public boolean begin(int manifestRevision, Nodeid nid, int changelogRevision) { 492 public boolean begin(int manifestRevision, Nodeid nid, int changelogRevision) {
498 System.out.println(); 506 System.out.println();
499 return true; 507 return true;
500 } 508 }
501 } 509 }
502 510
503 private void dumpCompleteManifestHigh() { 511 private void dumpCompleteManifestHigh() throws Exception {
504 new HgManifestCommand(hgRepo).dirs(true).execute(new HgManifestCommand.Handler() { 512 new HgManifestCommand(hgRepo).dirs(true).execute(new HgManifestCommand.Handler() {
505 513
506 public void begin(Nodeid manifestRevision) { 514 public void begin(Nodeid manifestRevision) {
507 System.out.println(">> " + manifestRevision); 515 System.out.println(">> " + manifestRevision);
508 } 516 }