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 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. /*
  2. * Copyright (C) 2010, 2014 Christian Halstrick <christian.halstrick@sap.com> and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.revplot;
  11. import static org.junit.Assert.assertArrayEquals;
  12. import static org.junit.Assert.assertEquals;
  13. import static org.junit.Assert.assertNotEquals;
  14. import static org.junit.Assert.assertTrue;
  15. import java.util.HashSet;
  16. import java.util.Set;
  17. import org.eclipse.jgit.revwalk.RevCommit;
  18. import org.eclipse.jgit.revwalk.RevWalkTestCase;
  19. import org.junit.Test;
  20. public class PlotCommitListTest extends RevWalkTestCase {
  21. static class CommitListAssert {
  22. private PlotCommitList<PlotLane> pcl;
  23. private PlotCommit<PlotLane> current;
  24. private int nextIndex = 0;
  25. CommitListAssert(PlotCommitList<PlotLane> pcl) {
  26. this.pcl = pcl;
  27. }
  28. public CommitListAssert commit(RevCommit id) {
  29. assertTrue("Unexpected end of list at pos#"+nextIndex, pcl.size()>nextIndex);
  30. current = pcl.get(nextIndex++);
  31. assertEquals("Expected commit not found at pos#" + (nextIndex - 1),
  32. id.getId(), current.getId());
  33. return this;
  34. }
  35. public CommitListAssert lanePos(int pos) {
  36. PlotLane lane = current.getLane();
  37. assertEquals("Position of lane of commit #" + (nextIndex - 1)
  38. + " not as expected.", pos, lane.getPosition());
  39. return this;
  40. }
  41. public int getLanePos() {
  42. return current.getLane().position;
  43. }
  44. /**
  45. * Checks that the current position is valid and consumes this position.
  46. *
  47. * @param allowedPositions
  48. * @return this
  49. */
  50. public CommitListAssert lanePos(Set<Integer> allowedPositions) {
  51. PlotLane lane = current.getLane();
  52. @SuppressWarnings("boxing")
  53. boolean found = allowedPositions.remove(lane.getPosition());
  54. assertTrue("Position of lane of commit #" + (nextIndex - 1)
  55. + " not as expected. Expecting one of: " + allowedPositions + " Actual: "+ lane.getPosition(), found);
  56. return this;
  57. }
  58. public CommitListAssert nrOfPassingLanes(int lanes) {
  59. assertEquals("Number of passing lanes of commit #"
  60. + (nextIndex - 1)
  61. + " not as expected.", lanes, current.passingLanes.length);
  62. return this;
  63. }
  64. public CommitListAssert parents(RevCommit... parents) {
  65. assertEquals("Number of parents of commit #" + (nextIndex - 1)
  66. + " not as expected.", parents.length,
  67. current.getParentCount());
  68. for (int i = 0; i < parents.length; i++)
  69. assertEquals("Unexpected parent of commit #" + (nextIndex - 1),
  70. parents[i], current.getParent(i));
  71. return this;
  72. }
  73. public CommitListAssert noMoreCommits() {
  74. assertEquals("Unexpected size of list", nextIndex, pcl.size());
  75. return this;
  76. }
  77. }
  78. private static Set<Integer> asSet(int... numbers) {
  79. Set<Integer> result = new HashSet<>();
  80. for (int n : numbers)
  81. result.add(Integer.valueOf(n));
  82. return result;
  83. }
  84. @Test
  85. public void testLinear() throws Exception {
  86. final RevCommit a = commit();
  87. final RevCommit b = commit(a);
  88. final RevCommit c = commit(b);
  89. try (PlotWalk pw = new PlotWalk(db)) {
  90. pw.markStart(pw.lookupCommit(c.getId()));
  91. PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
  92. pcl.source(pw);
  93. pcl.fillTo(Integer.MAX_VALUE);
  94. CommitListAssert test = new CommitListAssert(pcl);
  95. test.commit(c).lanePos(0).parents(b);
  96. test.commit(b).lanePos(0).parents(a);
  97. test.commit(a).lanePos(0).parents();
  98. test.noMoreCommits();
  99. }
  100. }
  101. @Test
  102. public void testMerged() throws Exception {
  103. final RevCommit a = commit();
  104. final RevCommit b = commit(a);
  105. final RevCommit c = commit(a);
  106. final RevCommit d = commit(b, c);
  107. try (PlotWalk pw = new PlotWalk(db)) {
  108. pw.markStart(pw.lookupCommit(d.getId()));
  109. PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
  110. pcl.source(pw);
  111. pcl.fillTo(Integer.MAX_VALUE);
  112. CommitListAssert test = new CommitListAssert(pcl);
  113. test.commit(d).lanePos(0).parents(b, c);
  114. test.commit(c).lanePos(1).parents(a);
  115. test.commit(b).lanePos(0).parents(a);
  116. test.commit(a).lanePos(0).parents();
  117. test.noMoreCommits();
  118. }
  119. }
  120. @Test
  121. public void testSideBranch() throws Exception {
  122. final RevCommit a = commit();
  123. final RevCommit b = commit(a);
  124. final RevCommit c = commit(a);
  125. try (PlotWalk pw = new PlotWalk(db)) {
  126. pw.markStart(pw.lookupCommit(b.getId()));
  127. pw.markStart(pw.lookupCommit(c.getId()));
  128. PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
  129. pcl.source(pw);
  130. pcl.fillTo(Integer.MAX_VALUE);
  131. Set<Integer> childPositions = asSet(0, 1);
  132. CommitListAssert test = new CommitListAssert(pcl);
  133. test.commit(c).lanePos(childPositions).parents(a);
  134. test.commit(b).lanePos(childPositions).parents(a);
  135. test.commit(a).lanePos(0).parents();
  136. test.noMoreCommits();
  137. }
  138. }
  139. @Test
  140. public void test2SideBranches() throws Exception {
  141. final RevCommit a = commit();
  142. final RevCommit b = commit(a);
  143. final RevCommit c = commit(a);
  144. final RevCommit d = commit(a);
  145. try (PlotWalk pw = new PlotWalk(db)) {
  146. pw.markStart(pw.lookupCommit(b.getId()));
  147. pw.markStart(pw.lookupCommit(c.getId()));
  148. pw.markStart(pw.lookupCommit(d.getId()));
  149. PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
  150. pcl.source(pw);
  151. pcl.fillTo(Integer.MAX_VALUE);
  152. Set<Integer> childPositions = asSet(0, 1, 2);
  153. CommitListAssert test = new CommitListAssert(pcl);
  154. test.commit(d).lanePos(childPositions).parents(a);
  155. test.commit(c).lanePos(childPositions).parents(a);
  156. test.commit(b).lanePos(childPositions).parents(a);
  157. test.commit(a).lanePos(0).parents();
  158. test.noMoreCommits();
  159. }
  160. }
  161. @Test
  162. public void testBug300282_1() throws Exception {
  163. final RevCommit a = commit();
  164. final RevCommit b = commit(a);
  165. final RevCommit c = commit(a);
  166. final RevCommit d = commit(a);
  167. final RevCommit e = commit(a);
  168. final RevCommit f = commit(a);
  169. final RevCommit g = commit(f);
  170. try (PlotWalk pw = new PlotWalk(db)) {
  171. // TODO: when we add unnecessary commit's as tips (e.g. a commit
  172. // which is a parent of another tip) the walk will return those
  173. // commits twice. Find out why!
  174. // pw.markStart(pw.lookupCommit(a.getId()));
  175. pw.markStart(pw.lookupCommit(b.getId()));
  176. pw.markStart(pw.lookupCommit(c.getId()));
  177. pw.markStart(pw.lookupCommit(d.getId()));
  178. pw.markStart(pw.lookupCommit(e.getId()));
  179. // pw.markStart(pw.lookupCommit(f.getId()));
  180. pw.markStart(pw.lookupCommit(g.getId()));
  181. PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
  182. pcl.source(pw);
  183. pcl.fillTo(Integer.MAX_VALUE);
  184. Set<Integer> childPositions = asSet(0, 1, 2, 3, 4);
  185. CommitListAssert test = new CommitListAssert(pcl);
  186. int posG = test.commit(g).lanePos(childPositions).parents(f)
  187. .getLanePos();
  188. test.commit(f).lanePos(posG).parents(a);
  189. test.commit(e).lanePos(childPositions).parents(a);
  190. test.commit(d).lanePos(childPositions).parents(a);
  191. test.commit(c).lanePos(childPositions).parents(a);
  192. test.commit(b).lanePos(childPositions).parents(a);
  193. test.commit(a).lanePos(0).parents();
  194. test.noMoreCommits();
  195. }
  196. }
  197. @Test
  198. public void testBug368927() throws Exception {
  199. final RevCommit a = commit();
  200. final RevCommit b = commit(a);
  201. final RevCommit c = commit(b);
  202. final RevCommit d = commit(b);
  203. final RevCommit e = commit(c);
  204. final RevCommit f = commit(e, d);
  205. final RevCommit g = commit(a);
  206. final RevCommit h = commit(f);
  207. final RevCommit i = commit(h);
  208. try (PlotWalk pw = new PlotWalk(db)) {
  209. pw.markStart(pw.lookupCommit(i.getId()));
  210. pw.markStart(pw.lookupCommit(g.getId()));
  211. PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
  212. pcl.source(pw);
  213. pcl.fillTo(Integer.MAX_VALUE);
  214. Set<Integer> childPositions = asSet(0, 1);
  215. CommitListAssert test = new CommitListAssert(pcl);
  216. int posI = test.commit(i).lanePos(childPositions).parents(h)
  217. .getLanePos();
  218. test.commit(h).lanePos(posI).parents(f);
  219. test.commit(g).lanePos(childPositions).parents(a);
  220. test.commit(f).lanePos(posI).parents(e, d);
  221. test.commit(e).lanePos(posI).parents(c);
  222. test.commit(d).lanePos(2).parents(b);
  223. test.commit(c).lanePos(posI).parents(b);
  224. test.commit(b).lanePos(posI).parents(a);
  225. test.commit(a).lanePos(0).parents();
  226. }
  227. }
  228. // test the history of the egit project between 9fdaf3c1 and e76ad9170f
  229. @Test
  230. public void testEgitHistory() throws Exception {
  231. final RevCommit merge_fix = commit();
  232. final RevCommit add_simple = commit(merge_fix);
  233. final RevCommit remove_unused = commit(merge_fix);
  234. final RevCommit merge_remove = commit(add_simple, remove_unused);
  235. final RevCommit resolve_handler = commit(merge_fix);
  236. final RevCommit clear_repositorycache = commit(merge_remove);
  237. final RevCommit add_Maven = commit(clear_repositorycache);
  238. final RevCommit use_remote = commit(clear_repositorycache);
  239. final RevCommit findToolBar_layout = commit(clear_repositorycache);
  240. final RevCommit merge_add_Maven = commit(findToolBar_layout, add_Maven);
  241. final RevCommit update_eclipse_iplog = commit(merge_add_Maven);
  242. final RevCommit changeset_implementation = commit(clear_repositorycache);
  243. final RevCommit merge_use_remote = commit(update_eclipse_iplog,
  244. use_remote);
  245. final RevCommit disable_source = commit(merge_use_remote);
  246. final RevCommit update_eclipse_iplog2 = commit(merge_use_remote);
  247. final RevCommit merge_disable_source = commit(update_eclipse_iplog2,
  248. disable_source);
  249. final RevCommit merge_changeset_implementation = commit(
  250. merge_disable_source, changeset_implementation);
  251. final RevCommit clone_operation = commit(merge_changeset_implementation);
  252. final RevCommit update_eclipse = commit(add_Maven);
  253. final RevCommit merge_resolve_handler = commit(clone_operation,
  254. resolve_handler);
  255. final RevCommit disable_comment = commit(clone_operation);
  256. final RevCommit merge_disable_comment = commit(merge_resolve_handler,
  257. disable_comment);
  258. final RevCommit fix_broken = commit(merge_disable_comment);
  259. final RevCommit add_a_clear = commit(fix_broken);
  260. final RevCommit merge_update_eclipse = commit(add_a_clear,
  261. update_eclipse);
  262. final RevCommit sort_roots = commit(merge_update_eclipse);
  263. final RevCommit fix_logged_npe = commit(merge_changeset_implementation);
  264. final RevCommit merge_fixed_logged_npe = commit(sort_roots,
  265. fix_logged_npe);
  266. try (PlotWalk pw = new PlotWalk(db)) {
  267. pw.markStart(pw.lookupCommit(merge_fixed_logged_npe.getId()));
  268. PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
  269. pcl.source(pw);
  270. pcl.fillTo(Integer.MAX_VALUE);
  271. CommitListAssert test = new CommitListAssert(pcl);
  272. // Note: all positions of side branches are rather arbitrary, but
  273. // some
  274. // may not overlap. Testing for the positions yielded by the current
  275. // implementation, which was manually checked to not overlap.
  276. final int mainPos = 0;
  277. test.commit(merge_fixed_logged_npe)
  278. .parents(sort_roots, fix_logged_npe).lanePos(mainPos);
  279. test.commit(fix_logged_npe).parents(merge_changeset_implementation)
  280. .lanePos(1);
  281. test.commit(sort_roots).parents(merge_update_eclipse)
  282. .lanePos(mainPos);
  283. test.commit(merge_update_eclipse)
  284. .parents(add_a_clear, update_eclipse).lanePos(mainPos);
  285. test.commit(add_a_clear).parents(fix_broken).lanePos(mainPos);
  286. test.commit(fix_broken).parents(merge_disable_comment)
  287. .lanePos(mainPos);
  288. test.commit(merge_disable_comment)
  289. .parents(merge_resolve_handler, disable_comment)
  290. .lanePos(mainPos);
  291. test.commit(disable_comment).parents(clone_operation).lanePos(2);
  292. test.commit(merge_resolve_handler)
  293. .parents(clone_operation, resolve_handler).lanePos(mainPos);
  294. test.commit(update_eclipse).parents(add_Maven).lanePos(3);
  295. test.commit(clone_operation).parents(merge_changeset_implementation)
  296. .lanePos(mainPos);
  297. test.commit(merge_changeset_implementation)
  298. .parents(merge_disable_source, changeset_implementation)
  299. .lanePos(mainPos);
  300. test.commit(merge_disable_source)
  301. .parents(update_eclipse_iplog2, disable_source)
  302. .lanePos(mainPos);
  303. test.commit(update_eclipse_iplog2).parents(merge_use_remote)
  304. .lanePos(mainPos);
  305. test.commit(disable_source).parents(merge_use_remote).lanePos(1);
  306. test.commit(merge_use_remote)
  307. .parents(update_eclipse_iplog, use_remote).lanePos(mainPos);
  308. test.commit(changeset_implementation).parents(clear_repositorycache)
  309. .lanePos(2);
  310. test.commit(update_eclipse_iplog).parents(merge_add_Maven)
  311. .lanePos(mainPos);
  312. test.commit(merge_add_Maven).parents(findToolBar_layout, add_Maven)
  313. .lanePos(mainPos);
  314. test.commit(findToolBar_layout).parents(clear_repositorycache)
  315. .lanePos(mainPos);
  316. test.commit(use_remote).parents(clear_repositorycache).lanePos(1);
  317. test.commit(add_Maven).parents(clear_repositorycache).lanePos(3);
  318. test.commit(clear_repositorycache).parents(merge_remove)
  319. .lanePos(mainPos);
  320. test.commit(resolve_handler).parents(merge_fix).lanePos(4);
  321. test.commit(merge_remove).parents(add_simple, remove_unused)
  322. .lanePos(mainPos);
  323. test.commit(remove_unused).parents(merge_fix).lanePos(1);
  324. test.commit(add_simple).parents(merge_fix).lanePos(mainPos);
  325. test.commit(merge_fix).parents().lanePos(mainPos);
  326. test.noMoreCommits();
  327. }
  328. }
  329. // test a history where a merge commit has two time the same parent
  330. @Test
  331. public void testDuplicateParents() throws Exception {
  332. final RevCommit m1 = commit();
  333. final RevCommit m2 = commit(m1);
  334. final RevCommit m3 = commit(m2, m2);
  335. final RevCommit s1 = commit(m2);
  336. final RevCommit s2 = commit(s1);
  337. try (PlotWalk pw = new PlotWalk(db)) {
  338. pw.markStart(pw.lookupCommit(m3));
  339. pw.markStart(pw.lookupCommit(s2));
  340. PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
  341. pcl.source(pw);
  342. pcl.fillTo(Integer.MAX_VALUE);
  343. CommitListAssert test = new CommitListAssert(pcl);
  344. test.commit(s2).nrOfPassingLanes(0);
  345. test.commit(s1).nrOfPassingLanes(0);
  346. test.commit(m3).nrOfPassingLanes(1);
  347. test.commit(m2).nrOfPassingLanes(0);
  348. test.commit(m1).nrOfPassingLanes(0);
  349. test.noMoreCommits();
  350. }
  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. try (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<>();
  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. /**
  421. * <pre>
  422. * b3
  423. * a4 |
  424. * | \|
  425. * | b2
  426. * a3 |
  427. * | \|
  428. * a2 |
  429. * | b1
  430. * | /
  431. * a1
  432. * </pre>
  433. *
  434. * @throws Exception
  435. */
  436. @Test
  437. public void testMultipleMerges() throws Exception {
  438. final RevCommit a1 = commit();
  439. final RevCommit b1 = commit(a1);
  440. final RevCommit a2 = commit(a1);
  441. final RevCommit a3 = commit(a2, b1);
  442. final RevCommit b2 = commit(b1);
  443. final RevCommit a4 = commit(a3, b2);
  444. final RevCommit b3 = commit(b2);
  445. try (PlotWalk pw = new PlotWalk(db)) {
  446. pw.markStart(pw.lookupCommit(a4));
  447. pw.markStart(pw.lookupCommit(b3));
  448. PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
  449. pcl.source(pw);
  450. pcl.fillTo(Integer.MAX_VALUE);
  451. Set<Integer> positions = asSet(0, 1);
  452. CommitListAssert test = new CommitListAssert(pcl);
  453. int posB = test.commit(b3).lanePos(positions).getLanePos();
  454. int posA = test.commit(a4).lanePos(positions).getLanePos();
  455. test.commit(b2).lanePos(posB);
  456. test.commit(a3).lanePos(posA);
  457. test.commit(a2).lanePos(posA);
  458. test.commit(b1).lanePos(posB);
  459. test.commit(a1).lanePos(posA);
  460. test.noMoreCommits();
  461. }
  462. }
  463. /**
  464. * <pre>
  465. * a4
  466. * | b3
  467. * a3 |
  468. * | \\|
  469. * | |\\
  470. * | b2||
  471. * a2 | //
  472. * | b1
  473. * | /
  474. * a1
  475. * </pre>
  476. *
  477. * @throws Exception
  478. */
  479. @Test
  480. public void testMergeBlockedBySelf() throws Exception {
  481. final RevCommit a1 = commit();
  482. final RevCommit b1 = commit(a1);
  483. final RevCommit a2 = commit(a1);
  484. final RevCommit b2 = commit(b1); // blocks merging arc
  485. final RevCommit a3 = commit(a2, b1);
  486. final RevCommit b3 = commit(b2);
  487. final RevCommit a4 = commit(a3);
  488. try (PlotWalk pw = new PlotWalk(db)) {
  489. pw.markStart(pw.lookupCommit(a4));
  490. pw.markStart(pw.lookupCommit(b3));
  491. PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
  492. pcl.source(pw);
  493. pcl.fillTo(Integer.MAX_VALUE);
  494. Set<Integer> positions = asSet(0, 1);
  495. CommitListAssert test = new CommitListAssert(pcl);
  496. int posA = test.commit(a4).lanePos(positions).getLanePos();
  497. int posB = test.commit(b3).lanePos(positions).getLanePos();
  498. test.commit(a3).lanePos(posA);
  499. test.commit(b2).lanePos(posB);
  500. test.commit(a2).lanePos(posA);
  501. // b1 is not repositioned, uses "detour lane"
  502. // (drawn as a double arc in the ascii graph above)
  503. test.commit(b1).lanePos(posB);
  504. test.commit(a1).lanePos(posA);
  505. test.noMoreCommits();
  506. }
  507. }
  508. /**
  509. * <pre>
  510. * b2
  511. * a4 |
  512. * | \ |
  513. * a3 \|
  514. * | \ |
  515. * | c |
  516. * | / |
  517. * a2 |
  518. * | b1
  519. * /
  520. * | /
  521. * a1
  522. * </pre>
  523. *
  524. * @throws Exception
  525. */
  526. @Test
  527. public void testMergeBlockedByOther() throws Exception {
  528. final RevCommit a1 = commit();
  529. final RevCommit b1 = commit(a1);
  530. final RevCommit a2 = commit(a1);
  531. final RevCommit c = commit(a2);// blocks merging arc
  532. final RevCommit a3 = commit(a2, c);
  533. final RevCommit a4 = commit(a3, b1);
  534. final RevCommit b2 = commit(b1);
  535. try (PlotWalk pw = new PlotWalk(db)) {
  536. pw.markStart(pw.lookupCommit(a4));
  537. pw.markStart(pw.lookupCommit(b2));
  538. pw.markStart(pw.lookupCommit(c));
  539. PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
  540. pcl.source(pw);
  541. pcl.fillTo(Integer.MAX_VALUE);
  542. Set<Integer> positions = asSet(0, 1, 2);
  543. CommitListAssert test = new CommitListAssert(pcl);
  544. int posB = test.commit(b2).lanePos(positions).getLanePos();
  545. int posA = test.commit(a4).lanePos(positions).getLanePos();
  546. test.commit(a3).lanePos(posA);
  547. test.commit(c).lanePos(positions);
  548. test.commit(a2).lanePos(posA);
  549. test.commit(b1).lanePos(posB); // repositioned to go around c
  550. test.commit(a1).lanePos(posA);
  551. test.noMoreCommits();
  552. }
  553. }
  554. /**
  555. * <pre>
  556. * b1
  557. * a3 |
  558. * | |
  559. * a2 |
  560. * -- processing stops here --
  561. * | /
  562. * a1
  563. * </pre>
  564. *
  565. * @throws Exception
  566. */
  567. @Test
  568. public void testDanglingCommitShouldContinueLane() throws Exception {
  569. final RevCommit a1 = commit();
  570. final RevCommit a2 = commit(a1);
  571. final RevCommit a3 = commit(a2);
  572. final RevCommit b1 = commit(a1);
  573. try (PlotWalk pw = new PlotWalk(db)) {
  574. pw.markStart(pw.lookupCommit(a3));
  575. pw.markStart(pw.lookupCommit(b1));
  576. PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
  577. pcl.source(pw);
  578. pcl.fillTo(2); // don't process a1
  579. Set<Integer> positions = asSet(0, 1);
  580. CommitListAssert test = new CommitListAssert(pcl);
  581. PlotLane laneB = test.commit(b1).lanePos(positions).current
  582. .getLane();
  583. int posA = test.commit(a3).lanePos(positions).getLanePos();
  584. test.commit(a2).lanePos(posA);
  585. assertArrayEquals(
  586. "Although the parent of b1, a1, is not processed yet, the b lane should still be drawn",
  587. new PlotLane[] { laneB }, test.current.passingLanes);
  588. test.noMoreCommits();
  589. }
  590. }
  591. @Test
  592. public void testTwoRoots1() throws Exception {
  593. final RevCommit a = commit();
  594. final RevCommit b = commit();
  595. try (PlotWalk pw = new PlotWalk(db)) {
  596. pw.markStart(pw.lookupCommit(a));
  597. pw.markStart(pw.lookupCommit(b));
  598. PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
  599. pcl.source(pw);
  600. pcl.fillTo(Integer.MAX_VALUE);
  601. CommitListAssert test = new CommitListAssert(pcl);
  602. test.commit(b).lanePos(0);
  603. test.commit(a).lanePos(0);
  604. test.noMoreCommits();
  605. }
  606. }
  607. @Test
  608. public void testTwoRoots2() throws Exception {
  609. final RevCommit a = commit();
  610. final RevCommit b1 = commit();
  611. final RevCommit b2 = commit(b1);
  612. try (PlotWalk pw = new PlotWalk(db)) {
  613. pw.markStart(pw.lookupCommit(a));
  614. pw.markStart(pw.lookupCommit(b2));
  615. PlotCommitList<PlotLane> pcl = new PlotCommitList<>();
  616. pcl.source(pw);
  617. pcl.fillTo(Integer.MAX_VALUE);
  618. CommitListAssert test = new CommitListAssert(pcl);
  619. test.commit(b2).lanePos(0);
  620. test.commit(b1).lanePos(0);
  621. test.commit(a).lanePos(0);
  622. test.noMoreCommits();
  623. }
  624. }
  625. }