comparison cmdline/org/tmatesoft/hg/console/Main.java @ 449:5787e912f60e smartgit3

Speed up changeset phase detection when no parent cache is avalable
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 07 Jun 2012 16:01:09 +0200
parents d0e5dc3cae6e
children 03fd8d079e9c
comparison
equal deleted inserted replaced
448:2e402c12ebc6 449:5787e912f60e
43 import org.tmatesoft.hg.internal.ByteArrayChannel; 43 import org.tmatesoft.hg.internal.ByteArrayChannel;
44 import org.tmatesoft.hg.internal.DigestHelper; 44 import org.tmatesoft.hg.internal.DigestHelper;
45 import org.tmatesoft.hg.internal.PathGlobMatcher; 45 import org.tmatesoft.hg.internal.PathGlobMatcher;
46 import org.tmatesoft.hg.internal.PhasesHelper; 46 import org.tmatesoft.hg.internal.PhasesHelper;
47 import org.tmatesoft.hg.internal.RelativePathRewrite; 47 import org.tmatesoft.hg.internal.RelativePathRewrite;
48 import org.tmatesoft.hg.internal.RevisionDescendants;
48 import org.tmatesoft.hg.internal.StreamLogFacility; 49 import org.tmatesoft.hg.internal.StreamLogFacility;
49 import org.tmatesoft.hg.repo.HgBranches; 50 import org.tmatesoft.hg.repo.HgBranches;
50 import org.tmatesoft.hg.repo.HgChangelog; 51 import org.tmatesoft.hg.repo.HgChangelog;
51 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; 52 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset;
52 import org.tmatesoft.hg.repo.HgDataFile; 53 import org.tmatesoft.hg.repo.HgDataFile;
93 System.out.println("REPO:" + hgRepo.getLocation()); 94 System.out.println("REPO:" + hgRepo.getLocation());
94 } 95 }
95 96
96 public static void main(String[] args) throws Exception { 97 public static void main(String[] args) throws Exception {
97 Main m = new Main(args); 98 Main m = new Main(args);
98 m.dumpPhases(); 99 m.testRevisionDescendants();
100 for (int i : new int[] {1,2,3}) {
101 m.dumpPhases();
102 }
99 // m.buildFileLog(); 103 // m.buildFileLog();
100 // m.testConsoleLog(); 104 // m.testConsoleLog();
101 // m.testTreeTraversal(); 105 // m.testTreeTraversal();
102 // m.testRevisionMap(); 106 // m.testRevisionMap();
103 // m.testSubrepos(); 107 // m.testSubrepos();
116 // m.dumpCompleteManifestLow(); 120 // m.dumpCompleteManifestLow();
117 // m.dumpCompleteManifestHigh(); 121 // m.dumpCompleteManifestHigh();
118 // m.bunchOfTests(); 122 // m.bunchOfTests();
119 } 123 }
120 124
121 // hg/test-phases 125 // -R {junit-test-repos}/branches-1
126 private void testRevisionDescendants() throws Exception {
127 int[] roots = new int[] {0, 1, 2, 3, 4, 5};
128 RevisionDescendants[] result = new RevisionDescendants[roots.length];
129 for (int i = 0; i < roots.length; i++) {
130 result[i] = new RevisionDescendants(hgRepo, roots[i]);
131 result[i].build();
132 }
133 for (int i = 0; i < roots.length; i++) {
134 System.out.printf("For root %d descendats are:", roots[i]);
135 for (int j = roots[i], x = hgRepo.getChangelog().getLastRevision(); j <= x; j++) {
136 if (result[i].isDescendant(j)) {
137 System.out.printf("%3d ", j);
138 }
139 }
140 System.out.printf(", isEmpty:%b\n", !result[i].hasDescendants());
141 }
142 }
143
144 // -R ${system_property:user.home}/hg/test-phases/
122 // TODO as junit test 145 // TODO as junit test
123 private void dumpPhases() throws Exception { 146 private void dumpPhases() throws Exception {
147 HgPhase[] result1 = new HgPhase[hgRepo.getChangelog().getRevisionCount()];
148 HgPhase[] result2 = new HgPhase[hgRepo.getChangelog().getRevisionCount()];
149 final long start1 = System.nanoTime();
124 HgChangelog.ParentWalker pw = hgRepo.getChangelog().new ParentWalker(); 150 HgChangelog.ParentWalker pw = hgRepo.getChangelog().new ParentWalker();
125 pw.init(); 151 pw.init();
152 final long start1bis = System.nanoTime();
126 PhasesHelper ph = new PhasesHelper(hgRepo, pw); 153 PhasesHelper ph = new PhasesHelper(hgRepo, pw);
127 System.out.println("With ParentWalker(simulates HgChangeset case)");
128 for (int i = 0, l = hgRepo.getChangelog().getLastRevision(); i <= l; i++) { 154 for (int i = 0, l = hgRepo.getChangelog().getLastRevision(); i <= l; i++) {
129 HgPhase phase = ph.getPhase(i, null); 155 result1[i] = ph.getPhase(i, null);
130 System.out.printf("rev:%3d, phase:%s\n", i, phase); 156 }
131 } 157 final long start2 = System.nanoTime();
132 ph = new PhasesHelper(hgRepo); 158 ph = new PhasesHelper(hgRepo);
133 System.out.println("Without ParentWalker");
134 for (int i = 0, l = hgRepo.getChangelog().getLastRevision(); i <= l; i++) { 159 for (int i = 0, l = hgRepo.getChangelog().getLastRevision(); i <= l; i++) {
135 HgPhase phase = ph.getPhase(i, null); 160 result2[i] = ph.getPhase(i, null);
136 System.out.printf("rev:%3d, phase:%s\n", i, phase); 161 }
162 final long end = System.nanoTime();
163 System.out.printf("With ParentWalker(simulates log command for whole repo): %d ms (pw init: %,d ns)\n", (start2 - start1)/1000, start1bis - start1);
164 printPhases(result1);
165 System.out.printf("Without ParentWalker (simulates log command for single file): %d ms\n", (end - start2)/1000);
166 printPhases(result2);
167 }
168
169 private static void printPhases(HgPhase[] phase) {
170 for (int i = 0; i < phase.length; i++) {
171 System.out.printf("rev:%3d, phase:%s\n", i, phase[i]);
137 } 172 }
138 } 173 }
139 174
140 private void buildFileLog() throws Exception { 175 private void buildFileLog() throws Exception {
141 HgLogCommand cmd = new HgLogCommand(hgRepo); 176 HgLogCommand cmd = new HgLogCommand(hgRepo);