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.

RevWalkPathFilter1Test.java 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * Copyright (C) 2009, 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.assertEquals;
  45. import static org.junit.Assert.assertNull;
  46. import java.util.Collections;
  47. import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
  48. import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
  49. import org.eclipse.jgit.treewalk.filter.TreeFilter;
  50. import org.junit.Test;
  51. public class RevWalkPathFilter1Test extends RevWalkTestCase {
  52. protected void filter(final String path) {
  53. rw.setTreeFilter(AndTreeFilter.create(PathFilterGroup
  54. .createFromStrings(Collections.singleton(path)),
  55. TreeFilter.ANY_DIFF));
  56. }
  57. @Test
  58. public void testEmpty_EmptyTree() throws Exception {
  59. final RevCommit a = commit();
  60. filter("a");
  61. markStart(a);
  62. assertNull(rw.next());
  63. }
  64. @Test
  65. public void testEmpty_NoMatch() throws Exception {
  66. final RevCommit a = commit(tree(file("0", blob("0"))));
  67. filter("a");
  68. markStart(a);
  69. assertNull(rw.next());
  70. }
  71. @Test
  72. public void testSimple1() throws Exception {
  73. final RevCommit a = commit(tree(file("0", blob("0"))));
  74. filter("0");
  75. markStart(a);
  76. assertCommit(a, rw.next());
  77. assertNull(rw.next());
  78. }
  79. @Test
  80. public void testEdits_MatchNone() throws Exception {
  81. final RevCommit a = commit(tree(file("0", blob("a"))));
  82. final RevCommit b = commit(tree(file("0", blob("b"))), a);
  83. final RevCommit c = commit(tree(file("0", blob("c"))), b);
  84. final RevCommit d = commit(tree(file("0", blob("d"))), c);
  85. filter("a");
  86. markStart(d);
  87. assertNull(rw.next());
  88. }
  89. @Test
  90. public void testEdits_MatchAll() throws Exception {
  91. final RevCommit a = commit(tree(file("0", blob("a"))));
  92. final RevCommit b = commit(tree(file("0", blob("b"))), a);
  93. final RevCommit c = commit(tree(file("0", blob("c"))), b);
  94. final RevCommit d = commit(tree(file("0", blob("d"))), c);
  95. filter("0");
  96. markStart(d);
  97. assertCommit(d, rw.next());
  98. assertCommit(c, rw.next());
  99. assertCommit(b, rw.next());
  100. assertCommit(a, rw.next());
  101. assertNull(rw.next());
  102. }
  103. @Test
  104. public void testStringOfPearls_FilePath1() throws Exception {
  105. final RevCommit a = commit(tree(file("d/f", blob("a"))));
  106. final RevCommit b = commit(tree(file("d/f", blob("a"))), a);
  107. final RevCommit c = commit(tree(file("d/f", blob("b"))), b);
  108. filter("d/f");
  109. markStart(c);
  110. assertCommit(c, rw.next());
  111. assertEquals(1, c.getParentCount());
  112. assertCommit(a, c.getParent(0)); // b was skipped
  113. assertCommit(a, rw.next());
  114. assertEquals(0, a.getParentCount());
  115. assertNull(rw.next());
  116. }
  117. @Test
  118. public void testStringOfPearls_FilePath1_NoParentRewriting()
  119. throws Exception {
  120. final RevCommit a = commit(tree(file("d/f", blob("a"))));
  121. final RevCommit b = commit(tree(file("d/f", blob("a"))), a);
  122. final RevCommit c = commit(tree(file("d/f", blob("b"))), b);
  123. filter("d/f");
  124. markStart(c);
  125. rw.setRewriteParents(false);
  126. assertCommit(c, rw.next());
  127. assertEquals(1, c.getParentCount());
  128. assertCommit(b, c.getParent(0));
  129. assertCommit(a, rw.next()); // b was skipped
  130. assertEquals(0, a.getParentCount());
  131. assertNull(rw.next());
  132. }
  133. @Test
  134. public void testStringOfPearls_FilePath2() throws Exception {
  135. final RevCommit a = commit(tree(file("d/f", blob("a"))));
  136. final RevCommit b = commit(tree(file("d/f", blob("a"))), a);
  137. final RevCommit c = commit(tree(file("d/f", blob("b"))), b);
  138. final RevCommit d = commit(tree(file("d/f", blob("b"))), c);
  139. filter("d/f");
  140. markStart(d);
  141. // d was skipped
  142. assertCommit(c, rw.next());
  143. assertEquals(1, c.getParentCount());
  144. assertCommit(a, c.getParent(0)); // b was skipped
  145. assertCommit(a, rw.next());
  146. assertEquals(0, a.getParentCount());
  147. assertNull(rw.next());
  148. }
  149. @Test
  150. public void testStringOfPearls_FilePath2_NoParentRewriting()
  151. throws Exception {
  152. final RevCommit a = commit(tree(file("d/f", blob("a"))));
  153. final RevCommit b = commit(tree(file("d/f", blob("a"))), a);
  154. final RevCommit c = commit(tree(file("d/f", blob("b"))), b);
  155. final RevCommit d = commit(tree(file("d/f", blob("b"))), c);
  156. filter("d/f");
  157. markStart(d);
  158. rw.setRewriteParents(false);
  159. // d was skipped
  160. assertCommit(c, rw.next());
  161. assertEquals(1, c.getParentCount());
  162. assertCommit(b, c.getParent(0));
  163. // b was skipped
  164. assertCommit(a, rw.next());
  165. assertEquals(0, a.getParentCount());
  166. assertNull(rw.next());
  167. }
  168. @Test
  169. public void testStringOfPearls_DirPath2() throws Exception {
  170. final RevCommit a = commit(tree(file("d/f", blob("a"))));
  171. final RevCommit b = commit(tree(file("d/f", blob("a"))), a);
  172. final RevCommit c = commit(tree(file("d/f", blob("b"))), b);
  173. final RevCommit d = commit(tree(file("d/f", blob("b"))), c);
  174. filter("d");
  175. markStart(d);
  176. // d was skipped
  177. assertCommit(c, rw.next());
  178. assertEquals(1, c.getParentCount());
  179. assertCommit(a, c.getParent(0)); // b was skipped
  180. assertCommit(a, rw.next());
  181. assertEquals(0, a.getParentCount());
  182. assertNull(rw.next());
  183. }
  184. @Test
  185. public void testStringOfPearls_DirPath2_NoParentRewriting()
  186. throws Exception {
  187. final RevCommit a = commit(tree(file("d/f", blob("a"))));
  188. final RevCommit b = commit(tree(file("d/f", blob("a"))), a);
  189. final RevCommit c = commit(tree(file("d/f", blob("b"))), b);
  190. final RevCommit d = commit(tree(file("d/f", blob("b"))), c);
  191. filter("d");
  192. markStart(d);
  193. rw.setRewriteParents(false);
  194. // d was skipped
  195. assertCommit(c, rw.next());
  196. assertEquals(1, c.getParentCount());
  197. assertCommit(b, c.getParent(0));
  198. // b was skipped
  199. assertCommit(a, rw.next());
  200. assertEquals(0, a.getParentCount());
  201. assertNull(rw.next());
  202. }
  203. @Test
  204. public void testStringOfPearls_FilePath3() throws Exception {
  205. final RevCommit a = commit(tree(file("d/f", blob("a"))));
  206. final RevCommit b = commit(tree(file("d/f", blob("a"))), a);
  207. final RevCommit c = commit(tree(file("d/f", blob("b"))), b);
  208. final RevCommit d = commit(tree(file("d/f", blob("b"))), c);
  209. final RevCommit e = commit(tree(file("d/f", blob("b"))), d);
  210. final RevCommit f = commit(tree(file("d/f", blob("b"))), e);
  211. final RevCommit g = commit(tree(file("d/f", blob("b"))), f);
  212. final RevCommit h = commit(tree(file("d/f", blob("b"))), g);
  213. final RevCommit i = commit(tree(file("d/f", blob("c"))), h);
  214. filter("d/f");
  215. markStart(i);
  216. assertCommit(i, rw.next());
  217. assertEquals(1, i.getParentCount());
  218. assertCommit(c, i.getParent(0)); // h..d was skipped
  219. assertCommit(c, rw.next());
  220. assertEquals(1, c.getParentCount());
  221. assertCommit(a, c.getParent(0)); // b was skipped
  222. assertCommit(a, rw.next());
  223. assertEquals(0, a.getParentCount());
  224. assertNull(rw.next());
  225. }
  226. @Test
  227. public void testStringOfPearls_FilePath3_NoParentRewriting()
  228. throws Exception {
  229. final RevCommit a = commit(tree(file("d/f", blob("a"))));
  230. final RevCommit b = commit(tree(file("d/f", blob("a"))), a);
  231. final RevCommit c = commit(tree(file("d/f", blob("b"))), b);
  232. final RevCommit d = commit(tree(file("d/f", blob("b"))), c);
  233. final RevCommit e = commit(tree(file("d/f", blob("b"))), d);
  234. final RevCommit f = commit(tree(file("d/f", blob("b"))), e);
  235. final RevCommit g = commit(tree(file("d/f", blob("b"))), f);
  236. final RevCommit h = commit(tree(file("d/f", blob("b"))), g);
  237. final RevCommit i = commit(tree(file("d/f", blob("c"))), h);
  238. filter("d/f");
  239. markStart(i);
  240. rw.setRewriteParents(false);
  241. assertCommit(i, rw.next());
  242. assertEquals(1, i.getParentCount());
  243. assertCommit(h, i.getParent(0));
  244. // h..d was skipped
  245. assertCommit(c, rw.next());
  246. assertEquals(1, c.getParentCount());
  247. assertCommit(b, c.getParent(0));
  248. // b was skipped
  249. assertCommit(a, rw.next());
  250. assertEquals(0, a.getParentCount());
  251. assertNull(rw.next());
  252. }
  253. }