Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/MapTagsToFileRevisions.java @ 433:be697c3e951e
Revlog.RevisionMap helper class got promoted as TLC, renamed to HgRevisionMap
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 30 Mar 2012 16:43:09 +0200 |
parents | 12f668401613 |
children | 9265f7f4b49b |
comparison
equal
deleted
inserted
replaced
432:1fc0da631200 | 433:be697c3e951e |
---|---|
25 import org.tmatesoft.hg.repo.HgManifest; | 25 import org.tmatesoft.hg.repo.HgManifest; |
26 import org.tmatesoft.hg.repo.HgManifest.Flags; | 26 import org.tmatesoft.hg.repo.HgManifest.Flags; |
27 import org.tmatesoft.hg.repo.HgRepository; | 27 import org.tmatesoft.hg.repo.HgRepository; |
28 import org.tmatesoft.hg.repo.HgTags; | 28 import org.tmatesoft.hg.repo.HgTags; |
29 import org.tmatesoft.hg.repo.HgTags.TagInfo; | 29 import org.tmatesoft.hg.repo.HgTags.TagInfo; |
30 import org.tmatesoft.hg.repo.HgRevisionMap; | |
30 import org.tmatesoft.hg.util.CancelledException; | 31 import org.tmatesoft.hg.util.CancelledException; |
31 import org.tmatesoft.hg.util.Path; | 32 import org.tmatesoft.hg.util.Path; |
32 | 33 |
33 /** | 34 /** |
34 * @author Marc Strapetz | 35 * @author Marc Strapetz |
83 private void buildFile2ChangelogRevisionMap() throws Exception { | 84 private void buildFile2ChangelogRevisionMap() throws Exception { |
84 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython")); | 85 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython")); |
85 final HgChangelog clog = repository.getChangelog(); | 86 final HgChangelog clog = repository.getChangelog(); |
86 final HgDataFile fileNode = repository.getFileNode("configure.in"); | 87 final HgDataFile fileNode = repository.getFileNode("configure.in"); |
87 // warm-up | 88 // warm-up |
88 HgChangelog.RevisionMap clogMap = clog.new RevisionMap().init(); | 89 HgRevisionMap<HgChangelog> clogMap = new HgRevisionMap<HgChangelog>(clog).init(); |
89 HgDataFile.RevisionMap fileMap = fileNode.new RevisionMap().init(); | 90 HgRevisionMap<HgDataFile> fileMap = new HgRevisionMap<HgDataFile>(fileNode).init(); |
90 // | 91 // |
91 final int latestRevision = fileNode.getLastRevision(); | 92 final int latestRevision = fileNode.getLastRevision(); |
92 // | 93 // |
93 final long start_1 = System.nanoTime(); | 94 final long start_1 = System.nanoTime(); |
94 fileMap = fileNode.new RevisionMap().init(); | 95 fileMap = new HgRevisionMap<HgDataFile>(fileNode).init(); |
95 final long start_1a = System.nanoTime(); | 96 final long start_1a = System.nanoTime(); |
96 final Map<Nodeid, Nodeid> changesetToNodeid_1 = new HashMap<Nodeid, Nodeid>(); | 97 final Map<Nodeid, Nodeid> changesetToNodeid_1 = new HashMap<Nodeid, Nodeid>(); |
97 for (int revision = 0; revision <= latestRevision; revision++) { | 98 for (int revision = 0; revision <= latestRevision; revision++) { |
98 final Nodeid nodeId = fileMap.revision(revision); | 99 final Nodeid nodeId = fileMap.revision(revision); |
99 // final Nodeid changesetId = fileNode.getChangesetRevision(nodeId); | 100 // final Nodeid changesetId = fileNode.getChangesetRevision(nodeId); |
102 changesetToNodeid_1.put(changesetId, nodeId); | 103 changesetToNodeid_1.put(changesetId, nodeId); |
103 } | 104 } |
104 final long end_1 = System.nanoTime(); | 105 final long end_1 = System.nanoTime(); |
105 // | 106 // |
106 final long start_2 = System.nanoTime(); | 107 final long start_2 = System.nanoTime(); |
107 clogMap = clog.new RevisionMap().init(); | 108 clogMap = new HgRevisionMap<HgChangelog>(clog).init(); |
108 fileMap = fileNode.new RevisionMap().init(); | 109 fileMap = new HgRevisionMap<HgDataFile>(fileNode).init(); |
109 final Map<Nodeid, Nodeid> changesetToNodeid_2 = new HashMap<Nodeid, Nodeid>(); | 110 final Map<Nodeid, Nodeid> changesetToNodeid_2 = new HashMap<Nodeid, Nodeid>(); |
110 final long start_2a = System.nanoTime(); | 111 final long start_2a = System.nanoTime(); |
111 for (int revision = 0; revision <= latestRevision; revision++) { | 112 for (int revision = 0; revision <= latestRevision; revision++) { |
112 Nodeid nidFile = fileMap.revision(revision); | 113 Nodeid nidFile = fileMap.revision(revision); |
113 int localCset = fileNode.getChangesetRevisionIndex(revision); | 114 int localCset = fileNode.getChangesetRevisionIndex(revision); |
154 if (r % step != 0) { | 155 if (r % step != 0) { |
155 throw new IllegalStateException(Integer.toString(r)); | 156 throw new IllegalStateException(Integer.toString(r)); |
156 } | 157 } |
157 } | 158 } |
158 System.out.printf("Direct lookup of %d revisions took %,d ns\n", revisions.size(), System.nanoTime() - s1); | 159 System.out.printf("Direct lookup of %d revisions took %,d ns\n", revisions.size(), System.nanoTime() - s1); |
159 HgChangelog.RevisionMap rmap = clog.new RevisionMap(); | 160 HgRevisionMap<HgChangelog> rmap = new HgRevisionMap<HgChangelog>(clog); |
160 final long s2 = System.nanoTime(); | 161 final long s2 = System.nanoTime(); |
161 rmap.init(); | 162 rmap.init(); |
162 final long s3 = System.nanoTime(); | 163 final long s3 = System.nanoTime(); |
163 for (Nodeid n : revisions) { | 164 for (Nodeid n : revisions) { |
164 int r = rmap.revisionIndex(n); | 165 int r = rmap.revisionIndex(n); |
205 // Another run, 23 seconds now, seems nothing has been changed. Switched to Pool2 with DirectHashSet: 22,5 seconds | 206 // Another run, 23 seconds now, seems nothing has been changed. Switched to Pool2 with DirectHashSet: 22,5 seconds |
206 System.out.printf("Total time: %d ms\n", System.currentTimeMillis() - start); | 207 System.out.printf("Total time: %d ms\n", System.currentTimeMillis() - start); |
207 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory()); | 208 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory()); |
208 } | 209 } |
209 | 210 |
210 private int[] collectLocalTagRevisions(HgChangelog.RevisionMap clogrmap, TagInfo[] allTags, IntMap<List<TagInfo>> tagLocalRev2TagInfo) { | 211 private int[] collectLocalTagRevisions(HgRevisionMap<HgChangelog> clogrmap, TagInfo[] allTags, IntMap<List<TagInfo>> tagLocalRev2TagInfo) { |
211 int[] tagLocalRevs = new int[allTags.length]; | 212 int[] tagLocalRevs = new int[allTags.length]; |
212 int x = 0; | 213 int x = 0; |
213 for (int i = 0; i < allTags.length; i++) { | 214 for (int i = 0; i < allTags.length; i++) { |
214 final Nodeid tagRevision = allTags[i].revision(); | 215 final Nodeid tagRevision = allTags[i].revision(); |
215 final int tagRevisionIndex = clogrmap.revisionIndex(tagRevision); | 216 final int tagRevisionIndex = clogrmap.revisionIndex(tagRevision); |
239 // build cache | 240 // build cache |
240 // | 241 // |
241 final TagInfo[] allTags = new TagInfo[tags.getAllTags().size()]; | 242 final TagInfo[] allTags = new TagInfo[tags.getAllTags().size()]; |
242 tags.getAllTags().values().toArray(allTags); | 243 tags.getAllTags().values().toArray(allTags); |
243 // effective translation of changeset revisions to their local indexes | 244 // effective translation of changeset revisions to their local indexes |
244 final HgChangelog.RevisionMap clogrmap = repository.getChangelog().new RevisionMap().init(); | 245 final HgRevisionMap<HgChangelog> clogrmap = new HgRevisionMap<HgChangelog>(repository.getChangelog()).init(); |
245 // map to look up tag by changeset local number | 246 // map to look up tag by changeset local number |
246 final IntMap<List<TagInfo>> tagLocalRev2TagInfo = new IntMap<List<TagInfo>>(allTags.length); | 247 final IntMap<List<TagInfo>> tagLocalRev2TagInfo = new IntMap<List<TagInfo>>(allTags.length); |
247 System.out.printf("Collecting manifests for %d tags\n", allTags.length); | 248 System.out.printf("Collecting manifests for %d tags\n", allTags.length); |
248 final int[] tagLocalRevs = collectLocalTagRevisions(clogrmap, allTags, tagLocalRev2TagInfo); | 249 final int[] tagLocalRevs = collectLocalTagRevisions(clogrmap, allTags, tagLocalRev2TagInfo); |
249 System.out.printf("Prepared %d tag revisions to analyze: %d ms\n", tagLocalRevs.length, System.currentTimeMillis() - start); | 250 System.out.printf("Prepared %d tag revisions to analyze: %d ms\n", tagLocalRevs.length, System.currentTimeMillis() - start); |
257 collectTagsPerFile_Approach_2(repository, tagLocalRevs, tagLocalRev2TagInfo, allTags, targetPath); | 258 collectTagsPerFile_Approach_2(repository, tagLocalRevs, tagLocalRev2TagInfo, allTags, targetPath); |
258 } | 259 } |
259 | 260 |
260 // Approach 1. Build map with all files, their revisions and corresponding tags | 261 // Approach 1. Build map with all files, their revisions and corresponding tags |
261 // | 262 // |
262 private void collectTagsPerFile_Approach_1(final HgChangelog.RevisionMap clogrmap, final int[] tagLocalRevs, final TagInfo[] allTags, Path targetPath) throws HgException { | 263 private void collectTagsPerFile_Approach_1(final HgRevisionMap clogrmap, final int[] tagLocalRevs, final TagInfo[] allTags, Path targetPath) throws HgException { |
263 HgRepository repository = clogrmap.getRepo(); | 264 HgRepository repository = clogrmap.getRepo(); |
264 final long start = System.currentTimeMillis(); | 265 final long start = System.currentTimeMillis(); |
265 // file2rev2tag value is array of revisions, always of allTags.length. Revision index in the array | 266 // file2rev2tag value is array of revisions, always of allTags.length. Revision index in the array |
266 // is index of corresponding TagInfo in allTags; | 267 // is index of corresponding TagInfo in allTags; |
267 final Map<Path, Nodeid[]> file2rev2tag = new HashMap<Path, Nodeid[]>(); | 268 final Map<Path, Nodeid[]> file2rev2tag = new HashMap<Path, Nodeid[]>(); |