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.3KB

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