comparison test/org/tmatesoft/hg/test/MapTagsToFileRevisions.java @ 628:6526d8adbc0f

Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 22 May 2013 15:52:31 +0200
parents 0d128e09d70f
children
comparison
equal deleted inserted replaced
627:5153eb73b18d 628:6526d8adbc0f
24 import org.tmatesoft.hg.repo.HgDataFile; 24 import org.tmatesoft.hg.repo.HgDataFile;
25 import org.tmatesoft.hg.repo.HgLookup; 25 import org.tmatesoft.hg.repo.HgLookup;
26 import org.tmatesoft.hg.repo.HgManifest; 26 import org.tmatesoft.hg.repo.HgManifest;
27 import org.tmatesoft.hg.repo.HgManifest.Flags; 27 import org.tmatesoft.hg.repo.HgManifest.Flags;
28 import org.tmatesoft.hg.repo.HgRepository; 28 import org.tmatesoft.hg.repo.HgRepository;
29 import org.tmatesoft.hg.repo.HgRuntimeException;
29 import org.tmatesoft.hg.repo.HgTags; 30 import org.tmatesoft.hg.repo.HgTags;
30 import org.tmatesoft.hg.repo.HgTags.TagInfo; 31 import org.tmatesoft.hg.repo.HgTags.TagInfo;
31 import org.tmatesoft.hg.repo.HgRevisionMap; 32 import org.tmatesoft.hg.repo.HgRevisionMap;
32 import org.tmatesoft.hg.util.CancelledException; 33 import org.tmatesoft.hg.util.CancelledException;
33 import org.tmatesoft.hg.util.Path; 34 import org.tmatesoft.hg.util.Path;
158 // 159 //
159 final long start_3 = System.nanoTime(); 160 final long start_3 = System.nanoTime();
160 final Map<Nodeid, Nodeid> changesetToNodeid_3 = new HashMap<Nodeid, Nodeid>(); 161 final Map<Nodeid, Nodeid> changesetToNodeid_3 = new HashMap<Nodeid, Nodeid>();
161 fileNode.indexWalk(0, TIP, new HgDataFile.RevisionInspector() { 162 fileNode.indexWalk(0, TIP, new HgDataFile.RevisionInspector() {
162 163
163 public void next(int fileRevisionIndex, Nodeid revision, int linkedRevisionIndex) { 164 public void next(int fileRevisionIndex, Nodeid revision, int linkedRevisionIndex) throws HgRuntimeException {
164 changesetToNodeid_3.put(clog.getRevision(linkedRevisionIndex), revision); 165 changesetToNodeid_3.put(clog.getRevision(linkedRevisionIndex), revision);
165 } 166 }
166 }); 167 });
167 final long end_3 = System.nanoTime(); 168 final long end_3 = System.nanoTime();
168 Assert.assertEquals(changesetToNodeid_1, changesetToNodeid_3); 169 Assert.assertEquals(changesetToNodeid_1, changesetToNodeid_3);
271 tagLocalRevs = copy; 272 tagLocalRevs = copy;
272 } 273 }
273 return tagLocalRevs; 274 return tagLocalRevs;
274 } 275 }
275 276
276 public void collectTagsPerFile() throws HgException, CancelledException { 277 public void collectTagsPerFile() throws HgException, CancelledException, HgRuntimeException {
277 final long start = System.currentTimeMillis(); 278 final long start = System.currentTimeMillis();
278 final HgRepository repository = new HgLookup().detect(new File("/home/artem/hg/cpython")); 279 final HgRepository repository = new HgLookup().detect(new File("/home/artem/hg/cpython"));
279 final HgTags tags = repository.getTags(); 280 final HgTags tags = repository.getTags();
280 // 281 //
281 // build cache 282 // build cache
299 collectTagsPerFile_Approach_2(repository, tagLocalRevs, tagLocalRev2TagInfo, targetPath); 300 collectTagsPerFile_Approach_2(repository, tagLocalRevs, tagLocalRev2TagInfo, targetPath);
300 } 301 }
301 302
302 // Approach 1. Build map with all files, their revisions and corresponding tags 303 // Approach 1. Build map with all files, their revisions and corresponding tags
303 // 304 //
304 private void collectTagsPerFile_Approach_1(final HgRevisionMap<HgChangelog> clogrmap, final int[] tagLocalRevs, final TagInfo[] allTags, Path targetPath) throws HgException { 305 private void collectTagsPerFile_Approach_1(final HgRevisionMap<HgChangelog> clogrmap, final int[] tagLocalRevs, final TagInfo[] allTags, Path targetPath) throws HgException, IllegalArgumentException, HgRuntimeException {
305 HgRepository repository = clogrmap.getRepo(); 306 HgRepository repository = clogrmap.getRepo();
306 final long start = System.currentTimeMillis(); 307 final long start = System.currentTimeMillis();
307 // file2rev2tag value is array of revisions, always of allTags.length. Revision index in the array 308 // file2rev2tag value is array of revisions, always of allTags.length. Revision index in the array
308 // is index of corresponding TagInfo in allTags; 309 // is index of corresponding TagInfo in allTags;
309 final Map<Path, Nodeid[]> file2rev2tag = new HashMap<Path, Nodeid[]>(); 310 final Map<Path, Nodeid[]> file2rev2tag = new HashMap<Path, Nodeid[]>();
371 } 372 }
372 System.out.printf("%3d%7d%s\n", fileRevIndex, changesetRevIndex, associatedTags); 373 System.out.printf("%3d%7d%s\n", fileRevIndex, changesetRevIndex, associatedTags);
373 } 374 }
374 } 375 }
375 376
376 private void collectTagsPerFile_Approach_2(HgRepository repository, final int[] tagLocalRevs, final IntMap<List<TagInfo>> tagRevIndex2TagInfo, Path targetPath) throws HgException { 377 private void collectTagsPerFile_Approach_2(HgRepository repository, final int[] tagLocalRevs, final IntMap<List<TagInfo>> tagRevIndex2TagInfo, Path targetPath) throws HgException, HgRuntimeException {
377 // 378 //
378 // Approach 2. No all-file map. Collect file revisions recorded at the time of tagging, 379 // Approach 2. No all-file map. Collect file revisions recorded at the time of tagging,
379 // then for each file revision check if it is among those above, and if yes, take corresponding tags 380 // then for each file revision check if it is among those above, and if yes, take corresponding tags
380 HgDataFile fileNode = repository.getFileNode(targetPath); 381 HgDataFile fileNode = repository.getFileNode(targetPath);
381 final long start2 = System.nanoTime(); 382 final long start2 = System.nanoTime();
455 public boolean end(int manifestRevision) { 456 public boolean end(int manifestRevision) {
456 return true; 457 return true;
457 } 458 }
458 } 459 }
459 460
460 public static void main2(String[] args) throws HgCallbackTargetException, HgException, CancelledException { 461 public static void main2(String[] args) throws HgCallbackTargetException, HgException, CancelledException, HgRuntimeException {
461 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython")); 462 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython"));
462 final Path targetPath = Path.create("README"); 463 final Path targetPath = Path.create("README");
463 final HgTags tags = repository.getTags(); 464 final HgTags tags = repository.getTags();
464 final Map<String, HgTags.TagInfo> tagToInfo = tags.getAllTags(); 465 final Map<String, HgTags.TagInfo> tagToInfo = tags.getAllTags();
465 final HgManifest manifest = repository.getManifest(); 466 final HgManifest manifest = repository.getManifest();