Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/MapTagsToFileRevisions.java @ 367:2fadf8695f8a
Use 'revision index' instead of the vague 'local revision number' concept in the API
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 16 Dec 2011 15:37:27 +0100 |
parents | 189dc6dc1c3e |
children | 8107b95f4280 |
comparison
equal
deleted
inserted
replaced
366:189dc6dc1c3e | 367:2fadf8695f8a |
---|---|
95 final long start_1a = System.nanoTime(); | 95 final long start_1a = System.nanoTime(); |
96 final Map<Nodeid, Nodeid> changesetToNodeid_1 = new HashMap<Nodeid, Nodeid>(); | 96 final Map<Nodeid, Nodeid> changesetToNodeid_1 = new HashMap<Nodeid, Nodeid>(); |
97 for (int revision = 0; revision <= latestRevision; revision++) { | 97 for (int revision = 0; revision <= latestRevision; revision++) { |
98 final Nodeid nodeId = fileMap.revision(revision); | 98 final Nodeid nodeId = fileMap.revision(revision); |
99 // final Nodeid changesetId = fileNode.getChangesetRevision(nodeId); | 99 // final Nodeid changesetId = fileNode.getChangesetRevision(nodeId); |
100 int localCset = fileNode.getChangesetLocalRevision(revision); | 100 int localCset = fileNode.getChangesetRevisionIndex(revision); |
101 final Nodeid changesetId = clog.getRevision(localCset); | 101 final Nodeid changesetId = clog.getRevision(localCset); |
102 changesetToNodeid_1.put(changesetId, nodeId); | 102 changesetToNodeid_1.put(changesetId, nodeId); |
103 } | 103 } |
104 final long end_1 = System.nanoTime(); | 104 final long end_1 = System.nanoTime(); |
105 // | 105 // |
108 fileMap = fileNode.new RevisionMap().init(); | 108 fileMap = fileNode.new RevisionMap().init(); |
109 final Map<Nodeid, Nodeid> changesetToNodeid_2 = new HashMap<Nodeid, Nodeid>(); | 109 final Map<Nodeid, Nodeid> changesetToNodeid_2 = new HashMap<Nodeid, Nodeid>(); |
110 final long start_2a = System.nanoTime(); | 110 final long start_2a = System.nanoTime(); |
111 for (int revision = 0; revision <= latestRevision; revision++) { | 111 for (int revision = 0; revision <= latestRevision; revision++) { |
112 Nodeid nidFile = fileMap.revision(revision); | 112 Nodeid nidFile = fileMap.revision(revision); |
113 int localCset = fileNode.getChangesetLocalRevision(revision); | 113 int localCset = fileNode.getChangesetRevisionIndex(revision); |
114 Nodeid nidCset = clogMap.revision(localCset); | 114 Nodeid nidCset = clogMap.revision(localCset); |
115 changesetToNodeid_2.put(nidCset, nidFile); | 115 changesetToNodeid_2.put(nidCset, nidFile); |
116 } | 116 } |
117 final long end_2 = System.nanoTime(); | 117 final long end_2 = System.nanoTime(); |
118 Assert.assertEquals(changesetToNodeid_1, changesetToNodeid_2); | 118 Assert.assertEquals(changesetToNodeid_1, changesetToNodeid_2); |
136 System.out.printf("Approach 3: total %d\n", (end_3 - start_3)/1000000); | 136 System.out.printf("Approach 3: total %d\n", (end_3 - start_3)/1000000); |
137 } | 137 } |
138 | 138 |
139 /* | 139 /* |
140 * Each 5000 revisions from cpython, total 15 revisions | 140 * Each 5000 revisions from cpython, total 15 revisions |
141 * Direct clog.getLocalRevision: ~260 ms | 141 * Direct clog.getRevisionIndex: ~260 ms |
142 * RevisionMap.localRevision: ~265 ms (almost 100% in #init()) | 142 * RevisionMap.revisionIndex: ~265 ms (almost 100% in #init()) |
143 * each 1000'th revision, total 71 revision: 1 230 vs 270 | 143 * each 1000'th revision, total 71 revision: 1 230 vs 270 |
144 * each 2000'th revision, total 36 revision: 620 vs 270 | 144 * each 2000'th revision, total 36 revision: 620 vs 270 |
145 * each 3000'th revision, total 24 revision: 410 vs 275 | 145 * each 3000'th revision, total 24 revision: 410 vs 275 |
146 */ | 146 */ |
147 private void revisionMap() throws Exception { | 147 private void revisionMap() throws Exception { |
152 for (int i = 0, top = clog.getLastRevision(); i < top; i += step) { | 152 for (int i = 0, top = clog.getLastRevision(); i < top; i += step) { |
153 revisions.add(clog.getRevision(i)); | 153 revisions.add(clog.getRevision(i)); |
154 } | 154 } |
155 final long s1 = System.nanoTime(); | 155 final long s1 = System.nanoTime(); |
156 for (Nodeid n : revisions) { | 156 for (Nodeid n : revisions) { |
157 int r = clog.getLocalRevision(n); | 157 int r = clog.getRevisionIndex(n); |
158 if (r % step != 0) { | 158 if (r % step != 0) { |
159 throw new IllegalStateException(Integer.toString(r)); | 159 throw new IllegalStateException(Integer.toString(r)); |
160 } | 160 } |
161 } | 161 } |
162 System.out.printf("Direct lookup of %d revisions took %,d ns\n", revisions.size(), System.nanoTime() - s1); | 162 System.out.printf("Direct lookup of %d revisions took %,d ns\n", revisions.size(), System.nanoTime() - s1); |
163 HgChangelog.RevisionMap rmap = clog.new RevisionMap(); | 163 HgChangelog.RevisionMap rmap = clog.new RevisionMap(); |
164 final long s2 = System.nanoTime(); | 164 final long s2 = System.nanoTime(); |
165 rmap.init(); | 165 rmap.init(); |
166 final long s3 = System.nanoTime(); | 166 final long s3 = System.nanoTime(); |
167 for (Nodeid n : revisions) { | 167 for (Nodeid n : revisions) { |
168 int r = rmap.localRevision(n); | 168 int r = rmap.revisionIndex(n); |
169 if (r % step != 0) { | 169 if (r % step != 0) { |
170 throw new IllegalStateException(Integer.toString(r)); | 170 throw new IllegalStateException(Integer.toString(r)); |
171 } | 171 } |
172 } | 172 } |
173 System.out.printf("RevisionMap time: %d ms, of that init() %,d ns\n", (System.nanoTime() - s2) / 1000000, s3 - s2); | 173 System.out.printf("RevisionMap time: %d ms, of that init() %,d ns\n", (System.nanoTime() - s2) / 1000000, s3 - s2); |
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.localRevision(tagRevision); | 219 final int tagLocalRev = clogrmap.revisionIndex(tagRevision); |
220 if (tagLocalRev != HgRepository.BAD_REVISION) { | 220 if (tagLocalRev != HgRepository.BAD_REVISION) { |
221 tagLocalRevs[x++] = tagLocalRev; | 221 tagLocalRevs[x++] = tagLocalRev; |
222 List<TagInfo> tagsAssociatedWithRevision = tagLocalRev2TagInfo.get(tagLocalRev); | 222 List<TagInfo> tagsAssociatedWithRevision = tagLocalRev2TagInfo.get(tagLocalRev); |
223 if (tagsAssociatedWithRevision == null) { | 223 if (tagsAssociatedWithRevision == null) { |
224 tagLocalRev2TagInfo.put(tagLocalRev, tagsAssociatedWithRevision = new LinkedList<TagInfo>()); | 224 tagLocalRev2TagInfo.put(tagLocalRev, tagsAssociatedWithRevision = new LinkedList<TagInfo>()); |
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 localFileRev = 0; localFileRev < fileNode.getRevisionCount(); localFileRev++) { |
330 Nodeid fileRev = fileNode.getRevision(localFileRev); | 330 Nodeid fileRev = fileNode.getRevision(localFileRev); |
331 int changesetLocalRev = fileNode.getChangesetLocalRevision(localFileRev); | 331 int changesetLocalRev = fileNode.getChangesetRevisionIndex(localFileRev); |
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 } |
400 final HgDataFile fileNode = repository.getFileNode(targetPath); | 400 final HgDataFile fileNode = repository.getFileNode(targetPath); |
401 for (String tagName : tagToInfo.keySet()) { | 401 for (String tagName : tagToInfo.keySet()) { |
402 final HgTags.TagInfo info = tagToInfo.get(tagName); | 402 final HgTags.TagInfo info = tagToInfo.get(tagName); |
403 final Nodeid nodeId = info.revision(); | 403 final Nodeid nodeId = info.revision(); |
404 // TODO: This is not correct as we can't be sure that file at the corresponding revision is actually our target file (which may have been renamed, etc.) | 404 // TODO: This is not correct as we can't be sure that file at the corresponding revision is actually our target file (which may have been renamed, etc.) |
405 final Nodeid fileRevision = manifest.getFileRevision(repository.getChangelog().getLocalRevision(nodeId), targetPath); | 405 final Nodeid fileRevision = manifest.getFileRevision(repository.getChangelog().getRevisionIndex(nodeId), targetPath); |
406 if (fileRevision == null) { | 406 if (fileRevision == null) { |
407 continue; | 407 continue; |
408 } | 408 } |
409 | 409 |
410 final Nodeid changeSetRevision = fileNode.getChangesetRevision(fileRevision); | 410 final Nodeid changeSetRevision = fileNode.getChangesetRevision(fileRevision); |