Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/MapTagsToFileRevisions.java @ 368:8107b95f4280
Update Javadoc with 'revision index'
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 16 Dec 2011 16:00:57 +0100 |
parents | 2fadf8695f8a |
children | 9c9c442b5f2e |
comparison
equal
deleted
inserted
replaced
367:2fadf8695f8a | 368:8107b95f4280 |
---|---|
119 // | 119 // |
120 final long start_3 = System.nanoTime(); | 120 final long start_3 = System.nanoTime(); |
121 final Map<Nodeid, Nodeid> changesetToNodeid_3 = new HashMap<Nodeid, Nodeid>(); | 121 final Map<Nodeid, Nodeid> changesetToNodeid_3 = new HashMap<Nodeid, Nodeid>(); |
122 fileNode.walk(0, TIP, new HgDataFile.RevisionInspector() { | 122 fileNode.walk(0, TIP, new HgDataFile.RevisionInspector() { |
123 | 123 |
124 public void next(int localRevision, Nodeid revision, int linkedRevision) { | 124 public void next(int fileRevisionIndex, Nodeid revision, int linkedRevisionIndex) { |
125 try { | 125 try { |
126 changesetToNodeid_3.put(clog.getRevision(linkedRevision), revision); | 126 changesetToNodeid_3.put(clog.getRevision(linkedRevisionIndex), revision); |
127 } catch (HgException ex) { | 127 } catch (HgException ex) { |
128 ex.printStackTrace(); | 128 ex.printStackTrace(); |
129 } | 129 } |
130 } | 130 } |
131 }); | 131 }); |
214 private int[] collectLocalTagRevisions(HgChangelog.RevisionMap clogrmap, TagInfo[] allTags, IntMap<List<TagInfo>> tagLocalRev2TagInfo) { | 214 private int[] collectLocalTagRevisions(HgChangelog.RevisionMap clogrmap, TagInfo[] allTags, IntMap<List<TagInfo>> tagLocalRev2TagInfo) { |
215 int[] tagLocalRevs = new int[allTags.length]; | 215 int[] tagLocalRevs = new int[allTags.length]; |
216 int x = 0; | 216 int x = 0; |
217 for (int i = 0; i < allTags.length; i++) { | 217 for (int i = 0; i < allTags.length; i++) { |
218 final Nodeid tagRevision = allTags[i].revision(); | 218 final Nodeid tagRevision = allTags[i].revision(); |
219 final int tagLocalRev = clogrmap.revisionIndex(tagRevision); | 219 final int tagRevisionIndex = clogrmap.revisionIndex(tagRevision); |
220 if (tagLocalRev != HgRepository.BAD_REVISION) { | 220 if (tagRevisionIndex != HgRepository.BAD_REVISION) { |
221 tagLocalRevs[x++] = tagLocalRev; | 221 tagLocalRevs[x++] = tagRevisionIndex; |
222 List<TagInfo> tagsAssociatedWithRevision = tagLocalRev2TagInfo.get(tagLocalRev); | 222 List<TagInfo> tagsAssociatedWithRevision = tagLocalRev2TagInfo.get(tagRevisionIndex); |
223 if (tagsAssociatedWithRevision == null) { | 223 if (tagsAssociatedWithRevision == null) { |
224 tagLocalRev2TagInfo.put(tagLocalRev, tagsAssociatedWithRevision = new LinkedList<TagInfo>()); | 224 tagLocalRev2TagInfo.put(tagRevisionIndex, tagsAssociatedWithRevision = new LinkedList<TagInfo>()); |
225 } | 225 } |
226 tagsAssociatedWithRevision.add(allTags[i]); | 226 tagsAssociatedWithRevision.add(allTags[i]); |
227 } | 227 } |
228 } | 228 } |
229 if (x != allTags.length) { | 229 if (x != allTags.length) { |
324 // | 324 // |
325 // look up specific file. This part is fast. | 325 // look up specific file. This part is fast. |
326 HgDataFile fileNode = repository.getFileNode(targetPath); | 326 HgDataFile fileNode = repository.getFileNode(targetPath); |
327 final Nodeid[] allTagsOfTheFile = file2rev2tag.get(targetPath); | 327 final Nodeid[] allTagsOfTheFile = file2rev2tag.get(targetPath); |
328 // TODO if fileNode.isCopy, repeat for each getCopySourceName() | 328 // TODO if fileNode.isCopy, repeat for each getCopySourceName() |
329 for (int localFileRev = 0; localFileRev < fileNode.getRevisionCount(); localFileRev++) { | 329 for (int fileRevIndex = 0; fileRevIndex < fileNode.getRevisionCount(); fileRevIndex++) { |
330 Nodeid fileRev = fileNode.getRevision(localFileRev); | 330 Nodeid fileRev = fileNode.getRevision(fileRevIndex); |
331 int changesetLocalRev = fileNode.getChangesetRevisionIndex(localFileRev); | 331 int changesetRevIndex = fileNode.getChangesetRevisionIndex(fileRevIndex); |
332 List<String> associatedTags = new LinkedList<String>(); | 332 List<String> associatedTags = new LinkedList<String>(); |
333 for (int i = 0; i < allTagsOfTheFile.length; i++) { | 333 for (int i = 0; i < allTagsOfTheFile.length; i++) { |
334 if (fileRev.equals(allTagsOfTheFile[i])) { | 334 if (fileRev.equals(allTagsOfTheFile[i])) { |
335 associatedTags.add(allTags[i].name()); | 335 associatedTags.add(allTags[i].name()); |
336 } | 336 } |
337 } | 337 } |
338 System.out.printf("%3d%7d%s\n", localFileRev, changesetLocalRev, associatedTags); | 338 System.out.printf("%3d%7d%s\n", fileRevIndex, changesetRevIndex, associatedTags); |
339 } | 339 } |
340 } | 340 } |
341 | 341 |
342 private void collectTagsPerFile_Approach_2(HgRepository repository, final int[] tagLocalRevs, final IntMap<List<TagInfo>> tagLocalRev2TagInfo, TagInfo[] allTags, Path targetPath) throws HgException { | 342 private void collectTagsPerFile_Approach_2(HgRepository repository, final int[] tagLocalRevs, final IntMap<List<TagInfo>> tagLocalRev2TagInfo, TagInfo[] allTags, Path targetPath) throws HgException { |
343 // | 343 // |
348 final int lastRev = fileNode.getLastRevision(); | 348 final int lastRev = fileNode.getLastRevision(); |
349 final Map<Integer, Nodeid> fileRevisionAtTagRevision = repository.getManifest().getFileRevisions(targetPath, tagLocalRevs); | 349 final Map<Integer, Nodeid> fileRevisionAtTagRevision = repository.getManifest().getFileRevisions(targetPath, tagLocalRevs); |
350 final long start2a = System.nanoTime(); | 350 final long start2a = System.nanoTime(); |
351 fileNode.walk(0, lastRev, new HgDataFile.RevisionInspector() { | 351 fileNode.walk(0, lastRev, new HgDataFile.RevisionInspector() { |
352 | 352 |
353 public void next(int localFileRev, Nodeid fileRevision, int linkedRevision) { | 353 public void next(int fileRevisionIndex, Nodeid fileRevision, int changesetRevisionIndex) { |
354 int changesetLocalRev = linkedRevision; | |
355 List<String> associatedTags = new LinkedList<String>(); | 354 List<String> associatedTags = new LinkedList<String>(); |
356 for (int taggetRevision : tagLocalRevs) { | 355 for (int taggetRevision : tagLocalRevs) { |
357 // current file revision can't appear in tags that point to earlier changelog revisions (they got own file revision) | 356 // current file revision can't appear in tags that point to earlier changelog revisions (they got own file revision) |
358 if (taggetRevision >= changesetLocalRev) { | 357 if (taggetRevision >= changesetRevisionIndex) { |
359 // z points to some changeset with tag | 358 // z points to some changeset with tag |
360 Nodeid wasKnownAs = fileRevisionAtTagRevision.get(taggetRevision); | 359 Nodeid wasKnownAs = fileRevisionAtTagRevision.get(taggetRevision); |
361 if (wasKnownAs.equals(fileRevision)) { | 360 if (wasKnownAs.equals(fileRevision)) { |
362 // has tag associated with changeset at index z | 361 // has tag associated with changeset at index z |
363 List<TagInfo> tagsAtRev = tagLocalRev2TagInfo.get(taggetRevision); | 362 List<TagInfo> tagsAtRev = tagLocalRev2TagInfo.get(taggetRevision); |
366 associatedTags.add(ti.name()); | 365 associatedTags.add(ti.name()); |
367 } | 366 } |
368 } | 367 } |
369 } | 368 } |
370 } | 369 } |
371 System.out.printf("%3d%7d%s\n", localFileRev, changesetLocalRev, associatedTags); | 370 System.out.printf("%3d%7d%s\n", fileRevisionIndex, changesetRevisionIndex, associatedTags); |
372 } | 371 } |
373 }); | 372 }); |
374 System.out.printf("Alternative total time: %d ms, of that init: %d ms\n", (System.nanoTime() - start2)/1000000, (start2a-start2)/1000000); | 373 System.out.printf("Alternative total time: %d ms, of that init: %d ms\n", (System.nanoTime() - start2)/1000000, (start2a-start2)/1000000); |
375 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory()); | 374 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory()); |
376 } | 375 } |