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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  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<>();
  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<>();
  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<>();
  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<>();
  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<>();
  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<>();
  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<>();
  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<>();
  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. // test a history where a merge commit has two time the same parent
  353. @Test
  354. public void testDuplicateParents() throws Exception {
  355. final RevCommit m1 = commit();
  356. final RevCommit m2 = commit(m1);
  357. final RevCommit m3 = commit(m2, m2);
  358. final RevCommit s1 = commit(m2);
  359. final RevCommit s2 = commit(s1);
  360. PlotWalk pw = new PlotWalk(db);
  361. pw.markStart(pw.lookupCommit(m3));
  362. pw.markStart(pw.lookupCommit(s2));
  363. PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
  364. pcl.source(pw);
  365. pcl.fillTo(Integer.MAX_VALUE);
  366. CommitListAssert test = new CommitListAssert(pcl);
  367. test.commit(s2).nrOfPassingLanes(0);
  368. test.commit(s1).nrOfPassingLanes(0);
  369. test.commit(m3).nrOfPassingLanes(1);
  370. test.commit(m2).nrOfPassingLanes(0);
  371. test.commit(m1).nrOfPassingLanes(0);
  372. test.noMoreCommits();
  373. }
  374. /**
  375. * The graph shows the problematic original positioning. Due to this some
  376. * lanes are no straight lines here, but they are with the new layout code)
  377. *
  378. * <pre>
  379. * a5
  380. * | \
  381. * | a4
  382. * | /
  383. * a3
  384. * |
  385. * | e
  386. * | \
  387. * | |
  388. * | b3 |
  389. * | | d
  390. * | |/
  391. * | /|
  392. * |/ |
  393. * a2 |
  394. * | b2
  395. * | \
  396. * | c |
  397. * | / /
  398. * |/ b1
  399. * a1
  400. * </pre>
  401. *
  402. * @throws Exception
  403. */
  404. @Test
  405. public void testBug419359() throws Exception {
  406. // this may not be the exact situation of bug 419359 but it shows
  407. // similar behavior
  408. final RevCommit a1 = commit();
  409. final RevCommit b1 = commit();
  410. final RevCommit c = commit(a1);
  411. final RevCommit b2 = commit(b1);
  412. final RevCommit a2 = commit(a1);
  413. final RevCommit d = commit(a2);
  414. final RevCommit b3 = commit(b2);
  415. final RevCommit e = commit(d);
  416. final RevCommit a3 = commit(a2);
  417. final RevCommit a4 = commit(a3);
  418. final RevCommit a5 = commit(a3, a4);
  419. PlotWalk pw = new PlotWalk(db);
  420. pw.markStart(pw.lookupCommit(b3.getId()));
  421. pw.markStart(pw.lookupCommit(c.getId()));
  422. pw.markStart(pw.lookupCommit(e.getId()));
  423. pw.markStart(pw.lookupCommit(a5.getId()));
  424. PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
  425. pcl.source(pw);
  426. pcl.fillTo(Integer.MAX_VALUE);
  427. // test that the commits b1, b2 and b3 are on the same position
  428. int bPos = pcl.get(9).lane.position; // b1
  429. assertEquals("b2 is an a different position", bPos,
  430. pcl.get(7).lane.position);
  431. assertEquals("b3 is on a different position", bPos,
  432. pcl.get(4).lane.position);
  433. // test that nothing blocks the connections between b1, b2 and b3
  434. assertNotEquals("b lane is blocked by c", bPos,
  435. pcl.get(8).lane.position);
  436. assertNotEquals("b lane is blocked by a2", bPos,
  437. pcl.get(6).lane.position);
  438. assertNotEquals("b lane is blocked by d", bPos,
  439. pcl.get(5).lane.position);
  440. }
  441. /**
  442. * <pre>
  443. * b3
  444. * a4 |
  445. * | \|
  446. * | b2
  447. * a3 |
  448. * | \|
  449. * a2 |
  450. * | b1
  451. * | /
  452. * a1
  453. * </pre>
  454. *
  455. * @throws Exception
  456. */
  457. @Test
  458. public void testMultipleMerges() throws Exception {
  459. final RevCommit a1 = commit();
  460. final RevCommit b1 = commit(a1);
  461. final RevCommit a2 = commit(a1);
  462. final RevCommit a3 = commit(a2, b1);
  463. final RevCommit b2 = commit(b1);
  464. final RevCommit a4 = commit(a3, b2);
  465. final RevCommit b3 = commit(b2);
  466. PlotWalk pw = new PlotWalk(db);
  467. pw.markStart(pw.lookupCommit(a4));
  468. pw.markStart(pw.lookupCommit(b3));
  469. PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
  470. pcl.source(pw);
  471. pcl.fillTo(Integer.MAX_VALUE);
  472. Set<Integer> positions = asSet(0, 1);
  473. CommitListAssert test = new CommitListAssert(pcl);
  474. int posB = test.commit(b3).lanePos(positions).getLanePos();
  475. int posA = test.commit(a4).lanePos(positions).getLanePos();
  476. test.commit(b2).lanePos(posB);
  477. test.commit(a3).lanePos(posA);
  478. test.commit(a2).lanePos(posA);
  479. test.commit(b1).lanePos(posB);
  480. test.commit(a1).lanePos(posA);
  481. test.noMoreCommits();
  482. }
  483. /**
  484. * <pre>
  485. * a4
  486. * | b3
  487. * a3 |
  488. * | \\|
  489. * | |\\
  490. * | b2||
  491. * a2 | //
  492. * | b1
  493. * | /
  494. * a1
  495. * </pre>
  496. *
  497. * @throws Exception
  498. */
  499. @Test
  500. public void testMergeBlockedBySelf() throws Exception {
  501. final RevCommit a1 = commit();
  502. final RevCommit b1 = commit(a1);
  503. final RevCommit a2 = commit(a1);
  504. final RevCommit b2 = commit(b1); // blocks merging arc
  505. final RevCommit a3 = commit(a2, b1);
  506. final RevCommit b3 = commit(b2);
  507. final RevCommit a4 = commit(a3);
  508. PlotWalk pw = new PlotWalk(db);
  509. pw.markStart(pw.lookupCommit(a4));
  510. pw.markStart(pw.lookupCommit(b3));
  511. PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
  512. pcl.source(pw);
  513. pcl.fillTo(Integer.MAX_VALUE);
  514. Set<Integer> positions = asSet(0, 1);
  515. CommitListAssert test = new CommitListAssert(pcl);
  516. int posA = test.commit(a4).lanePos(positions).getLanePos();
  517. int posB = test.commit(b3).lanePos(positions).getLanePos();
  518. test.commit(a3).lanePos(posA);
  519. test.commit(b2).lanePos(posB);
  520. test.commit(a2).lanePos(posA);
  521. // b1 is not repositioned, uses "detour lane"
  522. // (drawn as a double arc in the ascii graph above)
  523. test.commit(b1).lanePos(posB);
  524. test.commit(a1).lanePos(posA);
  525. test.noMoreCommits();
  526. }
  527. /**
  528. * <pre>
  529. * b2
  530. * a4 |
  531. * | \ |
  532. * a3 \|
  533. * | \ |
  534. * | c |
  535. * | / |
  536. * a2 |
  537. * | b1
  538. * /
  539. * | /
  540. * a1
  541. * </pre>
  542. *
  543. * @throws Exception
  544. */
  545. @Test
  546. public void testMergeBlockedByOther() throws Exception {
  547. final RevCommit a1 = commit();
  548. final RevCommit b1 = commit(a1);
  549. final RevCommit a2 = commit(a1);
  550. final RevCommit c = commit(a2);// blocks merging arc
  551. final RevCommit a3 = commit(a2, c);
  552. final RevCommit a4 = commit(a3, b1);
  553. final RevCommit b2 = commit(b1);
  554. PlotWalk pw = new PlotWalk(db);
  555. pw.markStart(pw.lookupCommit(a4));
  556. pw.markStart(pw.lookupCommit(b2));
  557. pw.markStart(pw.lookupCommit(c));
  558. PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
  559. pcl.source(pw);
  560. pcl.fillTo(Integer.MAX_VALUE);
  561. Set<Integer> positions = asSet(0, 1, 2);
  562. CommitListAssert test = new CommitListAssert(pcl);
  563. int posB = test.commit(b2).lanePos(positions).getLanePos();
  564. int posA = test.commit(a4).lanePos(positions).getLanePos();
  565. test.commit(a3).lanePos(posA);
  566. test.commit(c).lanePos(positions);
  567. test.commit(a2).lanePos(posA);
  568. test.commit(b1).lanePos(posB); // repositioned to go around c
  569. test.commit(a1).lanePos(posA);
  570. test.noMoreCommits();
  571. }
  572. /**
  573. * <pre>
  574. * b1
  575. * a3 |
  576. * | |
  577. * a2 |
  578. * -- processing stops here --
  579. * | /
  580. * a1
  581. * </pre>
  582. *
  583. * @throws Exception
  584. */
  585. @Test
  586. public void testDanglingCommitShouldContinueLane() throws Exception {
  587. final RevCommit a1 = commit();
  588. final RevCommit a2 = commit(a1);
  589. final RevCommit a3 = commit(a2);
  590. final RevCommit b1 = commit(a1);
  591. PlotWalk pw = new PlotWalk(db);
  592. pw.markStart(pw.lookupCommit(a3));
  593. pw.markStart(pw.lookupCommit(b1));
  594. PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
  595. pcl.source(pw);
  596. pcl.fillTo(2); // don't process a1
  597. Set<Integer> positions = asSet(0, 1);
  598. CommitListAssert test = new CommitListAssert(pcl);
  599. PlotLane laneB = test.commit(b1).lanePos(positions).current.getLane();
  600. int posA = test.commit(a3).lanePos(positions).getLanePos();
  601. test.commit(a2).lanePos(posA);
  602. assertArrayEquals(
  603. "Although the parent of b1, a1, is not processed yet, the b lane should still be drawn",
  604. new PlotLane[] { laneB }, test.current.passingLanes);
  605. test.noMoreCommits();
  606. }
  607. @Test
  608. public void testTwoRoots1() throws Exception {
  609. final RevCommit a = commit();
  610. final RevCommit b = commit();
  611. PlotWalk pw = new PlotWalk(db);
  612. pw.markStart(pw.lookupCommit(a));
  613. pw.markStart(pw.lookupCommit(b));
  614. PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
  615. pcl.source(pw);
  616. pcl.fillTo(Integer.MAX_VALUE);
  617. CommitListAssert test = new CommitListAssert(pcl);
  618. test.commit(b).lanePos(0);
  619. test.commit(a).lanePos(0);
  620. test.noMoreCommits();
  621. }
  622. @Test
  623. public void testTwoRoots2() throws Exception {
  624. final RevCommit a = commit();
  625. final RevCommit b1 = commit();
  626. final RevCommit b2 = commit(b1);
  627. PlotWalk pw = new PlotWalk(db);
  628. pw.markStart(pw.lookupCommit(a));
  629. pw.markStart(pw.lookupCommit(b2));
  630. PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
  631. pcl.source(pw);
  632. pcl.fillTo(Integer.MAX_VALUE);
  633. CommitListAssert test = new CommitListAssert(pcl);
  634. test.commit(b2).lanePos(0);
  635. test.commit(b1).lanePos(0);
  636. test.commit(a).lanePos(0);
  637. test.noMoreCommits();
  638. }
  639. }