* Approach 2: total 213, init: 63, iteration: 150
* Approach 3: total 140
*/
private void buildFile2ChangelogRevisionMap(String... fileNames) throws Exception {
final HgRepository repository = new HgLookup().detect(new File("/home/artem/hg/cpython"));
final HgChangelog clog = repository.getChangelog();
// warm-up
HgRevisionMap<HgChangelog> clogMap = new HgRevisionMap<HgChangelog>(clog).init();
for (String fname : fileNames) {
HgDataFile fileNode = repository.getFileNode(fname);
// warm-up
HgRevisionMap<HgDataFile> fileMap = new HgRevisionMap<HgDataFile>(fileNode).init();
//
final int latestRevision = fileNode.getLastRevision();
//
final long start_0 = System.nanoTime();
final Map<Nodeid, Nodeid> changesetToNodeid_0 = new HashMap<Nodeid, Nodeid>();
for (int fileRevisionIndex = 0; fileRevisionIndex <= latestRevision; fileRevisionIndex++) {
Nodeid fileRevision = fileNode.getRevision(fileRevisionIndex);
Nodeid changesetRevision = fileNode.getChangesetRevision(fileRevision);
changesetToNodeid_0.put(changesetRevision, fileRevision);
}
final long end_0 = System.nanoTime();
//
final long start_1 = System.nanoTime();
fileMap = new HgRevisionMap<HgDataFile>(fileNode).init();
final long start_1a = System.nanoTime();
final Map<Nodeid, Nodeid> changesetToNodeid_1 = new HashMap<Nodeid, Nodeid>();
for (int revision = 0; revision <= latestRevision; revision++) {
final Nodeid nodeId = fileMap.revision(revision);
int localCset = fileNode.getChangesetRevisionIndex(revision);
final Nodeid changesetId = clog.getRevision(localCset);
// final Nodeid changesetId = fileNode.getChangesetRevision(nodeId);
changesetToNodeid_1.put(changesetId, nodeId);
}
final long end_1 = System.nanoTime();
//
final long start_2 = System.nanoTime();
clogMap = new HgRevisionMap<HgChangelog>(clog).init();
fileMap = new HgRevisionMap<HgDataFile>(fileNode).init();
final Map<Nodeid, Nodeid> changesetToNodeid_2 = new HashMap<Nodeid, Nodeid>();
final long start_2a = System.nanoTime();
for (int revision = 0; revision <= latestRevision; revision++) {
Nodeid nidFile = fileMap.revision(revision);
int localCset = fileNode.getChangesetRevisionIndex(revision);
Nodeid nidCset = clogMap.revision(localCset);
changesetToNodeid_2.put(nidCset, nidFile);
}
final long end_2 = System.nanoTime();
Assert.assertEquals(changesetToNodeid_1, changesetToNodeid_2);
//
final long start_3 = System.nanoTime();
final Map<Nodeid, Nodeid> changesetToNodeid_3 = new HashMap<Nodeid, Nodeid>();
fileNode.indexWalk(0, TIP, new HgDataFile.RevisionInspector() {
public void next(int fileRevisionIndex, Nodeid revision, int linkedRevisionIndex) throws HgRuntimeException {
changesetToNodeid_3.put(clog.getRevision(linkedRevisionIndex), revision);
}
});
final long end_3 = System.nanoTime();
Assert.assertEquals(changesetToNodeid_1, changesetToNodeid_3);
System.out.printf("%s, %d revisions\n", fname, 1+latestRevision);