You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PlotCommitListTest.java 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. /*
  2. * Copyright (C) 2010, 2014 Christian Halstrick <christian.halstrick@sap.com>
  3. * and other copyright owners as documented in the project's IP log.
  4. *
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Distribution License v1.0 which
  7. * accompanies this distribution, is reproduced below, and is
  8. * available at http://www.eclipse.org/org/documents/edl-v10.php
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. *
  24. * - Neither the name of the Eclipse Foundation, Inc. nor the
  25. * names of its contributors may be used to endorse or promote
  26. * products derived from this software without specific prior
  27. * written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  30. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  31. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  41. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. */
  43. package org.eclipse.jgit.revplot;
  44. import static org.junit.Assert.assertArrayEquals;
  45. import static org.junit.Assert.assertEquals;
  46. import static org.junit.Assert.assertNotEquals;
  47. import static org.junit.Assert.assertTrue;
  48. import java.util.HashSet;
  49. import java.util.Set;
  50. import org.eclipse.jgit.revwalk.RevCommit;
  51. import org.eclipse.jgit.revwalk.RevWalkTestCase;
  52. import org.junit.Test;
  53. public class PlotCommitListTest extends RevWalkTestCase {
  54. class CommitListAssert {
  55. private PlotCommitList<PlotLane> pcl;
  56. private PlotCommit<PlotLane> current;
  57. private int nextIndex = 0;
  58. CommitListAssert(PlotCommitList<PlotLane> pcl) {
  59. this.pcl = pcl;
  60. }
  61. public CommitListAssert commit(RevCommit id) {
  62. assertTrue("Unexpected end of list at pos#"+nextIndex, pcl.size()>nextIndex);
  63. current = pcl.get(nextIndex++);
  64. assertEquals("Expected commit not found at pos#" + (nextIndex - 1),
  65. id.getId(), current.getId());
  66. return this;
  67. }
  68. public CommitListAssert lanePos(int pos) {
  69. PlotLane lane = current.getLane();
  70. assertEquals("Position of lane of commit #" + (nextIndex - 1)
  71. + " not as expected.", pos, lane.getPosition());
  72. return this;
  73. }
  74. public int getLanePos() {
  75. return current.getLane().position;
  76. }
  77. /**
  78. * Checks that the current position is valid and consumes this position.
  79. *
  80. * @param allowedPositions
  81. * @return this
  82. */
  83. public CommitListAssert lanePos(Set<Integer> allowedPositions) {
  84. PlotLane lane = current.getLane();
  85. @SuppressWarnings("boxing")
  86. boolean found = allowedPositions.remove(lane.getPosition());
  87. assertTrue("Position of lane of commit #" + (nextIndex - 1)
  88. + " not as expected. Expecting one of: " + allowedPositions + " Actual: "+ lane.getPosition(), found);
  89. return this;
  90. }
  91. public CommitListAssert nrOfPassingLanes(int lanes) {
  92. assertEquals("Number of passing lanes of commit #"
  93. + (nextIndex - 1)
  94. + " not as expected.", lanes, current.passingLanes.length);
  95. return this;
  96. }
  97. public CommitListAssert parents(RevCommit... parents) {
  98. assertEquals("Number of parents of commit #" + (nextIndex - 1)
  99. + " not as expected.", parents.length,
  100. current.getParentCount());
  101. for (int i = 0; i < parents.length; i++)
  102. assertEquals("Unexpected parent of commit #" + (nextIndex - 1),
  103. parents[i], current.getParent(i));
  104. return this;
  105. }
  106. public CommitListAssert noMoreCommits() {
  107. assertEquals("Unexpected size of list", nextIndex, pcl.size());
  108. return this;
  109. }
  110. }
  111. private static Set<Integer> asSet(int... numbers) {
  112. Set<Integer> result = new HashSet<Integer>();
  113. for (int n : numbers)
  114. result.add(Integer.valueOf(n));
  115. return result;
  116. }
  117. @Test
  118. public void testLinear() throws Exception {
  119. final RevCommit a = commit();
  120. final RevCommit b = commit(a);
  121. final RevCommit c = commit(b);
  122. PlotWalk pw = new PlotWalk(db);
  123. pw.markStart(pw.lookupCommit(c.getId()));
  124. PlotCommitList<PlotLane> pcl = new PlotCommitList<PlotLane>();
  125. pcl.source(pw);
  126. pcl.fillTo(Integer.MAX_VALUE);
  127. CommitListAssert test = new CommitListAssert(pcl);
  128. test.commit(c).lanePos(0).parents(b);
  129. test.commit(b).lanePos(0).parents(a);
  130. test.commit(a).lanePos(0).parents();
  131. test.noMoreCommits();
  132. }
  133. @Test
  134. public void testMerged() throws Exception {
  135. final RevCommit a = commit();
  136. final RevCommit b = commit(a);
  137. final RevCommit c = commit(a);
  138. final RevCommit d = commit(b, c);
  139. PlotWalk pw = new PlotWalk(db);
  140. pw.markStart(pw.lookupCommit(d.getId()));
  141. PlotCommitList<PlotLane> pcl = new PlotCommitList<PlotLane>();
  142. pcl.source(pw);
  143. pcl.fillTo(Integer.MAX_VALUE);
  144. CommitListAssert test = new CommitListAssert(pcl);
  145. test.commit(d).lanePos(0).parents(b, c);
  146. test.commit(c).lanePos(1).parents(a);
  147. test.commit(b).lanePos(0).parents(a);
  148. test.commit(a).lanePos(0).parents();
  149. test.noMoreCommits();
  150. }
  151. @Test
  152. public void testSideBranch() throws Exception {
  153. final RevCommit a = commit();
  154. final RevCommit b = commit(a);
  155. final RevCommit c = commit(a);
  156. PlotWalk pw = new PlotWalk(db);
  157. pw.markStart(pw.lookupCommit(b.getId()));
  158. pw.markStart(pw.lookupCommit(c.getId()));
  159. PlotCommitList<PlotLane> pcl = new PlotCommitList<PlotLane>();
  160. pcl.source(pw);
  161. pcl.fillTo(Integer.MAX_VALUE);
  162. Set<Integer> childPositions = asSet(0, 1);
  163. CommitListAssert test = new CommitListAssert(pcl);
  164. test.commit(c).lanePos(childPositions).parents(a);
  165. test.commit(b).lanePos(childPositions).parents(a);
  166. test.commit(a).lanePos(0).parents();
  167. test.noMoreCommits();
  168. }
  169. @Test
  170. public void test2SideBranches() throws Exception {
  171. final RevCommit a = commit();
  172. final RevCommit b = commit(a);
  173. final RevCommit c = commit(a);
  174. final RevCommit d = commit(a);
  175. PlotWalk pw = new PlotWalk(db);
  176. pw.markStart(pw.lookupCommit(b.getId()));
  177. pw.markStart(pw.lookupCommit(c.getId()));
  178. pw.markStart(pw.lookupCommit(d.getId()));
  179. PlotCommitList<PlotLane> pcl = new PlotCommitList<PlotLane>();
  180. pcl.source(pw);
  181. pcl.fillTo(Integer.MAX_VALUE);
  182. Set<Integer> childPositions = asSet(0, 1, 2);
  183. CommitListAssert test = new CommitListAssert(pcl);
  184. test.commit(d).lanePos(childPositions).parents(a);
  185. test.commit(c).lanePos(childPositions).parents(a);
  186. test.commit(b).lanePos(childPositions).parents(a);
  187. test.commit(a).lanePos(0).parents();
  188. test.noMoreCommits();
  189. }
  190. @Test
  191. public void testBug300282_1() throws Exception {
  192. final RevCommit a = commit();
  193. final RevCommit b = commit(a);
  194. final RevCommit c = commit(a);
  195. final RevCommit d = commit(a);
  196. final RevCommit e = commit(a);
  197. final RevCommit f = commit(a);
  198. final RevCommit g = commit(f);
  199. PlotWalk pw = new PlotWalk(db);
  200. // TODO: when we add unnecessary commit's as tips (e.g. a commit which
  201. // is a parent of another tip) the walk will return those commits twice.
  202. // Find out why!
  203. // pw.markStart(pw.lookupCommit(a.getId()));
  204. pw.markStart(pw.lookupCommit(b.getId()));
  205. pw.markStart(pw.lookupCommit(c.getId()));
  206. pw.markStart(pw.lookupCommit(d.getId()));
  207. pw.markStart(pw.lookupCommit(e.getId()));
  208. // pw.markStart(pw.lookupCommit(f.getId()));
  209. pw.markStart(pw.lookupCommit(g.getId()));
  210. PlotCommitList<PlotLane> pcl = new PlotCommitList<PlotLane>();
  211. pcl.source(pw);
  212. pcl.fillTo(Integer.MAX_VALUE);
  213. Set<Integer> childPositions = asSet(0, 1, 2, 3, 4);
  214. CommitListAssert test = new CommitListAssert(pcl);
  215. int posG = test.commit(g).lanePos(childPositions).parents(f)
  216. .getLanePos();
  217. test.commit(f).lanePos(posG).parents(a);
  218. test.commit(e).lanePos(childPositions).parents(a);
  219. test.commit(d).lanePos(childPositions).parents(a);
  220. test.commit(c).lanePos(childPositions).parents(a);
  221. test.commit(b).lanePos(childPositions).parents(a);
  222. test.commit(a).lanePos(0).parents();
  223. test.noMoreCommits();
  224. }
  225. @Test
  226. public void testBug368927() throws Exception {
  227. final RevCommit a = commit();
  228. final RevCommit b = commit(a);
  229. final RevCommit c = commit(b);
  230. final RevCommit d = commit(b);
  231. final RevCommit e = commit(c);
  232. final RevCommit f = commit(e, d);
  233. final RevCommit g = commit(a);
  234. final RevCommit h = commit(f);
  235. final RevCommit i = commit(h);
  236. PlotWalk pw = new PlotWalk(db);
  237. pw.markStart(pw.lookupCommit(i.getId()));
  238. pw.markStart(pw.lookupCommit(g.getId()));
  239. PlotCommitList<PlotLane> pcl = new PlotCommitList<PlotLane>();
  240. pcl.source(pw);
  241. pcl.fillTo(Integer.MAX_VALUE);
  242. Set<Integer> childPositions = asSet(0, 1);
  243. CommitListAssert test = new CommitListAssert(pcl);
  244. int posI = test.commit(i).lanePos(childPositions).parents(h)
  245. .getLanePos();
  246. test.commit(h).lanePos(posI).parents(f);
  247. test.commit(g).lanePos(childPositions).parents(a);
  248. test.commit(f).lanePos(posI).parents(e, d);
  249. test.commit(e).lanePos(posI).parents(c);
  250. test.commit(d).lanePos(2).parents(b);
  251. test.commit(c).lanePos(posI).parents(b);
  252. test.commit(b).lanePos(posI).parents(a);
  253. test.commit(a).lanePos(0).parents();
  254. }
  255. // test the history of the egit project between 9fdaf3c1 and e76ad9170f
  256. @Test
  257. public void testEgitHistory() throws Exception {
  258. final RevCommit merge_fix = commit();
  259. final RevCommit add_simple = commit(merge_fix);
  260. final RevCommit remove_unused = commit(merge_fix);
  261. final RevCommit merge_remove = commit(add_simple, remove_unused);
  262. final RevCommit resolve_handler = commit(merge_fix);
  263. final RevCommit clear_repositorycache = commit(merge_remove);
  264. final RevCommit add_Maven = commit(clear_repositorycache);
  265. final RevCommit use_remote = commit(clear_repositorycache);
  266. final RevCommit findToolBar_layout = commit(clear_repositorycache);
  267. final RevCommit merge_add_Maven = commit(findToolBar_layout, add_Maven);
  268. final RevCommit update_eclipse_iplog = commit(merge_add_Maven);
  269. final RevCommit changeset_implementation = commit(clear_repositorycache);
  270. final RevCommit merge_use_remote = commit(update_eclipse_iplog,
  271. use_remote);
  272. final RevCommit disable_source = commit(merge_use_remote);
  273. final RevCommit update_eclipse_iplog2 = commit(merge_use_remote);
  274. final RevCommit merge_disable_source = commit(update_eclipse_iplog2,
  275. disable_source);
  276. final RevCommit merge_changeset_implementation = commit(
  277. merge_disable_source, changeset_implementation);
  278. final RevCommit clone_operation = commit(merge_changeset_implementation);
  279. final RevCommit update_eclipse = commit(add_Maven);
  280. final RevCommit merge_resolve_handler = commit(clone_operation,
  281. resolve_handler);
  282. final RevCommit disable_comment = commit(clone_operation);
  283. final RevCommit merge_disable_comment = commit(merge_resolve_handler,
  284. disable_comment);
  285. final RevCommit fix_broken = commit(merge_disable_comment);
  286. final RevCommit add_a_clear = commit(fix_broken);
  287. final RevCommit merge_update_eclipse = commit(add_a_clear,
  288. update_eclipse);
  289. final RevCommit sort_roots = commit(merge_update_eclipse);
  290. final RevCommit fix_logged_npe = commit(merge_changeset_implementation);
  291. final RevCommit merge_fixed_logged_npe = commit(sort_roots,
  292. fix_logged_npe);
  293. PlotWalk pw = new PlotWalk(db);
  294. pw.markStart(pw.lookupCommit(merge_fixed_logged_npe.getId()));
  295. PlotCommitList<PlotLane> pcl = new PlotCommitList<PlotLane>();
  296. pcl.source(pw);
  297. pcl.fillTo(Integer.MAX_VALUE);
  298. CommitListAssert test = new CommitListAssert(pcl);
  299. // Note: all positions of side branches are rather arbitrary, but some
  300. // may not overlap. Testing for the positions yielded by the current
  301. // implementation, which was manually checked to not overlap.
  302. final int mainPos = 0;
  303. test.commit(merge_fixed_logged_npe).parents(sort_roots, fix_logged_npe)
  304. .lanePos(mainPos);
  305. test.commit(fix_logged_npe).parents(merge_changeset_implementation)
  306. .lanePos(1);
  307. test.commit(sort_roots).parents(merge_update_eclipse).lanePos(mainPos);
  308. test.commit(merge_update_eclipse).parents(add_a_clear, update_eclipse)
  309. .lanePos(mainPos);
  310. test.commit(add_a_clear).parents(fix_broken).lanePos(mainPos);
  311. test.commit(fix_broken).parents(merge_disable_comment).lanePos(mainPos);
  312. test.commit(merge_disable_comment)
  313. .parents(merge_resolve_handler, disable_comment)
  314. .lanePos(mainPos);
  315. test.commit(disable_comment).parents(clone_operation).lanePos(2);
  316. test.commit(merge_resolve_handler)
  317. .parents(clone_operation, resolve_handler).lanePos(mainPos);
  318. test.commit(update_eclipse).parents(add_Maven).lanePos(3);
  319. test.commit(clone_operation).parents(merge_changeset_implementation)
  320. .lanePos(mainPos);
  321. test.commit(merge_changeset_implementation)
  322. .parents(merge_disable_source, changeset_implementation)
  323. .lanePos(mainPos);
  324. test.commit(merge_disable_source)
  325. .parents(update_eclipse_iplog2, disable_source)
  326. .lanePos(mainPos);
  327. test.commit(update_eclipse_iplog2).parents(merge_use_remote)
  328. .lanePos(mainPos);
  329. test.commit(disable_source).parents(merge_use_remote).lanePos(1);
  330. test.commit(merge_use_remote).parents(update_eclipse_iplog, use_remote)
  331. .lanePos(mainPos);
  332. test.commit(changeset_implementation).parents(clear_repositorycache)
  333. .lanePos(2);
  334. test.commit(update_eclipse_iplog).parents(merge_add_Maven)
  335. .lanePos(mainPos);
  336. test.commit(merge_add_Maven).parents(findToolBar_layout, add_Maven)
  337. .lanePos(mainPos);
  338. test.commit(findToolBar_layout).parents(clear_repositorycache)
  339. .lanePos(mainPos);
  340. test.commit(use_remote).parents(clear_repositorycache).lanePos(1);
  341. test.commit(add_Maven).parents(clear_repositorycache).lanePos(3);
  342. test.commit(clear_repositorycache).parents(merge_remove)
  343. .lanePos(mainPos);
  344. test.commit(resolve_handler).parents(merge_fix).lanePos(4);
  345. test.commit(merge_remove).parents(add_simple, remove_unused)
  346. .lanePos(mainPos);
  347. test.commit(remove_unused).parents(merge_fix).lanePos(1);
  348. test.commit(add_simple).parents(merge_fix).lanePos(mainPos);
  349. test.commit(merge_fix).parents().lanePos(mainPos);
  350. test.noMoreCommits();
  351. }
  352. /**
  353. * The graph shows the problematic original positioning. Due to this some
  354. * lanes are no straight lines here, but they are with the new layout code)
  355. *
  356. * <pre>
  357. * a5
  358. * | \
  359. * | a4
  360. * | /
  361. * a3
  362. * |
  363. * | e
  364. * | \
  365. * | |
  366. * | b3 |
  367. * | | d
  368. * | |/
  369. * | /|
  370. * |/ |
  371. * a2 |
  372. * | b2
  373. * | \
  374. * | c |
  375. * | / /
  376. * |/ b1
  377. * a1
  378. * </pre>
  379. *
  380. * @throws Exception
  381. */
  382. @Test
  383. public void testBug419359() throws Exception {
  384. // this may not be the exact situation of bug 419359 but it shows
  385. // similar behavior
  386. final RevCommit a1 = commit();
  387. final RevCommit b1 = commit();
  388. final RevCommit c = commit(a1);
  389. final RevCommit b2 = commit(b1);
  390. final RevCommit a2 = commit(a1);
  391. final RevCommit d = commit(a2);
  392. final RevCommit b3 = commit(b2);
  393. final RevCommit e = commit(d);
  394. final RevCommit a3 = commit(a2);
  395. final RevCommit a4 = commit(a3);
  396. final RevCommit a5 = commit(a3, a4);
  397. PlotWalk pw = new PlotWalk(db);
  398. pw.markStart(pw.lookupCommit(b3.getId()));
  399. pw.markStart(pw.lookupCommit(c.getId()));
  400. pw.markStart(pw.lookupCommit(e.getId()));
  401. pw.markStart(pw.lookupCommit(a5.getId()));
  402. PlotCommitList<PlotLane> pcl = new PlotCommitList<PlotLane>();
  403. pcl.source(pw);
  404. pcl.fillTo(Integer.MAX_VALUE);
  405. // test that the commits b1, b2 and b3 are on the same position
  406. int bPos = pcl.get(9).lane.position; // b1
  407. assertEquals("b2 is an a different position", bPos,
  408. pcl.get(7).lane.position);
  409. assertEquals("b3 is on a different position", bPos,
  410. pcl.get(4).lane.position);
  411. // test that nothing blocks the connections between b1, b2 and b3
  412. assertNotEquals("b lane is blocked by c", bPos,
  413. pcl.get(8).lane.position);
  414. assertNotEquals("b lane is blocked by a2", bPos,
  415. pcl.get(6).lane.position);
  416. assertNotEquals("b lane is blocked by d", bPos,
  417. pcl.get(5).lane.position);
  418. }
  419. /**
  420. * <pre>
  421. * b3
  422. * a4 |
  423. * | \|
  424. * | b2
  425. * a3 |
  426. * | \|
  427. * a2 |
  428. * | b1
  429. * | /
  430. * a1
  431. * </pre>
  432. *
  433. * @throws Exception
  434. */
  435. @Test
  436. public void testMultipleMerges() throws Exception {
  437. final RevCommit a1 = commit();
  438. final RevCommit b1 = commit(a1);
  439. final RevCommit a2 = commit(a1);
  440. final RevCommit a3 = commit(a2, b1);
  441. final RevCommit b2 = commit(b1);
  442. final RevCommit a4 = commit(a3, b2);
  443. final RevCommit b3 = commit(b2);
  444. PlotWalk pw = new PlotWalk(db);
  445. pw.markStart(pw.lookupCommit(a4));
  446. pw.markStart(pw.lookupCommit(b3));
  447. PlotCommitList<PlotLane> pcl = new PlotCommitList<PlotLane>();
  448. pcl.source(pw);
  449. pcl.fillTo(Integer.MAX_VALUE);
  450. Set<Integer> positions = asSet(0, 1);
  451. CommitListAssert test = new CommitListAssert(pcl);
  452. int posB = test.commit(b3).lanePos(positions).getLanePos();
  453. int posA = test.commit(a4).lanePos(positions).getLanePos();
  454. test.commit(b2).lanePos(posB);
  455. test.commit(a3).lanePos(posA);
  456. test.commit(a2).lanePos(posA);
  457. test.commit(b1).lanePos(posB);
  458. test.commit(a1).lanePos(posA);
  459. test.noMoreCommits();
  460. }
  461. /**
  462. * <pre>
  463. * a4
  464. * | b3
  465. * a3 |
  466. * | \\|
  467. * | |\\
  468. * | b2||
  469. * a2 | //
  470. * | b1
  471. * | /
  472. * a1
  473. * </pre>
  474. *
  475. * @throws Exception
  476. */
  477. @Test
  478. public void testMergeBlockedBySelf() throws Exception {
  479. final RevCommit a1 = commit();
  480. final RevCommit b1 = commit(a1);
  481. final RevCommit a2 = commit(a1);
  482. final RevCommit b2 = commit(b1); // blocks merging arc
  483. final RevCommit a3 = commit(a2, b1);
  484. final RevCommit b3 = commit(b2);
  485. final RevCommit a4 = commit(a3);
  486. PlotWalk pw = new PlotWalk(db);
  487. pw.markStart(pw.lookupCommit(a4));
  488. pw.markStart(pw.lookupCommit(b3));
  489. PlotCommitList<PlotLane> pcl = new PlotCommitList<PlotLane>();
  490. pcl.source(pw);
  491. pcl.fillTo(Integer.MAX_VALUE);
  492. Set<Integer> positions = asSet(0, 1);
  493. CommitListAssert test = new CommitListAssert(pcl);
  494. int posA = test.commit(a4).lanePos(positions).getLanePos();
  495. int posB = test.commit(b3).lanePos(positions).getLanePos();
  496. test.commit(a3).lanePos(posA);
  497. test.commit(b2).lanePos(posB);
  498. test.commit(a2).lanePos(posA);
  499. // b1 is not repositioned, uses "detour lane"
  500. // (drawn as a double arc in the ascii graph above)
  501. test.commit(b1).lanePos(posB);
  502. test.commit(a1).lanePos(posA);
  503. test.noMoreCommits();
  504. }
  505. /**
  506. * <pre>
  507. * b2
  508. * a4 |
  509. * | \ |
  510. * a3 \|
  511. * | \ |
  512. * | c |
  513. * | / |
  514. * a2 |
  515. * | b1
  516. * /
  517. * | /
  518. * a1
  519. * </pre>
  520. *
  521. * @throws Exception
  522. */
  523. @Test
  524. public void testMergeBlockedByOther() throws Exception {
  525. final RevCommit a1 = commit();
  526. final RevCommit b1 = commit(a1);
  527. final RevCommit a2 = commit(a1);
  528. final RevCommit c = commit(a2);// blocks merging arc
  529. final RevCommit a3 = commit(a2, c);
  530. final RevCommit a4 = commit(a3, b1);
  531. final RevCommit b2 = commit(b1);
  532. PlotWalk pw = new PlotWalk(db);
  533. pw.markStart(pw.lookupCommit(a4));
  534. pw.markStart(pw.lookupCommit(b2));
  535. pw.markStart(pw.lookupCommit(c));
  536. PlotCommitList<PlotLane> pcl = new PlotCommitList<PlotLane>();
  537. pcl.source(pw);
  538. pcl.fillTo(Integer.MAX_VALUE);
  539. Set<Integer> positions = asSet(0, 1, 2);
  540. CommitListAssert test = new CommitListAssert(pcl);
  541. int posB = test.commit(b2).lanePos(positions).getLanePos();
  542. int posA = test.commit(a4).lanePos(positions).getLanePos();
  543. test.commit(a3).lanePos(posA);
  544. test.commit(c).lanePos(positions);
  545. test.commit(a2).lanePos(posA);
  546. test.commit(b1).lanePos(posB); // repositioned to go around c
  547. test.commit(a1).lanePos(posA);
  548. test.noMoreCommits();
  549. }
  550. /**
  551. * <pre>
  552. * b1
  553. * a3 |
  554. * | |
  555. * a2 |
  556. * -- processing stops here --
  557. * | /
  558. * a1
  559. * </pre>
  560. *
  561. * @throws Exception
  562. */
  563. @Test
  564. public void testDanglingCommitShouldContinueLane() throws Exception {
  565. final RevCommit a1 = commit();
  566. final RevCommit a2 = commit(a1);
  567. final RevCommit a3 = commit(a2);
  568. final RevCommit b1 = commit(a1);
  569. PlotWalk pw = new PlotWalk(db);
  570. pw.markStart(pw.lookupCommit(a3));
  571. pw.markStart(pw.lookupCommit(b1));
  572. PlotCommitList<PlotLane> pcl = new PlotCommitList<PlotLane>();
  573. pcl.source(pw);
  574. pcl.fillTo(2); // don't process a1
  575. Set<Integer> positions = asSet(0, 1);
  576. CommitListAssert test = new CommitListAssert(pcl);
  577. PlotLane laneB = test.commit(b1).lanePos(positions).current.getLane();
  578. int posA = test.commit(a3).lanePos(positions).getLanePos();
  579. test.commit(a2).lanePos(posA);
  580. assertArrayEquals(
  581. "Although the parent of b1, a1, is not processed yet, the b lane should still be drawn",
  582. new PlotLane[] { laneB }, test.current.passingLanes);
  583. test.noMoreCommits();
  584. }
  585. @Test
  586. public void testTwoRoots1() throws Exception {
  587. final RevCommit a = commit();
  588. final RevCommit b = commit();
  589. PlotWalk pw = new PlotWalk(db);
  590. pw.markStart(pw.lookupCommit(a));
  591. pw.markStart(pw.lookupCommit(b));
  592. PlotCommitList<PlotLane> pcl = new PlotCommitList<PlotLane>();
  593. pcl.source(pw);
  594. pcl.fillTo(Integer.MAX_VALUE);
  595. CommitListAssert test = new CommitListAssert(pcl);
  596. test.commit(b).lanePos(0);
  597. test.commit(a).lanePos(0);
  598. test.noMoreCommits();
  599. }
  600. @Test
  601. public void testTwoRoots2() throws Exception {
  602. final RevCommit a = commit();
  603. final RevCommit b1 = commit();
  604. final RevCommit b2 = commit(b1);
  605. PlotWalk pw = new PlotWalk(db);
  606. pw.markStart(pw.lookupCommit(a));
  607. pw.markStart(pw.lookupCommit(b2));
  608. PlotCommitList<PlotLane> pcl = new PlotCommitList<PlotLane>();
  609. pcl.source(pw);
  610. pcl.fillTo(Integer.MAX_VALUE);
  611. CommitListAssert test = new CommitListAssert(pcl);
  612. test.commit(b2).lanePos(0);
  613. test.commit(b1).lanePos(0);
  614. test.commit(a).lanePos(0);
  615. test.noMoreCommits();
  616. }
  617. }