annotate 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
rev   line source
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 package org.tmatesoft.hg.test;
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
3 import java.io.File;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
4 import java.util.ArrayList;
256
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
5 import java.util.Arrays;
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
6 import java.util.HashMap;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
7 import java.util.LinkedList;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
8 import java.util.List;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
9 import java.util.Map;
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
11 import org.tmatesoft.hg.core.HgChangeset;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
12 import org.tmatesoft.hg.core.HgChangesetHandler;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
13 import org.tmatesoft.hg.core.HgException;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
14 import org.tmatesoft.hg.core.HgLogCommand;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
15 import org.tmatesoft.hg.core.Nodeid;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
16 import org.tmatesoft.hg.repo.HgChangelog;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
17 import org.tmatesoft.hg.repo.HgDataFile;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
18 import org.tmatesoft.hg.repo.HgLookup;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
19 import org.tmatesoft.hg.repo.HgManifest;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
20 import org.tmatesoft.hg.repo.HgRepository;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
21 import org.tmatesoft.hg.repo.HgTags;
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import org.tmatesoft.hg.repo.HgTags.TagInfo;
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
23 import org.tmatesoft.hg.util.CancelledException;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
24 import org.tmatesoft.hg.util.Path;
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 /**
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 * @author Marc Strapetz
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 */
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 public class MapTagsToFileRevisions {
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 // Static =================================================================
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
33 public static void main(String[] args) throws Exception {
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
34 MapTagsToFileRevisions m = new MapTagsToFileRevisions();
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
35 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory());
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
36 m.main();
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
37 m = null;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
38 System.gc();
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
39 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory());
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
40 }
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
41
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
42 private void main() throws HgException, CancelledException {
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 final long start = System.currentTimeMillis();
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython"));
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 final HgTags tags = repository.getTags();
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 //
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 // build cache
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
48 //
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
49 final TagInfo[] allTags = new TagInfo[tags.getTags().size()];
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
50 tags.getTags().values().toArray(allTags);
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
51 // file2rev2tag value is array of revisions, always of allTags.length. Revision index in the array
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
52 // is index of corresponding TagInfo in allTags;
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
53 final Map<String, Nodeid[]> file2rev2tag = new HashMap<String, Nodeid[]>();
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
54 System.out.printf("Collecting manifests for %d tags\n", allTags.length);
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 // effective translation of changeset revisions to their local indexes
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 final HgChangelog.RevisionMap clogrmap = repository.getChangelog().new RevisionMap().init();
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
57 int[] tagLocalRevs = new int[allTags.length];
259
ea0c0de86d0e Avoid IAE when repository has removed tags. Do not duplicate pools that are already in ManifestParser
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 256
diff changeset
58 int x = 0;
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
59 for (int i = 0; i < allTags.length; i++) {
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
60 final Nodeid tagRevision = allTags[i].revision();
259
ea0c0de86d0e Avoid IAE when repository has removed tags. Do not duplicate pools that are already in ManifestParser
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 256
diff changeset
61 final int tagLocalRev = clogrmap.localRevision(tagRevision);
ea0c0de86d0e Avoid IAE when repository has removed tags. Do not duplicate pools that are already in ManifestParser
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 256
diff changeset
62 if (tagLocalRev != HgRepository.BAD_REVISION) {
ea0c0de86d0e Avoid IAE when repository has removed tags. Do not duplicate pools that are already in ManifestParser
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 256
diff changeset
63 tagLocalRevs[x++] = tagLocalRev;
ea0c0de86d0e Avoid IAE when repository has removed tags. Do not duplicate pools that are already in ManifestParser
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 256
diff changeset
64 }
ea0c0de86d0e Avoid IAE when repository has removed tags. Do not duplicate pools that are already in ManifestParser
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 256
diff changeset
65 }
ea0c0de86d0e Avoid IAE when repository has removed tags. Do not duplicate pools that are already in ManifestParser
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 256
diff changeset
66 if (x != allTags.length) {
ea0c0de86d0e Avoid IAE when repository has removed tags. Do not duplicate pools that are already in ManifestParser
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 256
diff changeset
67 // some tags were removed (recorded Nodeid.NULL tagname)
ea0c0de86d0e Avoid IAE when repository has removed tags. Do not duplicate pools that are already in ManifestParser
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 256
diff changeset
68 int[] copy = new int[x];
ea0c0de86d0e Avoid IAE when repository has removed tags. Do not duplicate pools that are already in ManifestParser
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 256
diff changeset
69 System.arraycopy(tagLocalRevs, 0, copy, 0, x);
ea0c0de86d0e Avoid IAE when repository has removed tags. Do not duplicate pools that are already in ManifestParser
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 256
diff changeset
70 tagLocalRevs = copy;
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 }
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
72 System.out.printf("Prepared tag revisions to analyze: %d ms\n", System.currentTimeMillis() - start);
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 //
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 repository.getManifest().walk(new HgManifest.Inspector() {
256
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
75 private int[] tagIndexAtRev = new int[4]; // it's unlikely there would be a lot of tags associated with a given cset
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) {
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 Nodeid cset = clogrmap.revision(changelogRevision);
256
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
79 Arrays.fill(tagIndexAtRev, -1);
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
80 for (int i = 0, x = 0; i < allTags.length; i++) {
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
81 if (cset.equals(allTags[i].revision())) {
256
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
82 tagIndexAtRev[x++] = i;
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
83 if (x == tagIndexAtRev.length) {
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
84 // expand twice as much
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
85 int[] expanded = new int[x << 1];
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
86 System.arraycopy(tagIndexAtRev, 0, expanded, 0, x);
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
87 expanded[x] = -1; // just in case there'd be no more tags associated with this cset
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
88 tagIndexAtRev = expanded;
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
89 }
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
90 }
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
91 }
256
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
92 if (tagIndexAtRev[0] == -1) {
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93 System.out.println("Can't happen, provided we iterate over revisions with tags only");
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 return true;
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98 public boolean next(Nodeid nid, String fname, String flags) {
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
99 Nodeid[] m = file2rev2tag.get(fname);
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 if (m == null) {
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
101 file2rev2tag.put(fname, m = new Nodeid[allTags.length]);
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102 }
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
103 for (int tagIndex : tagIndexAtRev) {
256
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
104 if (tagIndex == -1) {
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
105 break;
b61ed0f2c4da Yet another slight perf/mem improvement for the tags per file sample
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 255
diff changeset
106 }
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
107 if (m[tagIndex] != null) {
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
108 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());
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
109 }
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
110 m[tagIndex] = nid;
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
111 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
112 return true;
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
114
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
115 public boolean end(int manifestRevision) {
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 return true;
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
117 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
118
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
119 }, tagLocalRevs);
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
120 System.out.printf("Cache built: %d ms\n", System.currentTimeMillis() - start);
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
121 //
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
122 // look up specific file. This part is fast.
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
123 final Path targetPath = Path.create("README");
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
124 HgDataFile fileNode = repository.getFileNode(targetPath);
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
125 final Nodeid[] allTagsOfTheFile = file2rev2tag.get(targetPath.toString());
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
126 // TODO if fileNode.isCopy, repeat for each getCopySourceName()
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
127 for (int localFileRev = 0; localFileRev < fileNode.getRevisionCount(); localFileRev++) {
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
128 Nodeid fileRev = fileNode.getRevision(localFileRev);
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129 int changesetLocalRev = fileNode.getChangesetLocalRevision(localFileRev);
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
130 List<String> associatedTags = new LinkedList<String>();
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
131 for (int i = 0; i < allTagsOfTheFile.length; i++) {
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
132 if (fileRev.equals(allTagsOfTheFile[i])) {
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
133 associatedTags.add(allTags[i].name());
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
134 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
135 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
136 System.out.printf("%3d%7d%s\n", localFileRev, changesetLocalRev, associatedTags);
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
137 }
255
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
138 System.out.printf("Total time: %d ms\n", System.currentTimeMillis() - start);
5a6ab50b4cbf Improve memory footprint of tag collection (about 14 Mb saved for cpython repo without HashMap.Entry and Entry[])
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 254
diff changeset
139 System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory());
254
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
140 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
141
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
142 public static void main2(String[] args) throws HgException, CancelledException {
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
143 final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython"));
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
144 final Path targetPath = Path.create("README");
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
145 final HgTags tags = repository.getTags();
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
146 final Map<String, HgTags.TagInfo> tagToInfo = tags.getTags();
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
147 final HgManifest manifest = repository.getManifest();
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
148 final Map<Nodeid, List<String>> changeSetRevisionToTags = new HashMap<Nodeid, List<String>>();
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
149 final HgDataFile fileNode = repository.getFileNode(targetPath);
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
150 for (String tagName : tagToInfo.keySet()) {
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
151 final HgTags.TagInfo info = tagToInfo.get(tagName);
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
152 final Nodeid nodeId = info.revision();
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
153 // 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.)
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
154 final Nodeid fileRevision = manifest.getFileRevision(repository.getChangelog().getLocalRevision(nodeId), targetPath);
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
155 if (fileRevision == null) {
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
156 continue;
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
157 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
158
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
159 final Nodeid changeSetRevision = fileNode.getChangesetRevision(fileRevision);
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
160 List<String> revisionTags = changeSetRevisionToTags.get(changeSetRevision);
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
161 if (revisionTags == null) {
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
162 revisionTags = new ArrayList<String>();
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
163 changeSetRevisionToTags.put(changeSetRevision, revisionTags);
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
164 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
165 revisionTags.add(tagName);
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
166 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
167
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
168 final HgLogCommand logCommand = new HgLogCommand(repository);
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
169 logCommand.file(targetPath, true);
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
170 logCommand.execute(new HgChangesetHandler() {
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
171 public void next(HgChangeset changeset) {
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
172 if (changeset.getAffectedFiles().contains(targetPath)) {
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
173 System.out.println(changeset.getRevision() + " " + changeSetRevisionToTags.get(changeset.getNodeid()));
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
174 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
175 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
176 });
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
177 }
a620f0663a37 Collect tags for a file - improve performance of 'sparse' manifest reads
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
178 }