Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/MapTagsToFileRevisions.java @ 259:ea0c0de86d0e
Avoid IAE when repository has removed tags. Do not duplicate pools that are already in ManifestParser
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 16 Aug 2011 22:15:02 +0200 |
parents | b61ed0f2c4da |
children | 31f67be94e71 |
comparison
equal
deleted
inserted
replaced
258:e5776067b3b8 | 259:ea0c0de86d0e |
---|---|
11 import org.tmatesoft.hg.core.HgChangeset; | 11 import org.tmatesoft.hg.core.HgChangeset; |
12 import org.tmatesoft.hg.core.HgChangesetHandler; | 12 import org.tmatesoft.hg.core.HgChangesetHandler; |
13 import org.tmatesoft.hg.core.HgException; | 13 import org.tmatesoft.hg.core.HgException; |
14 import org.tmatesoft.hg.core.HgLogCommand; | 14 import org.tmatesoft.hg.core.HgLogCommand; |
15 import org.tmatesoft.hg.core.Nodeid; | 15 import org.tmatesoft.hg.core.Nodeid; |
16 import org.tmatesoft.hg.internal.Pool; | |
17 import org.tmatesoft.hg.repo.HgChangelog; | 16 import org.tmatesoft.hg.repo.HgChangelog; |
18 import org.tmatesoft.hg.repo.HgDataFile; | 17 import org.tmatesoft.hg.repo.HgDataFile; |
19 import org.tmatesoft.hg.repo.HgLookup; | 18 import org.tmatesoft.hg.repo.HgLookup; |
20 import org.tmatesoft.hg.repo.HgManifest; | 19 import org.tmatesoft.hg.repo.HgManifest; |
21 import org.tmatesoft.hg.repo.HgRepository; | 20 import org.tmatesoft.hg.repo.HgRepository; |
54 final Map<String, Nodeid[]> file2rev2tag = new HashMap<String, Nodeid[]>(); | 53 final Map<String, Nodeid[]> file2rev2tag = new HashMap<String, Nodeid[]>(); |
55 System.out.printf("Collecting manifests for %d tags\n", allTags.length); | 54 System.out.printf("Collecting manifests for %d tags\n", allTags.length); |
56 // effective translation of changeset revisions to their local indexes | 55 // effective translation of changeset revisions to their local indexes |
57 final HgChangelog.RevisionMap clogrmap = repository.getChangelog().new RevisionMap().init(); | 56 final HgChangelog.RevisionMap clogrmap = repository.getChangelog().new RevisionMap().init(); |
58 int[] tagLocalRevs = new int[allTags.length]; | 57 int[] tagLocalRevs = new int[allTags.length]; |
58 int x = 0; | |
59 for (int i = 0; i < allTags.length; i++) { | 59 for (int i = 0; i < allTags.length; i++) { |
60 final Nodeid tagRevision = allTags[i].revision(); | 60 final Nodeid tagRevision = allTags[i].revision(); |
61 tagLocalRevs[i] = clogrmap.localRevision(tagRevision); | 61 final int tagLocalRev = clogrmap.localRevision(tagRevision); |
62 if (tagLocalRev != HgRepository.BAD_REVISION) { | |
63 tagLocalRevs[x++] = tagLocalRev; | |
64 } | |
65 } | |
66 if (x != allTags.length) { | |
67 // some tags were removed (recorded Nodeid.NULL tagname) | |
68 int[] copy = new int[x]; | |
69 System.arraycopy(tagLocalRevs, 0, copy, 0, x); | |
70 tagLocalRevs = copy; | |
62 } | 71 } |
63 System.out.printf("Prepared tag revisions to analyze: %d ms\n", System.currentTimeMillis() - start); | 72 System.out.printf("Prepared tag revisions to analyze: %d ms\n", System.currentTimeMillis() - start); |
64 // | 73 // |
65 repository.getManifest().walk(new HgManifest.Inspector() { | 74 repository.getManifest().walk(new HgManifest.Inspector() { |
66 private int[] tagIndexAtRev = new int[4]; // it's unlikely there would be a lot of tags associated with a given cset | 75 private int[] tagIndexAtRev = new int[4]; // it's unlikely there would be a lot of tags associated with a given cset |
67 private final Pool<String> filenamePool = new Pool<String>(); | |
68 private final Pool<Nodeid> nodeidPool = new Pool<Nodeid>(); | |
69 | 76 |
70 public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) { | 77 public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) { |
71 Nodeid cset = clogrmap.revision(changelogRevision); | 78 Nodeid cset = clogrmap.revision(changelogRevision); |
72 Arrays.fill(tagIndexAtRev, -1); | 79 Arrays.fill(tagIndexAtRev, -1); |
73 for (int i = 0, x = 0; i < allTags.length; i++) { | 80 for (int i = 0, x = 0; i < allTags.length; i++) { |
87 } | 94 } |
88 return true; | 95 return true; |
89 } | 96 } |
90 | 97 |
91 public boolean next(Nodeid nid, String fname, String flags) { | 98 public boolean next(Nodeid nid, String fname, String flags) { |
92 fname = filenamePool.unify(fname); | |
93 nid = nodeidPool.unify(nid); | |
94 Nodeid[] m = file2rev2tag.get(fname); | 99 Nodeid[] m = file2rev2tag.get(fname); |
95 if (m == null) { | 100 if (m == null) { |
96 file2rev2tag.put(fname, m = new Nodeid[allTags.length]); | 101 file2rev2tag.put(fname, m = new Nodeid[allTags.length]); |
97 } | 102 } |
98 for (int tagIndex : tagIndexAtRev) { | 103 for (int tagIndex : tagIndexAtRev) { |