comparison cmdline/org/tmatesoft/hg/console/Main.java @ 305:ae8d116f4ee2

Experimental code to build file history
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 22 Sep 2011 03:57:38 +0200
parents 45dc79e545f5
children 3f40262153a4
comparison
equal deleted inserted replaced
304:85b8efde5586 305:ae8d116f4ee2
18 18
19 import static org.tmatesoft.hg.repo.HgRepository.TIP; 19 import static org.tmatesoft.hg.repo.HgRepository.TIP;
20 20
21 import java.io.File; 21 import java.io.File;
22 import java.util.ArrayList; 22 import java.util.ArrayList;
23 import java.util.Collection;
23 import java.util.Collections; 24 import java.util.Collections;
24 import java.util.List; 25 import java.util.List;
25 import java.util.Map; 26 import java.util.Map;
26 27
27 import org.junit.Assert; 28 import org.junit.Assert;
83 System.out.println("REPO:" + hgRepo.getLocation()); 84 System.out.println("REPO:" + hgRepo.getLocation());
84 } 85 }
85 86
86 public static void main(String[] args) throws Exception { 87 public static void main(String[] args) throws Exception {
87 Main m = new Main(args); 88 Main m = new Main(args);
88 m.testConsoleLog(); 89 m.buildFileLog();
90 // m.testConsoleLog();
89 // m.testTreeTraversal(); 91 // m.testTreeTraversal();
90 // m.testRevisionMap(); 92 // m.testRevisionMap();
91 // m.testSubrepos(); 93 // m.testSubrepos();
92 // m.testReadWorkingCopy(); 94 // m.testReadWorkingCopy();
93 // m.testParents(); 95 // m.testParents();
102 // m.testStatusInternals(); 104 // m.testStatusInternals();
103 // m.catCompleteHistory(); 105 // m.catCompleteHistory();
104 // m.dumpCompleteManifestLow(); 106 // m.dumpCompleteManifestLow();
105 // m.dumpCompleteManifestHigh(); 107 // m.dumpCompleteManifestHigh();
106 // m.bunchOfTests(); 108 // m.bunchOfTests();
109 }
110
111 private void buildFileLog() {
112 final HgDataFile fn = hgRepo.getFileNode("file1");
113 HgDataFile.HistoryWalker hw = fn.history();
114 while (hw.hasNext()) {
115 hw.next();
116 StringBuilder sb = new StringBuilder();
117 Collection<Nodeid> children = hw.childChangesets();
118 for (Nodeid cc : children) {
119 sb.append(cc.shortNotation());
120 sb.append(", ");
121 }
122 if (hw.isJoin()) {
123 final Pair<Nodeid, Nodeid> parents = hw.parentChangesets();
124 System.out.printf("join[(%s, %s) => %s]\n", parents.first().shortNotation(), parents.second().shortNotation(), hw.changesetRevision().shortNotation());
125 }
126 if (hw.isFork()) {
127 System.out.printf("fork[%s => %s]\n", hw.changesetRevision().shortNotation(), sb);
128 }
129 if (!hw.isFork() && !hw.isJoin() && !children.isEmpty()) {
130 System.out.printf("%s => %s\n", hw.changesetRevision().shortNotation(), sb);
131 }
132 }
133 }
134
135 private void buildFileLogOld() {
136 final HgDataFile fn = hgRepo.getFileNode("file1");
137 final int[] fileChangesetRevisions = new int[fn.getRevisionCount()];
138 fn.history(new HgChangelog.Inspector() {
139 private int fileLocalRevisions = 0;
140 private int[] parentRevisions = new int[2];
141
142 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
143 fileChangesetRevisions[fileLocalRevisions] = revisionNumber;
144 fn.parents(fileLocalRevisions, parentRevisions, null, null);
145 boolean join = parentRevisions[0] != -1 && parentRevisions[1] != -1;
146 if (join) {
147 System.out.print("join[");
148 }
149 if (parentRevisions[0] != -1) {
150 System.out.printf("%2d->%2d, ", fileChangesetRevisions[parentRevisions[0]], revisionNumber);
151 }
152 if (parentRevisions[1] != -1) {
153 System.out.printf("%2d->%2d, ", fileChangesetRevisions[parentRevisions[1]], revisionNumber);
154 }
155 if (join) {
156 System.out.print("]");
157 }
158 fileLocalRevisions++;
159 }
160 });
161 System.out.println();
107 } 162 }
108 163
109 private void testConsoleLog() { 164 private void testConsoleLog() {
110 LogFacility fc = new StreamLogFacility(true, true, true, System.out); 165 LogFacility fc = new StreamLogFacility(true, true, true, System.out);
111 System.out.printf("isDebug: %s, isInfo:%s\n", fc.isDebug(), fc.isInfo()); 166 System.out.printf("isDebug: %s, isInfo:%s\n", fc.isDebug(), fc.isInfo());