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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. * Copyright (C) 2010, 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 org.eclipse.jgit.revwalk.RevCommit;
  45. import org.eclipse.jgit.revwalk.RevWalkTestCase;
  46. public class PlotCommitListTest extends RevWalkTestCase {
  47. class CommitListAssert {
  48. private PlotCommitList<PlotLane> pcl;
  49. private PlotCommit<PlotLane> current;
  50. private int nextIndex = 0;
  51. CommitListAssert(PlotCommitList<PlotLane> pcl) {
  52. this.pcl = pcl;
  53. }
  54. public CommitListAssert commit(RevCommit id) {
  55. assertTrue("Unexpected end of list at pos#"+nextIndex, pcl.size()>nextIndex);
  56. current = pcl.get(nextIndex++);
  57. assertEquals("Expected commit not found at pos#" + (nextIndex - 1),
  58. id.getId(), current.getId());
  59. return this;
  60. }
  61. public CommitListAssert lanePos(int pos) {
  62. PlotLane lane = current.getLane();
  63. assertEquals("Position of lane of commit #" + (nextIndex - 1)
  64. + " not as expected.", pos, lane.getPosition());
  65. return this;
  66. }
  67. public CommitListAssert parents(RevCommit... parents) {
  68. assertEquals("Number of parents of commit #" + (nextIndex - 1)
  69. + " not as expected.", parents.length,
  70. current.getParentCount());
  71. for (int i = 0; i < parents.length; i++)
  72. assertEquals("Unexpected parent of commit #" + (nextIndex - 1),
  73. parents[i], current.getParent(i));
  74. return this;
  75. }
  76. public CommitListAssert noMoreCommits() {
  77. assertEquals("Unexpected size of list", nextIndex, pcl.size());
  78. return this;
  79. }
  80. }
  81. @SuppressWarnings("boxing")
  82. public void testLinear() throws Exception {
  83. final RevCommit a = commit();
  84. final RevCommit b = commit(a);
  85. final RevCommit c = commit(b);
  86. PlotWalk pw = new PlotWalk(db);
  87. pw.markStart(pw.lookupCommit(c.getId()));
  88. PlotCommitList<PlotLane> pcl = new PlotCommitList<PlotLane>();
  89. pcl.source(pw);
  90. pcl.fillTo(Integer.MAX_VALUE);
  91. CommitListAssert test = new CommitListAssert(pcl);
  92. test.commit(c).lanePos(0).parents(b);
  93. test.commit(b).lanePos(0).parents(a);
  94. test.commit(a).lanePos(0).parents();
  95. test.noMoreCommits();
  96. }
  97. @SuppressWarnings("boxing")
  98. public void testMerged() throws Exception {
  99. final RevCommit a = commit();
  100. final RevCommit b = commit(a);
  101. final RevCommit c = commit(a);
  102. final RevCommit d = commit(b, c);
  103. PlotWalk pw = new PlotWalk(db);
  104. pw.markStart(pw.lookupCommit(d.getId()));
  105. PlotCommitList<PlotLane> pcl = new PlotCommitList<PlotLane>();
  106. pcl.source(pw);
  107. pcl.fillTo(Integer.MAX_VALUE);
  108. CommitListAssert test = new CommitListAssert(pcl);
  109. test.commit(d).lanePos(0).parents(b, c);
  110. test.commit(c).lanePos(0).parents(a);
  111. test.commit(b).lanePos(1).parents(a);
  112. test.commit(a).lanePos(0).parents();
  113. test.noMoreCommits();
  114. }
  115. @SuppressWarnings("boxing")
  116. public void testSideBranch() throws Exception {
  117. final RevCommit a = commit();
  118. final RevCommit b = commit(a);
  119. final RevCommit c = commit(a);
  120. PlotWalk pw = new PlotWalk(db);
  121. pw.markStart(pw.lookupCommit(b.getId()));
  122. pw.markStart(pw.lookupCommit(c.getId()));
  123. PlotCommitList<PlotLane> pcl = new PlotCommitList<PlotLane>();
  124. pcl.source(pw);
  125. pcl.fillTo(Integer.MAX_VALUE);
  126. CommitListAssert test = new CommitListAssert(pcl);
  127. test.commit(c).lanePos(0).parents(a);
  128. test.commit(b).lanePos(1).parents(a);
  129. test.commit(a).lanePos(0).parents();
  130. test.noMoreCommits();
  131. }
  132. @SuppressWarnings("boxing")
  133. public void test2SideBranches() throws Exception {
  134. final RevCommit a = commit();
  135. final RevCommit b = commit(a);
  136. final RevCommit c = commit(a);
  137. final RevCommit d = commit(a);
  138. PlotWalk pw = new PlotWalk(db);
  139. pw.markStart(pw.lookupCommit(b.getId()));
  140. pw.markStart(pw.lookupCommit(c.getId()));
  141. pw.markStart(pw.lookupCommit(d.getId()));
  142. PlotCommitList<PlotLane> pcl = new PlotCommitList<PlotLane>();
  143. pcl.source(pw);
  144. pcl.fillTo(Integer.MAX_VALUE);
  145. CommitListAssert test = new CommitListAssert(pcl);
  146. test.commit(d).lanePos(0).parents(a);
  147. test.commit(c).lanePos(1).parents(a);
  148. test.commit(b).lanePos(1).parents(a);
  149. test.commit(a).lanePos(0).parents();
  150. test.noMoreCommits();
  151. }
  152. @SuppressWarnings("boxing")
  153. public void testBug300282_1() throws Exception {
  154. final RevCommit a = commit();
  155. final RevCommit b = commit(a);
  156. final RevCommit c = commit(a);
  157. final RevCommit d = commit(a);
  158. final RevCommit e = commit(a);
  159. final RevCommit f = commit(a);
  160. final RevCommit g = commit(f);
  161. PlotWalk pw = new PlotWalk(db);
  162. // TODO: when we add unnecessary commit's as tips (e.g. a commit which
  163. // is a parent of another tip) the walk will return those commits twice.
  164. // Find out why!
  165. // pw.markStart(pw.lookupCommit(a.getId()));
  166. pw.markStart(pw.lookupCommit(b.getId()));
  167. pw.markStart(pw.lookupCommit(c.getId()));
  168. pw.markStart(pw.lookupCommit(d.getId()));
  169. pw.markStart(pw.lookupCommit(e.getId()));
  170. // pw.markStart(pw.lookupCommit(f.getId()));
  171. pw.markStart(pw.lookupCommit(g.getId()));
  172. PlotCommitList<PlotLane> pcl = new PlotCommitList<PlotLane>();
  173. pcl.source(pw);
  174. pcl.fillTo(Integer.MAX_VALUE);
  175. CommitListAssert test = new CommitListAssert(pcl);
  176. test.commit(g).lanePos(0).parents(f);
  177. test.commit(f).lanePos(0).parents(a);
  178. test.commit(e).lanePos(1).parents(a);
  179. test.commit(d).lanePos(1).parents(a);
  180. test.commit(c).lanePos(1).parents(a);
  181. test.commit(b).lanePos(1).parents(a);
  182. test.commit(a).lanePos(0).parents();
  183. test.noMoreCommits();
  184. }
  185. // test the history of the egit project between 9fdaf3c1 and e76ad9170f
  186. public void testEgitHistory() throws Exception {
  187. final RevCommit merge_fix = commit();
  188. final RevCommit add_simple = commit(merge_fix);
  189. final RevCommit remove_unused = commit(merge_fix);
  190. final RevCommit merge_remove = commit(add_simple, remove_unused);
  191. final RevCommit resolve_handler = commit(merge_fix);
  192. final RevCommit clear_repositorycache = commit(merge_remove);
  193. final RevCommit add_Maven = commit(clear_repositorycache);
  194. final RevCommit use_remote = commit(clear_repositorycache);
  195. final RevCommit findToolBar_layout = commit(clear_repositorycache);
  196. final RevCommit merge_add_Maven = commit(findToolBar_layout, add_Maven);
  197. final RevCommit update_eclipse_iplog = commit(merge_add_Maven);
  198. final RevCommit changeset_implementation = commit(clear_repositorycache);
  199. final RevCommit merge_use_remote = commit(update_eclipse_iplog,
  200. use_remote);
  201. final RevCommit disable_source = commit(merge_use_remote);
  202. final RevCommit update_eclipse_iplog2 = commit(merge_use_remote);
  203. final RevCommit merge_disable_source = commit(update_eclipse_iplog2,
  204. disable_source);
  205. final RevCommit merge_changeset_implementation = commit(
  206. merge_disable_source, changeset_implementation);
  207. final RevCommit clone_operation = commit(merge_disable_source,
  208. merge_changeset_implementation);
  209. final RevCommit update_eclipse = commit(add_Maven);
  210. final RevCommit merge_resolve_handler = commit(clone_operation,
  211. resolve_handler);
  212. final RevCommit disable_comment = commit(clone_operation);
  213. final RevCommit merge_disable_comment = commit(merge_resolve_handler,
  214. disable_comment);
  215. final RevCommit fix_broken = commit(merge_disable_comment);
  216. final RevCommit add_a_clear = commit(fix_broken);
  217. final RevCommit merge_update_eclipse = commit(add_a_clear,
  218. update_eclipse);
  219. final RevCommit sort_roots = commit(merge_update_eclipse);
  220. final RevCommit fix_logged_npe = commit(merge_changeset_implementation);
  221. final RevCommit merge_fixed_logged_npe = commit(sort_roots,
  222. fix_logged_npe);
  223. PlotWalk pw = new PlotWalk(db);
  224. pw.markStart(pw.lookupCommit(merge_fixed_logged_npe.getId()));
  225. PlotCommitList<PlotLane> pcl = new PlotCommitList<PlotLane>();
  226. pcl.source(pw);
  227. pcl.fillTo(Integer.MAX_VALUE);
  228. CommitListAssert test = new CommitListAssert(pcl);
  229. test.commit(merge_fixed_logged_npe).parents(sort_roots, fix_logged_npe)
  230. .lanePos(0);
  231. test.commit(fix_logged_npe).parents(merge_changeset_implementation)
  232. .lanePos(0);
  233. test.commit(sort_roots).parents(merge_update_eclipse).lanePos(1);
  234. test.commit(merge_update_eclipse).parents(add_a_clear, update_eclipse)
  235. .lanePos(1);
  236. test.commit(add_a_clear).parents(fix_broken).lanePos(1);
  237. test.commit(fix_broken).parents(merge_disable_comment).lanePos(1);
  238. test.commit(merge_disable_comment)
  239. .parents(merge_resolve_handler, disable_comment).lanePos(1);
  240. test.commit(disable_comment).parents(clone_operation).lanePos(1);
  241. test.commit(merge_resolve_handler)
  242. .parents(clone_operation, resolve_handler).lanePos(2);
  243. test.commit(update_eclipse).parents(add_Maven).lanePos(3);
  244. test.commit(clone_operation)
  245. .parents(merge_disable_source, merge_changeset_implementation)
  246. .lanePos(1);
  247. test.commit(merge_changeset_implementation)
  248. .parents(merge_disable_source, changeset_implementation)
  249. .lanePos(0);
  250. test.commit(merge_disable_source)
  251. .parents(update_eclipse_iplog2, disable_source).lanePos(1);
  252. test.commit(update_eclipse_iplog2).parents(merge_use_remote).lanePos(0);
  253. test.commit(disable_source).parents(merge_use_remote).lanePos(1);
  254. test.commit(merge_use_remote).parents(update_eclipse_iplog, use_remote)
  255. .lanePos(0);
  256. test.commit(changeset_implementation).parents(clear_repositorycache)
  257. .lanePos(2);
  258. test.commit(update_eclipse_iplog).parents(merge_add_Maven).lanePos(0);
  259. test.commit(merge_add_Maven).parents(findToolBar_layout, add_Maven)
  260. .lanePos(0);
  261. test.commit(findToolBar_layout).parents(clear_repositorycache)
  262. .lanePos(0);
  263. test.commit(use_remote).parents(clear_repositorycache).lanePos(1);
  264. test.commit(add_Maven).parents(clear_repositorycache).lanePos(3);
  265. test.commit(clear_repositorycache).parents(merge_remove).lanePos(2);
  266. test.commit(resolve_handler).parents(merge_fix).lanePos(4);
  267. test.commit(merge_remove).parents(add_simple, remove_unused).lanePos(2);
  268. test.commit(remove_unused).parents(merge_fix).lanePos(0);
  269. test.commit(add_simple).parents(merge_fix).lanePos(1);
  270. test.commit(merge_fix).parents().lanePos(3);
  271. test.noMoreCommits();
  272. }
  273. }