repository.getManifest().walk(new HgManifest.Inspector() {
private int[] tagIndexAtRev = new int[4]; // it's unlikely there would be a lot of tags associated with a given cset
public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) {
// may do better here using tagLocalRev2TagInfo, but need to change a lot, too lazy now
Nodeid cset = clogrmap.revision(changelogRevision);
Arrays.fill(tagIndexAtRev, -1);
for (int i = 0, x = 0; i < allTags.length; i++) {
if (cset.equals(allTags[i].revision())) {
tagIndexAtRev[x++] = i;
if (x == tagIndexAtRev.length) {
// expand twice as much
int[] expanded = new int[x << 1];
System.arraycopy(tagIndexAtRev, 0, expanded, 0, x);
expanded[x] = -1; // just in case there'd be no more tags associated with this cset
tagIndexAtRev = expanded;
}
}
}
if (tagIndexAtRev[0] == -1) {
System.out.println("Can't happen, provided we iterate over revisions with tags only");
}
return true;
}
public boolean next(Nodeid nid, Path fname, HgManifest.Flags flags) {
Nodeid[] m = file2rev2tag.get(fname);
if (m == null) {
file2rev2tag.put(fname, m = new Nodeid[allTags.length]);
}
for (int tagIndex : tagIndexAtRev) {
if (tagIndex == -1) {
break;
}
if (m[tagIndex] != null) {
System.out.printf("There's another revision (%s) associated with tag %s already while we try to associate %s\n", m[tagIndex].shortNotation(), allTags[tagIndex].name(), nid.shortNotation());
}
m[tagIndex] = nid;
}
return true;
}
public boolean end(int manifestRevision) {
return true;
}
}, tagLocalRevs);
System.out.printf("Cache built: %d ms\n", System.currentTimeMillis() - start);
//
// look up specific file. This part is fast.
HgDataFile fileNode = repository.getFileNode(targetPath);
final Nodeid[] allTagsOfTheFile = file2rev2tag.get(targetPath);
// TODO if fileNode.isCopy, repeat for each getCopySourceName()
for (int fileRevIndex = 0; fileRevIndex < fileNode.getRevisionCount(); fileRevIndex++) {
Nodeid fileRev = fileNode.getRevision(fileRevIndex);
int changesetRevIndex = fileNode.getChangesetRevisionIndex(fileRevIndex);
List<String> associatedTags = new LinkedList<String>();
for (int i = 0; i < allTagsOfTheFile.length; i++) {
if (fileRev.equals(allTagsOfTheFile[i])) {
associatedTags.add(allTags[i].name());
}
}
System.out.printf("%3d%7d%s\n", fileRevIndex, changesetRevIndex, associatedTags);
}