comparison cmdline/org/tmatesoft/hg/console/Main.java @ 514:5dcb4581c8ef

Report renames when following file history tree with HgFileRenameHandlerMixin
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 17 Dec 2012 19:06:07 +0100
parents 122e0600799f
children e6c8b9b654b2
comparison
equal deleted inserted replaced
513:a41d955dc360 514:5dcb4581c8ef
28 import java.util.Map; 28 import java.util.Map;
29 29
30 import org.tmatesoft.hg.core.HgChangeset; 30 import org.tmatesoft.hg.core.HgChangeset;
31 import org.tmatesoft.hg.core.HgChangesetTreeHandler; 31 import org.tmatesoft.hg.core.HgChangesetTreeHandler;
32 import org.tmatesoft.hg.core.HgException; 32 import org.tmatesoft.hg.core.HgException;
33 import org.tmatesoft.hg.core.HgFileRenameHandlerMixin;
33 import org.tmatesoft.hg.core.HgFileRevision; 34 import org.tmatesoft.hg.core.HgFileRevision;
34 import org.tmatesoft.hg.core.HgLogCommand; 35 import org.tmatesoft.hg.core.HgLogCommand;
35 import org.tmatesoft.hg.core.HgManifestCommand; 36 import org.tmatesoft.hg.core.HgManifestCommand;
36 import org.tmatesoft.hg.core.HgManifestHandler; 37 import org.tmatesoft.hg.core.HgManifestHandler;
37 import org.tmatesoft.hg.core.Nodeid; 38 import org.tmatesoft.hg.core.Nodeid;
64 import org.tmatesoft.hg.repo.HgSubrepoLocation.Kind; 65 import org.tmatesoft.hg.repo.HgSubrepoLocation.Kind;
65 import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector; 66 import org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector;
66 import org.tmatesoft.hg.repo.ext.HgExtensionsManager; 67 import org.tmatesoft.hg.repo.ext.HgExtensionsManager;
67 import org.tmatesoft.hg.repo.ext.HgExtensionsManager.HgExt; 68 import org.tmatesoft.hg.repo.ext.HgExtensionsManager.HgExt;
68 import org.tmatesoft.hg.repo.ext.Rebase; 69 import org.tmatesoft.hg.repo.ext.Rebase;
70 import org.tmatesoft.hg.util.Adaptable;
69 import org.tmatesoft.hg.util.FileWalker; 71 import org.tmatesoft.hg.util.FileWalker;
70 import org.tmatesoft.hg.util.LogFacility; 72 import org.tmatesoft.hg.util.LogFacility;
71 import org.tmatesoft.hg.util.Pair; 73 import org.tmatesoft.hg.util.Pair;
72 import org.tmatesoft.hg.util.Path; 74 import org.tmatesoft.hg.util.Path;
73 import org.tmatesoft.hg.util.PathRewrite; 75 import org.tmatesoft.hg.util.PathRewrite;
172 private void buildFileLog() throws Exception { 174 private void buildFileLog() throws Exception {
173 final long start = System.nanoTime(); 175 final long start = System.nanoTime();
174 HgLogCommand cmd = new HgLogCommand(hgRepo); 176 HgLogCommand cmd = new HgLogCommand(hgRepo);
175 cmd.file("file1b.txt", true); 177 cmd.file("file1b.txt", true);
176 final int[] count = new int[] { 0 }; 178 final int[] count = new int[] { 0 };
177 cmd.execute(new HgChangesetTreeHandler() { 179 class MyHandler implements HgChangesetTreeHandler, Adaptable {
178 public void treeElement(HgChangesetTreeHandler.TreeElement entry) { 180 public void treeElement(HgChangesetTreeHandler.TreeElement entry) {
179 StringBuilder sb = new StringBuilder(); 181 StringBuilder sb = new StringBuilder();
180 HashSet<Nodeid> test = new HashSet<Nodeid>(entry.childRevisions()); 182 HashSet<Nodeid> test = new HashSet<Nodeid>(entry.childRevisions());
181 for (HgChangeset cc : entry.children()) { 183 for (HgChangeset cc : entry.children()) {
182 sb.append(cc.getRevisionIndex()); 184 sb.append(cc.getRevisionIndex());
209 if (isJoin || isFork) { 211 if (isJoin || isFork) {
210 System.out.println(); 212 System.out.println();
211 } 213 }
212 count[0]++; 214 count[0]++;
213 } 215 }
214 }); 216
217 public <T> T getAdapter(Class<T> adapterClass) {
218 if (adapterClass == HgFileRenameHandlerMixin.class) {
219 // in fact, new instance is not very nice, however
220 // getAdapter callers are supposed to understand the risk of new instance
221 // and cache returned value
222 // besides, stateless implementation of RenameDumpHandler
223 // doesn't really care about few instances
224 return adapterClass.cast(new Log.RenameDumpHandler());
225 }
226 return null;
227 }
228 };
229 cmd.execute(new MyHandler());
215 System.out.println(count[0]); 230 System.out.println(count[0]);
216 final long end = System.nanoTime(); 231 final long end = System.nanoTime();
217 System.out.printf("buildFileLog: %,d ms\n", (end-start)/1000); 232 System.out.printf("buildFileLog: %,d ms\n", (end-start)/1000);
218 } 233 }
219 234