comparison test/org/tmatesoft/hg/test/TestHistory.java @ 508:ca5202afea90

Support follow history option when walking file history tree
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 12 Dec 2012 20:52:10 +0100
parents a6435c1a42d0
children a30e74dca193
comparison
equal deleted inserted replaced
507:a6435c1a42d0 508:ca5202afea90
128 repo = Configuration.get().find("branches-1"); 128 repo = Configuration.get().find("branches-1");
129 final String fname = "file1"; 129 final String fname = "file1";
130 assertTrue("[sanity]", repo.getFileNode(fname).exists()); 130 assertTrue("[sanity]", repo.getFileNode(fname).exists());
131 eh.run("hg", "log", "--debug", fname, "--cwd", repo.getLocation()); 131 eh.run("hg", "log", "--debug", fname, "--cwd", repo.getLocation());
132 132
133 final LinkedList<HgChangeset> cmdResult = new LinkedList<HgChangeset>(); 133 TreeCollectHandler h = new TreeCollectHandler(false);
134 new HgLogCommand(repo).file(fname, false).execute(new HgChangesetTreeHandler() { 134 new HgLogCommand(repo).file(fname, false).execute(h);
135 135 // since we use TreeCollectHandler with natural order (older to newer), shall reverse console result in report()
136 public void treeElement(TreeElement entry) throws HgCallbackTargetException { 136 report("execute with HgChangesetTreeHandler(follow == false)", h.getResult(), true);
137 // check consistency 137 }
138 Nodeid cset = entry.changeset().getNodeid(); 138
139 errorCollector.assertEquals(entry.changesetRevision(), cset); 139 @Test
140 Pair<HgChangeset, HgChangeset> parents_a = entry.parents(); 140 public void testChangesetTreeFollowRename() throws Exception {
141 Pair<Nodeid, Nodeid> parents_b = entry.parentRevisions(); 141 // FIXME better test with more than 1 rename, and renames not from the last revision (somewhere from the middle of the origin change history)
142 if (parents_b.first().isNull()) { 142 final String fname = "cmdline/org/tmatesoft/hg/console/Remote.java";
143 errorCollector.assertTrue(parents_a.first() == null); 143 assertTrue("[sanity]", repo.getFileNode(fname).exists());
144 } else { 144 eh.run("hg", "log", "--debug", "--follow", fname);
145 errorCollector.assertEquals(parents_b.first(), parents_a.first().getNodeid()); 145
146 } 146 TreeCollectHandler h = new TreeCollectHandler(true);
147 if (parents_b.second().isNull()) { 147 new HgLogCommand(repo).file(fname, true).execute(h);
148 errorCollector.assertTrue(parents_a.second() == null); 148
149 } else { 149 report("execute with HgChangesetTreeHandler(follow == true)", h.getResult(), false);
150 errorCollector.assertEquals(parents_b.second(), parents_a.second().getNodeid());
151 }
152 //
153 cmdResult.add(entry.changeset());
154 }
155 });
156 report("execute with HgChangesetTreeHandler", cmdResult, true);
157 } 150 }
158 151
159 private void report(String what, List<HgChangeset> r, boolean reverseConsoleResult) { 152 private void report(String what, List<HgChangeset> r, boolean reverseConsoleResult) {
160 final List<Record> consoleResult = changelogParser.getResult(); 153 final List<Record> consoleResult = changelogParser.getResult();
161 report(what, r, consoleResult, reverseConsoleResult, errorCollector); 154 report(what, r, consoleResult, reverseConsoleResult, errorCollector);
289 // 282 //
290 changelogParser.reset(); 283 changelogParser.reset();
291 eh.run("hg", "log", "--debug", "-b", "default", "-b", "test", "--cwd", repo.getLocation()); 284 eh.run("hg", "log", "--debug", "-b", "default", "-b", "test", "--cwd", repo.getLocation());
292 report("log -b default -b test" , new HgLogCommand(repo).branch("default").branch("test").execute(), true); 285 report("log -b default -b test" , new HgLogCommand(repo).branch("default").branch("test").execute(), true);
293 } 286 }
287
288 ////
289
290 private final class TreeCollectHandler implements HgChangesetTreeHandler {
291 private final LinkedList<HgChangeset> cmdResult = new LinkedList<HgChangeset>();
292 private final boolean reverseResult;
293
294 public TreeCollectHandler(boolean _reverseResult) {
295 this.reverseResult = _reverseResult;
296 }
297
298 public List<HgChangeset> getResult() {
299 return cmdResult;
300 }
301
302 public void treeElement(TreeElement entry) throws HgCallbackTargetException {
303 // check consistency
304 Nodeid cset = entry.changeset().getNodeid();
305 errorCollector.assertEquals(entry.changesetRevision(), cset);
306 Pair<HgChangeset, HgChangeset> parents_a = entry.parents();
307 Pair<Nodeid, Nodeid> parents_b = entry.parentRevisions();
308 if (parents_b.first().isNull()) {
309 errorCollector.assertTrue(parents_a.first() == null);
310 } else {
311 errorCollector.assertEquals(parents_b.first(), parents_a.first().getNodeid());
312 }
313 if (parents_b.second().isNull()) {
314 errorCollector.assertTrue(parents_a.second() == null);
315 } else {
316 errorCollector.assertEquals(parents_b.second(), parents_a.second().getNodeid());
317 }
318 //
319 if (reverseResult) {
320 cmdResult.addFirst(entry.changeset());
321 } else {
322 cmdResult.addLast(entry.changeset());
323 }
324 }
325
326
327 }
294 } 328 }