Mercurial > hg4j
comparison cmdline/org/tmatesoft/hg/console/Main.java @ 423:9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 23 Mar 2012 22:51:18 +0100 |
parents | ccd7d25e5aea |
children | 6437d261048a |
comparison
equal
deleted
inserted
replaced
422:5d1cc7366d04 | 423:9c9c442b5f2e |
---|---|
26 import java.util.HashSet; | 26 import java.util.HashSet; |
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; | |
32 import org.tmatesoft.hg.core.HgCallbackTargetException; | 31 import org.tmatesoft.hg.core.HgCallbackTargetException; |
33 import org.tmatesoft.hg.core.HgCatCommand; | 32 import org.tmatesoft.hg.core.HgCatCommand; |
34 import org.tmatesoft.hg.core.HgChangeset; | 33 import org.tmatesoft.hg.core.HgChangeset; |
35 import org.tmatesoft.hg.core.HgChangesetFileSneaker; | 34 import org.tmatesoft.hg.core.HgChangesetFileSneaker; |
36 import org.tmatesoft.hg.core.HgChangesetTreeHandler; | 35 import org.tmatesoft.hg.core.HgChangesetTreeHandler; |
55 import org.tmatesoft.hg.repo.HgInternals; | 54 import org.tmatesoft.hg.repo.HgInternals; |
56 import org.tmatesoft.hg.repo.HgManifest; | 55 import org.tmatesoft.hg.repo.HgManifest; |
57 import org.tmatesoft.hg.repo.HgManifest.Flags; | 56 import org.tmatesoft.hg.repo.HgManifest.Flags; |
58 import org.tmatesoft.hg.repo.HgMergeState; | 57 import org.tmatesoft.hg.repo.HgMergeState; |
59 import org.tmatesoft.hg.repo.HgRepository; | 58 import org.tmatesoft.hg.repo.HgRepository; |
59 import org.tmatesoft.hg.repo.HgRuntimeException; | |
60 import org.tmatesoft.hg.repo.HgStatusCollector; | 60 import org.tmatesoft.hg.repo.HgStatusCollector; |
61 import org.tmatesoft.hg.repo.HgStatusInspector; | 61 import org.tmatesoft.hg.repo.HgStatusInspector; |
62 import org.tmatesoft.hg.repo.HgSubrepoLocation; | 62 import org.tmatesoft.hg.repo.HgSubrepoLocation; |
63 import org.tmatesoft.hg.repo.HgSubrepoLocation.Kind; | 63 import org.tmatesoft.hg.repo.HgSubrepoLocation.Kind; |
64 import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector; | 64 import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector; |
129 private void buildFileLog() throws Exception { | 129 private void buildFileLog() throws Exception { |
130 HgLogCommand cmd = new HgLogCommand(hgRepo); | 130 HgLogCommand cmd = new HgLogCommand(hgRepo); |
131 cmd.file("file1", false); | 131 cmd.file("file1", false); |
132 cmd.execute(new HgChangesetTreeHandler() { | 132 cmd.execute(new HgChangesetTreeHandler() { |
133 public void next(HgChangesetTreeHandler.TreeElement entry) { | 133 public void next(HgChangesetTreeHandler.TreeElement entry) { |
134 try { | 134 StringBuilder sb = new StringBuilder(); |
135 StringBuilder sb = new StringBuilder(); | 135 HashSet<Nodeid> test = new HashSet<Nodeid>(entry.childRevisions()); |
136 HashSet<Nodeid> test = new HashSet<Nodeid>(entry.childRevisions()); | 136 for (HgChangeset cc : entry.children()) { |
137 for (HgChangeset cc : entry.children()) { | 137 sb.append(cc.getRevisionIndex()); |
138 sb.append(cc.getRevisionIndex()); | 138 sb.append(':'); |
139 sb.append(':'); | 139 sb.append(cc.getNodeid().shortNotation()); |
140 sb.append(cc.getNodeid().shortNotation()); | 140 sb.append(", "); |
141 sb.append(", "); | 141 } |
142 final Pair<Nodeid, Nodeid> parents = entry.parentRevisions(); | |
143 final boolean isJoin = !parents.first().isNull() && !parents.second().isNull(); | |
144 final boolean isFork = entry.children().size() > 1; | |
145 final HgChangeset cset = entry.changeset(); | |
146 System.out.printf("%d:%s - %s\n", cset.getRevisionIndex(), cset.getNodeid().shortNotation(), cset.getComment()); | |
147 if (!isJoin && !isFork && !entry.children().isEmpty()) { | |
148 System.out.printf("\t=> %s\n", sb); | |
149 } | |
150 if (isJoin) { | |
151 HgChangeset p1 = entry.parents().first(); | |
152 HgChangeset p2 = entry.parents().second(); | |
153 System.out.printf("\tjoin <= (%d:%s, %d:%s)", p1.getRevisionIndex(), p1.getNodeid().shortNotation(), p2.getRevisionIndex(), p2.getNodeid().shortNotation()); | |
154 if (isFork) { | |
155 System.out.print(", "); | |
142 } | 156 } |
143 final Pair<Nodeid, Nodeid> parents = entry.parentRevisions(); | 157 } |
144 final boolean isJoin = !parents.first().isNull() && !parents.second().isNull(); | 158 if (isFork) { |
145 final boolean isFork = entry.children().size() > 1; | 159 if (!isJoin) { |
146 final HgChangeset cset = entry.changeset(); | 160 System.out.print('\t'); |
147 System.out.printf("%d:%s - %s\n", cset.getRevisionIndex(), cset.getNodeid().shortNotation(), cset.getComment()); | |
148 if (!isJoin && !isFork && !entry.children().isEmpty()) { | |
149 System.out.printf("\t=> %s\n", sb); | |
150 } | 161 } |
151 if (isJoin) { | 162 System.out.printf("fork => [%s]", sb); |
152 HgChangeset p1 = entry.parents().first(); | 163 } |
153 HgChangeset p2 = entry.parents().second(); | 164 if (isJoin || isFork) { |
154 System.out.printf("\tjoin <= (%d:%s, %d:%s)", p1.getRevisionIndex(), p1.getNodeid().shortNotation(), p2.getRevisionIndex(), p2.getNodeid().shortNotation()); | 165 System.out.println(); |
155 if (isFork) { | |
156 System.out.print(", "); | |
157 } | |
158 } | |
159 if (isFork) { | |
160 if (!isJoin) { | |
161 System.out.print('\t'); | |
162 } | |
163 System.out.printf("fork => [%s]", sb); | |
164 } | |
165 if (isJoin || isFork) { | |
166 System.out.println(); | |
167 } | |
168 } catch (HgException ex) { | |
169 ex.printStackTrace(); | |
170 } | 166 } |
171 } | 167 } |
172 }); | 168 }); |
173 } | 169 } |
174 | 170 |
195 } | 191 } |
196 if (join) { | 192 if (join) { |
197 System.out.print("]"); | 193 System.out.print("]"); |
198 } | 194 } |
199 fileLocalRevisions++; | 195 fileLocalRevisions++; |
200 } catch (HgException ex) { | 196 } catch (HgRuntimeException ex) { |
201 ex.printStackTrace(); | 197 ex.printStackTrace(); |
202 } | 198 } |
203 } | 199 } |
204 }); | 200 }); |
205 System.out.println(); | 201 System.out.println(); |
384 final ByteArrayChannel sink = new ByteArrayChannel(); | 380 final ByteArrayChannel sink = new ByteArrayChannel(); |
385 r.putContentTo(sink); | 381 r.putContentTo(sink); |
386 return String.format("%s %s (%d bytes)", r.getPath(), r.getRevision(), sink.toArray().length); | 382 return String.format("%s %s (%d bytes)", r.getPath(), r.getRevision(), sink.toArray().length); |
387 } | 383 } |
388 | 384 |
389 private void testFileStatus() throws HgException, IOException { | 385 private void testFileStatus() throws Exception { |
390 // final Path path = Path.create("src/org/tmatesoft/hg/util/"); | 386 // final Path path = Path.create("src/org/tmatesoft/hg/util/"); |
391 // final Path path = Path.create("src/org/tmatesoft/hg/internal/Experimental.java"); | 387 // final Path path = Path.create("src/org/tmatesoft/hg/internal/Experimental.java"); |
392 // final Path path = Path.create("missing-dir/"); | 388 // final Path path = Path.create("missing-dir/"); |
393 // HgWorkingCopyStatusCollector wcsc = HgWorkingCopyStatusCollector.create(hgRepo, path); | 389 // HgWorkingCopyStatusCollector wcsc = HgWorkingCopyStatusCollector.create(hgRepo, path); |
394 HgWorkingCopyStatusCollector wcsc = HgWorkingCopyStatusCollector.create(hgRepo, new PathGlobMatcher("mi**")); | 390 HgWorkingCopyStatusCollector wcsc = HgWorkingCopyStatusCollector.create(hgRepo, new PathGlobMatcher("mi**")); |
504 System.out.printf("%d : %s\n", manifestRevision, nid); | 500 System.out.printf("%d : %s\n", manifestRevision, nid); |
505 return true; | 501 return true; |
506 } | 502 } |
507 | 503 |
508 public boolean next(Nodeid nid, String fname, String flags) { | 504 public boolean next(Nodeid nid, String fname, String flags) { |
509 throw new HgBadStateException(HgManifest.Inspector2.class.getName()); | 505 throw new IllegalStateException(HgManifest.Inspector2.class.getName()); |
510 } | 506 } |
511 public boolean next(Nodeid nid, Path fname, Flags flags) { | 507 public boolean next(Nodeid nid, Path fname, Flags flags) { |
512 System.out.println(nid + "\t" + fname + "\t\t" + flags); | 508 System.out.println(nid + "\t" + fname + "\t\t" + flags); |
513 return true; | 509 return true; |
514 } | 510 } |
527 } | 523 } |
528 public void dir(Path p) { | 524 public void dir(Path p) { |
529 System.out.println(p); | 525 System.out.println(p); |
530 } | 526 } |
531 public void file(HgFileRevision fileRevision) { | 527 public void file(HgFileRevision fileRevision) { |
532 try { | 528 System.out.print(fileRevision.getRevision());; |
533 System.out.print(fileRevision.getRevision());; | 529 System.out.print(" "); |
534 System.out.print(" "); | 530 System.out.printf("%s %s", fileRevision.getParents().first().shortNotation(), fileRevision.getParents().second().shortNotation()); |
535 System.out.printf("%s %s", fileRevision.getParents().first().shortNotation(), fileRevision.getParents().second().shortNotation()); | 531 System.out.print(" "); |
536 System.out.print(" "); | 532 System.out.println(fileRevision.getPath()); |
537 System.out.println(fileRevision.getPath()); | |
538 } catch (HgException ex) { | |
539 throw new HgCallbackTargetException.Wrap(ex); | |
540 } | |
541 } | 533 } |
542 | 534 |
543 public void end(Nodeid manifestRevision) { | 535 public void end(Nodeid manifestRevision) { |
544 System.out.println(); | 536 System.out.println(); |
545 } | 537 } |