comparison cmdline/org/tmatesoft/hg/console/Main.java @ 471:7bcfbc255f48

Merge changes from smartgit3 branch into 1.1 stream
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 11 Jul 2012 20:40:47 +0200
parents 909306e412e2 1a3c18d57a8e
children 2a0b09eec376
comparison
equal deleted inserted replaced
470:31bd09da0dcf 471:7bcfbc255f48
43 import org.tmatesoft.hg.core.Nodeid; 43 import org.tmatesoft.hg.core.Nodeid;
44 import org.tmatesoft.hg.internal.BasicSessionContext; 44 import org.tmatesoft.hg.internal.BasicSessionContext;
45 import org.tmatesoft.hg.internal.ByteArrayChannel; 45 import org.tmatesoft.hg.internal.ByteArrayChannel;
46 import org.tmatesoft.hg.internal.DigestHelper; 46 import org.tmatesoft.hg.internal.DigestHelper;
47 import org.tmatesoft.hg.internal.PathGlobMatcher; 47 import org.tmatesoft.hg.internal.PathGlobMatcher;
48 import org.tmatesoft.hg.internal.PhasesHelper;
48 import org.tmatesoft.hg.internal.RelativePathRewrite; 49 import org.tmatesoft.hg.internal.RelativePathRewrite;
50 import org.tmatesoft.hg.internal.RevisionDescendants;
49 import org.tmatesoft.hg.internal.StreamLogFacility; 51 import org.tmatesoft.hg.internal.StreamLogFacility;
50 import org.tmatesoft.hg.repo.HgBranches; 52 import org.tmatesoft.hg.repo.HgBranches;
51 import org.tmatesoft.hg.repo.HgChangelog; 53 import org.tmatesoft.hg.repo.HgChangelog;
52 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; 54 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset;
53 import org.tmatesoft.hg.repo.HgDataFile; 55 import org.tmatesoft.hg.repo.HgDataFile;
57 import org.tmatesoft.hg.repo.HgIgnore; 59 import org.tmatesoft.hg.repo.HgIgnore;
58 import org.tmatesoft.hg.repo.HgInternals; 60 import org.tmatesoft.hg.repo.HgInternals;
59 import org.tmatesoft.hg.repo.HgManifest; 61 import org.tmatesoft.hg.repo.HgManifest;
60 import org.tmatesoft.hg.repo.HgManifest.Flags; 62 import org.tmatesoft.hg.repo.HgManifest.Flags;
61 import org.tmatesoft.hg.repo.HgMergeState; 63 import org.tmatesoft.hg.repo.HgMergeState;
64 import org.tmatesoft.hg.repo.HgParentChildMap;
65 import org.tmatesoft.hg.repo.HgPhase;
62 import org.tmatesoft.hg.repo.HgRepository; 66 import org.tmatesoft.hg.repo.HgRepository;
63 import org.tmatesoft.hg.repo.HgRuntimeException; 67 import org.tmatesoft.hg.repo.HgRuntimeException;
64 import org.tmatesoft.hg.repo.HgStatusCollector; 68 import org.tmatesoft.hg.repo.HgStatusCollector;
65 import org.tmatesoft.hg.repo.HgStatusInspector; 69 import org.tmatesoft.hg.repo.HgStatusInspector;
66 import org.tmatesoft.hg.repo.HgSubrepoLocation; 70 import org.tmatesoft.hg.repo.HgSubrepoLocation;
67 import org.tmatesoft.hg.repo.HgSubrepoLocation.Kind; 71 import org.tmatesoft.hg.repo.HgSubrepoLocation.Kind;
72 import org.tmatesoft.hg.repo.ext.MqManager;
73 import org.tmatesoft.hg.repo.ext.MqManager.PatchRecord;
68 import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector; 74 import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector;
69 import org.tmatesoft.hg.repo.HgRevisionMap; 75 import org.tmatesoft.hg.repo.HgRevisionMap;
70 import org.tmatesoft.hg.util.FileWalker; 76 import org.tmatesoft.hg.util.FileWalker;
71 import org.tmatesoft.hg.util.LogFacility; 77 import org.tmatesoft.hg.util.LogFacility;
72 import org.tmatesoft.hg.util.Pair; 78 import org.tmatesoft.hg.util.Pair;
100 public static void main(String[] args) throws Exception { 106 public static void main(String[] args) throws Exception {
101 Main m = new Main(args); 107 Main m = new Main(args);
102 // m.checkWalkFileRevisions(); 108 // m.checkWalkFileRevisions();
103 // m.checkSubProgress(); 109 // m.checkSubProgress();
104 // m.checkFileFlags(); 110 // m.checkFileFlags();
111 m.testMqManager();
112 // m.testRevisionDescendants();
113 // m.dumpPhases();
105 // m.buildFileLog(); 114 // m.buildFileLog();
106 // m.testConsoleLog(); 115 // m.testConsoleLog();
107 // m.testTreeTraversal(); 116 // m.testTreeTraversal();
108 // m.testRevisionMap(); 117 // m.testRevisionMap();
109 m.testSubrepos(); 118 m.testSubrepos();
122 // m.dumpCompleteManifestLow(); 131 // m.dumpCompleteManifestLow();
123 // m.dumpCompleteManifestHigh(); 132 // m.dumpCompleteManifestHigh();
124 // m.bunchOfTests(); 133 // m.bunchOfTests();
125 } 134 }
126 135
136
137 // TODO as junit tests in 'default'
138 // -R ${system_property:user.home}/hg/test-mq
139 private void testMqManager() throws Exception {
140 MqManager mqManager = new MqManager(hgRepo);
141 mqManager.refresh();
142 int i = 1;
143 System.out.println("Complete patch queue:");
144 for (PatchRecord pr : mqManager.getAllKnownPatches()) {
145 System.out.printf("#%-3d %s from %s\n", i++, pr.getName(), pr.getPatchLocation());
146 }
147 i = 1;
148 System.out.println("Patches from the queue already applied to the repo:");
149 for (PatchRecord pr : mqManager.getAppliedPatches()) {
150 System.out.printf("#%-3d %s, known as cset:%s\n", i++, pr.getName(), pr.getRevision().shortNotation());
151 }
152 boolean allAppliedAreKnown = mqManager.getAllKnownPatches().containsAll(mqManager.getAppliedPatches());
153 System.out.printf("[sanity] allAppliedAreKnown:%b, not yet applied:%d\n", allAppliedAreKnown, mqManager.getQueueSize());
154 Assert.assertTrue(allAppliedAreKnown);
155
156 System.out.printf("Queues: %s, active:%s\n", mqManager.getQueueNames(), mqManager.getActiveQueueName());
157 Assert.assertTrue(mqManager.getQueueNames().size() > 1);
158 Assert.assertTrue(mqManager.getActiveQueueName().length() > 0);
159 }
160
161
162 // -R {junit-test-repos}/branches-1
163 private void testRevisionDescendants() throws Exception {
164 int[] roots = new int[] {0, 1, 2, 3, 4, 5};
165 RevisionDescendants[] result = new RevisionDescendants[roots.length];
166 for (int i = 0; i < roots.length; i++) {
167 result[i] = new RevisionDescendants(hgRepo, roots[i]);
168 result[i].build();
169 }
170 for (int i = 0; i < roots.length; i++) {
171 System.out.printf("For root %d descendats are:", roots[i]);
172 for (int j = roots[i], x = hgRepo.getChangelog().getLastRevision(); j <= x; j++) {
173 if (result[i].isDescendant(j)) {
174 System.out.printf("%3d ", j);
175 }
176 }
177 System.out.printf(", isEmpty:%b\n", !result[i].hasDescendants());
178 }
179 }
180
181 // -R ${system_property:user.home}/hg/test-phases/
182 // TODO as junit test
183 private void dumpPhases() throws Exception {
184 HgPhase[] result1 = new HgPhase[hgRepo.getChangelog().getRevisionCount()];
185 HgPhase[] result2 = new HgPhase[hgRepo.getChangelog().getRevisionCount()];
186 final long start1 = System.nanoTime();
187 HgParentChildMap<HgChangelog> pw = new HgParentChildMap<HgChangelog>(hgRepo.getChangelog());
188 pw.init();
189 final long start1bis = System.nanoTime();
190 PhasesHelper ph = new PhasesHelper(hgRepo, pw);
191 for (int i = 0, l = hgRepo.getChangelog().getLastRevision(); i <= l; i++) {
192 result1[i] = ph.getPhase(i, null);
193 }
194 final long start2 = System.nanoTime();
195 ph = new PhasesHelper(hgRepo);
196 for (int i = 0, l = hgRepo.getChangelog().getLastRevision(); i <= l; i++) {
197 result2[i] = ph.getPhase(i, null);
198 }
199 final long end = System.nanoTime();
200 System.out.printf("With ParentWalker(simulates log command for whole repo): %d ms (pw init: %,d ns)\n", (start2 - start1)/1000, start1bis - start1);
201 printPhases(result1);
202 System.out.printf("Without ParentWalker (simulates log command for single file): %d ms\n", (end - start2)/1000);
203 printPhases(result2);
204 }
205
206 private static void printPhases(HgPhase[] phase) {
207 for (int i = 0; i < phase.length; i++) {
208 System.out.printf("rev:%3d, phase:%s\n", i, phase[i]);
209 }
210 }
211
127 // hg4j repo 212 // hg4j repo
128 public void checkWalkFileRevisions() throws Exception { 213 public void checkWalkFileRevisions() throws Exception {
129 // hg --debug manifest --rev 150 | grep cmdline/org/tmatesoft/hg/console/Main.java 214 // hg --debug manifest --rev 150 | grep cmdline/org/tmatesoft/hg/console/Main.java
130 hgRepo.getManifest().walkFileRevisions(Path.create("cmdline/org/tmatesoft/hg/console/Main.java"), new ManifestDump(), 100, 150, 200, 210, 300); 215 hgRepo.getManifest().walkFileRevisions(Path.create("cmdline/org/tmatesoft/hg/console/Main.java"), new ManifestDump(), 100, 150, 200, 210, 300);
131 } 216 }
132 217
133 // no repo 218 // no repo
219 // FIXME as test, perhaps in TestAuxUtilities
134 private void checkSubProgress() { 220 private void checkSubProgress() {
135 ProgressSupport ps = new ProgressSupport() { 221 ProgressSupport ps = new ProgressSupport() {
136 private int units; 222 private int units;
137 223
138 public void start(int totalUnits) { 224 public void start(int totalUnits) {
174 System.out.println("Link: " + link.getFlags(TIP)); 260 System.out.println("Link: " + link.getFlags(TIP));
175 System.out.println("Exec: " + exec.getFlags(TIP)); 261 System.out.println("Exec: " + exec.getFlags(TIP));
176 System.out.println("File: " + file.getFlags(TIP)); 262 System.out.println("File: " + file.getFlags(TIP));
177 } 263 }
178 264
265
179 private void buildFileLog() throws Exception { 266 private void buildFileLog() throws Exception {
267 final long start = System.nanoTime();
180 HgLogCommand cmd = new HgLogCommand(hgRepo); 268 HgLogCommand cmd = new HgLogCommand(hgRepo);
181 cmd.file("file1", false); 269 cmd.file("file1", false);
182 cmd.execute(new HgChangesetTreeHandler() { 270 cmd.execute(new HgChangesetTreeHandler() {
183 public void treeElement(HgChangesetTreeHandler.TreeElement entry) { 271 public void treeElement(HgChangesetTreeHandler.TreeElement entry) {
184 StringBuilder sb = new StringBuilder(); 272 StringBuilder sb = new StringBuilder();
191 } 279 }
192 final Pair<Nodeid, Nodeid> parents = entry.parentRevisions(); 280 final Pair<Nodeid, Nodeid> parents = entry.parentRevisions();
193 final boolean isJoin = !parents.first().isNull() && !parents.second().isNull(); 281 final boolean isJoin = !parents.first().isNull() && !parents.second().isNull();
194 final boolean isFork = entry.children().size() > 1; 282 final boolean isFork = entry.children().size() > 1;
195 final HgChangeset cset = entry.changeset(); 283 final HgChangeset cset = entry.changeset();
196 System.out.printf("%d:%s - %s\n", cset.getRevisionIndex(), cset.getNodeid().shortNotation(), cset.getComment()); 284 System.out.printf("%d:%s - %s (%s)\n", cset.getRevisionIndex(), cset.getNodeid().shortNotation(), cset.getComment(), cset.getPhase());
197 if (!isJoin && !isFork && !entry.children().isEmpty()) { 285 if (!isJoin && !isFork && !entry.children().isEmpty()) {
198 System.out.printf("\t=> %s\n", sb); 286 System.out.printf("\t=> %s\n", sb);
199 } 287 }
200 if (isJoin) { 288 if (isJoin) {
201 HgChangeset p1 = entry.parents().first(); 289 HgChangeset p1 = entry.parents().first();
214 if (isJoin || isFork) { 302 if (isJoin || isFork) {
215 System.out.println(); 303 System.out.println();
216 } 304 }
217 } 305 }
218 }); 306 });
307 final long end = System.nanoTime();
308 System.out.printf("buildFileLog: %,d ms\n", (end-start)/1000);
219 } 309 }
220 310
221 private void buildFileLogOld() throws Exception { 311 private void buildFileLogOld() throws Exception {
222 final HgDataFile fn = hgRepo.getFileNode("file1"); 312 final HgDataFile fn = hgRepo.getFileNode("file1");
223 final int[] fileChangesetRevisions = new int[fn.getRevisionCount()]; 313 final int[] fileChangesetRevisions = new int[fn.getRevisionCount()];