comparison cmdline/org/tmatesoft/hg/console/Main.java @ 354:5f9073eabf06

Propagate errors with exceptions up to a end client
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 01 Dec 2011 05:21:40 +0100
parents 33eaed1ad130
children 150500515714
comparison
equal deleted inserted replaced
353:0f3687e79f5a 354:5f9073eabf06
27 import java.util.List; 27 import java.util.List;
28 import java.util.Map; 28 import java.util.Map;
29 29
30 import org.junit.Assert; 30 import org.junit.Assert;
31 import org.tmatesoft.hg.core.HgBadStateException; 31 import org.tmatesoft.hg.core.HgBadStateException;
32 import org.tmatesoft.hg.core.HgCallbackTargetException;
32 import org.tmatesoft.hg.core.HgCatCommand; 33 import org.tmatesoft.hg.core.HgCatCommand;
33 import org.tmatesoft.hg.core.HgChangeset; 34 import org.tmatesoft.hg.core.HgChangeset;
34 import org.tmatesoft.hg.core.HgChangesetTreeHandler; 35 import org.tmatesoft.hg.core.HgChangesetTreeHandler;
35 import org.tmatesoft.hg.core.HgDataStreamException; 36 import org.tmatesoft.hg.core.HgDataStreamException;
37 import org.tmatesoft.hg.core.HgException;
36 import org.tmatesoft.hg.core.HgFileInformer; 38 import org.tmatesoft.hg.core.HgFileInformer;
37 import org.tmatesoft.hg.core.HgFileRevision; 39 import org.tmatesoft.hg.core.HgFileRevision;
38 import org.tmatesoft.hg.core.HgLogCommand; 40 import org.tmatesoft.hg.core.HgLogCommand;
39 import org.tmatesoft.hg.core.HgManifestCommand; 41 import org.tmatesoft.hg.core.HgManifestCommand;
40 import org.tmatesoft.hg.core.Nodeid; 42 import org.tmatesoft.hg.core.Nodeid;
115 117
116 private void buildFileLog() throws Exception { 118 private void buildFileLog() throws Exception {
117 HgLogCommand cmd = new HgLogCommand(hgRepo); 119 HgLogCommand cmd = new HgLogCommand(hgRepo);
118 cmd.file("file1", false); 120 cmd.file("file1", false);
119 cmd.execute(new HgChangesetTreeHandler() { 121 cmd.execute(new HgChangesetTreeHandler() {
120 public void next(org.tmatesoft.hg.core.HgChangesetTreeHandler.TreeElement entry) { 122 public void next(HgChangesetTreeHandler.TreeElement entry) {
121 StringBuilder sb = new StringBuilder(); 123 StringBuilder sb = new StringBuilder();
122 HashSet<Nodeid> test = new HashSet<Nodeid>(entry.childRevisions()); 124 HashSet<Nodeid> test = new HashSet<Nodeid>(entry.childRevisions());
123 for (HgChangeset cc : entry.children()) { 125 for (HgChangeset cc : entry.children()) {
124 sb.append(cc.getRevision()); 126 sb.append(cc.getRevision());
125 sb.append(':'); 127 sb.append(':');
506 } 508 }
507 public void dir(Path p) { 509 public void dir(Path p) {
508 System.out.println(p); 510 System.out.println(p);
509 } 511 }
510 public void file(HgFileRevision fileRevision) { 512 public void file(HgFileRevision fileRevision) {
511 System.out.print(fileRevision.getRevision());; 513 try {
512 System.out.print(" "); 514 System.out.print(fileRevision.getRevision());;
513 System.out.printf("%s %s", fileRevision.getParents().first().shortNotation(), fileRevision.getParents().second().shortNotation()); 515 System.out.print(" ");
514 System.out.print(" "); 516 System.out.printf("%s %s", fileRevision.getParents().first().shortNotation(), fileRevision.getParents().second().shortNotation());
515 System.out.println(fileRevision.getPath()); 517 System.out.print(" ");
518 System.out.println(fileRevision.getPath());
519 } catch (HgException ex) {
520 throw new HgCallbackTargetException.Wrap(ex);
521 }
516 } 522 }
517 523
518 public void end(Nodeid manifestRevision) { 524 public void end(Nodeid manifestRevision) {
519 System.out.println(); 525 System.out.println();
520 } 526 }
568 } 574 }
569 } 575 }
570 } 576 }
571 577
572 578
573 private void testStatusInternals() throws HgDataStreamException { 579 private void testStatusInternals() throws HgException {
574 HgDataFile n = hgRepo.getFileNode(Path.create("design.txt")); 580 HgDataFile n = hgRepo.getFileNode(Path.create("design.txt"));
575 for (String s : new String[] {"011dfd44417c72bd9e54cf89b82828f661b700ed", "e5529faa06d53e06a816e56d218115b42782f1ba", "c18e7111f1fc89a80a00f6a39d51288289a382fc"}) { 581 for (String s : new String[] {"011dfd44417c72bd9e54cf89b82828f661b700ed", "e5529faa06d53e06a816e56d218115b42782f1ba", "c18e7111f1fc89a80a00f6a39d51288289a382fc"}) {
576 // expected: 359, 2123, 3079 582 // expected: 359, 2123, 3079
577 byte[] b = s.getBytes(); 583 byte[] b = s.getBytes();
578 final Nodeid nid = Nodeid.fromAscii(b, 0, b.length); 584 final Nodeid nid = Nodeid.fromAscii(b, 0, b.length);