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.

RevWalkSortTest.java 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * Copyright (C) 2009-2010, Google Inc.
  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.revwalk;
  44. import static org.junit.Assert.assertNull;
  45. import static org.junit.Assert.assertTrue;
  46. import org.junit.Test;
  47. public class RevWalkSortTest extends RevWalkTestCase {
  48. @Test
  49. public void testSort_Default() throws Exception {
  50. final RevCommit a = commit();
  51. final RevCommit b = commit(1, a);
  52. final RevCommit c = commit(1, b);
  53. final RevCommit d = commit(1, c);
  54. markStart(d);
  55. assertCommit(d, rw.next());
  56. assertCommit(c, rw.next());
  57. assertCommit(b, rw.next());
  58. assertCommit(a, rw.next());
  59. assertNull(rw.next());
  60. }
  61. @Test
  62. public void testSort_COMMIT_TIME_DESC() throws Exception {
  63. final RevCommit a = commit();
  64. final RevCommit b = commit(a);
  65. final RevCommit c = commit(b);
  66. final RevCommit d = commit(c);
  67. rw.sort(RevSort.COMMIT_TIME_DESC);
  68. markStart(d);
  69. assertCommit(d, rw.next());
  70. assertCommit(c, rw.next());
  71. assertCommit(b, rw.next());
  72. assertCommit(a, rw.next());
  73. assertNull(rw.next());
  74. }
  75. @Test
  76. public void testSort_REVERSE() throws Exception {
  77. final RevCommit a = commit();
  78. final RevCommit b = commit(a);
  79. final RevCommit c = commit(b);
  80. final RevCommit d = commit(c);
  81. rw.sort(RevSort.REVERSE);
  82. markStart(d);
  83. assertCommit(a, rw.next());
  84. assertCommit(b, rw.next());
  85. assertCommit(c, rw.next());
  86. assertCommit(d, rw.next());
  87. assertNull(rw.next());
  88. }
  89. @Test
  90. public void testSort_COMMIT_TIME_DESC_OutOfOrder1() throws Exception {
  91. // Despite being out of order time-wise, a strand-of-pearls must
  92. // still maintain topological order.
  93. //
  94. final RevCommit a = commit();
  95. final RevCommit b = commit(a);
  96. final RevCommit c = commit(-5, b);
  97. final RevCommit d = commit(10, c);
  98. assertTrue(parseBody(a).getCommitTime() < parseBody(d).getCommitTime());
  99. assertTrue(parseBody(c).getCommitTime() < parseBody(b).getCommitTime());
  100. rw.sort(RevSort.COMMIT_TIME_DESC);
  101. markStart(d);
  102. assertCommit(d, rw.next());
  103. assertCommit(c, rw.next());
  104. assertCommit(b, rw.next());
  105. assertCommit(a, rw.next());
  106. assertNull(rw.next());
  107. }
  108. @Test
  109. public void testSort_COMMIT_TIME_DESC_OutOfOrder2() throws Exception {
  110. // c1 is back dated before its parent.
  111. //
  112. final RevCommit a = commit();
  113. final RevCommit b = commit(a);
  114. final RevCommit c1 = commit(-5, b);
  115. final RevCommit c2 = commit(10, b);
  116. final RevCommit d = commit(c1, c2);
  117. rw.sort(RevSort.COMMIT_TIME_DESC);
  118. markStart(d);
  119. assertCommit(d, rw.next());
  120. assertCommit(c2, rw.next());
  121. assertCommit(b, rw.next());
  122. assertCommit(a, rw.next());
  123. assertCommit(c1, rw.next());
  124. assertNull(rw.next());
  125. }
  126. @Test
  127. public void testSort_TOPO() throws Exception {
  128. // c1 is back dated before its parent.
  129. //
  130. final RevCommit a = commit();
  131. final RevCommit b = commit(a);
  132. final RevCommit c1 = commit(-5, b);
  133. final RevCommit c2 = commit(10, b);
  134. final RevCommit d = commit(c1, c2);
  135. rw.sort(RevSort.TOPO);
  136. markStart(d);
  137. assertCommit(d, rw.next());
  138. assertCommit(c2, rw.next());
  139. assertCommit(c1, rw.next());
  140. assertCommit(b, rw.next());
  141. assertCommit(a, rw.next());
  142. assertNull(rw.next());
  143. }
  144. @Test
  145. public void testSort_TOPO_REVERSE() throws Exception {
  146. // c1 is back dated before its parent.
  147. //
  148. final RevCommit a = commit();
  149. final RevCommit b = commit(a);
  150. final RevCommit c1 = commit(-5, b);
  151. final RevCommit c2 = commit(10, b);
  152. final RevCommit d = commit(c1, c2);
  153. rw.sort(RevSort.TOPO);
  154. rw.sort(RevSort.REVERSE, true);
  155. markStart(d);
  156. assertCommit(a, rw.next());
  157. assertCommit(b, rw.next());
  158. assertCommit(c1, rw.next());
  159. assertCommit(c2, rw.next());
  160. assertCommit(d, rw.next());
  161. assertNull(rw.next());
  162. }
  163. }