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.

RevWalkPathFilter6012Test.java 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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.assertEquals;
  45. import static org.junit.Assert.assertNotNull;
  46. import java.lang.reflect.Field;
  47. import java.util.Collections;
  48. import java.util.HashMap;
  49. import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
  50. import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
  51. import org.eclipse.jgit.treewalk.filter.TreeFilter;
  52. import org.junit.Before;
  53. import org.junit.Test;
  54. // Note: Much of this test case is broken as it depends upon
  55. // the graph applying topological sorting *before* doing merge
  56. // simplification. It also depends upon a difference between
  57. // full history and non-full history for a path, something we
  58. // don't quite yet have a distiction for in JGit.
  59. //
  60. public class RevWalkPathFilter6012Test extends RevWalkTestCase {
  61. private static final String pA = "pA", pF = "pF", pE = "pE";
  62. private RevCommit a, b, c, d, e, f, g, h, i;
  63. private HashMap<RevCommit, String> byName;
  64. @Before
  65. public void setUp() throws Exception {
  66. super.setUp();
  67. // Test graph was stolen from git-core t6012-rev-list-simplify
  68. // (by Junio C Hamano in 65347030590bcc251a9ff2ed96487a0f1b9e9fa8)
  69. //
  70. final RevBlob zF = blob("zF");
  71. final RevBlob zH = blob("zH");
  72. final RevBlob zI = blob("zI");
  73. final RevBlob zS = blob("zS");
  74. final RevBlob zY = blob("zY");
  75. a = commit(tree(file(pF, zH)));
  76. b = commit(tree(file(pF, zI)), a);
  77. c = commit(tree(file(pF, zI)), a);
  78. d = commit(tree(file(pA, zS), file(pF, zI)), c);
  79. parseBody(d);
  80. e = commit(d.getTree(), d, b);
  81. f = commit(tree(file(pA, zS), file(pE, zY), file(pF, zI)), e);
  82. parseBody(f);
  83. g = commit(tree(file(pE, zY), file(pF, zI)), b);
  84. h = commit(f.getTree(), g, f);
  85. i = commit(tree(file(pA, zS), file(pE, zY), file(pF, zF)), h);
  86. byName = new HashMap<RevCommit, String>();
  87. for (Field z : RevWalkPathFilter6012Test.class.getDeclaredFields()) {
  88. if (z.getType() == RevCommit.class)
  89. byName.put((RevCommit) z.get(this), z.getName());
  90. }
  91. }
  92. protected void check(final RevCommit... order) throws Exception {
  93. markStart(i);
  94. final StringBuilder act = new StringBuilder();
  95. for (final RevCommit z : rw) {
  96. final String name = byName.get(z);
  97. assertNotNull(name);
  98. act.append(name);
  99. act.append(' ');
  100. }
  101. final StringBuilder exp = new StringBuilder();
  102. for (final RevCommit z : order) {
  103. final String name = byName.get(z);
  104. assertNotNull(name);
  105. exp.append(name);
  106. exp.append(' ');
  107. }
  108. assertEquals(exp.toString(), act.toString());
  109. }
  110. protected void filter(final String path) {
  111. rw.setTreeFilter(AndTreeFilter.create(PathFilterGroup
  112. .createFromStrings(Collections.singleton(path)),
  113. TreeFilter.ANY_DIFF));
  114. }
  115. @Test
  116. public void test1() throws Exception {
  117. // TODO --full-history
  118. check(i, h, g, f, e, d, c, b, a);
  119. }
  120. @Test
  121. public void test2() throws Exception {
  122. // TODO --full-history
  123. filter(pF);
  124. // TODO fix broken test
  125. // check(i, h, e, c, b, a);
  126. }
  127. @Test
  128. public void test3() throws Exception {
  129. // TODO --full-history
  130. rw.sort(RevSort.TOPO);
  131. filter(pF);
  132. // TODO fix broken test
  133. // check(i, h, e, c, b, a);
  134. }
  135. @Test
  136. public void test4() throws Exception {
  137. // TODO --full-history
  138. rw.sort(RevSort.COMMIT_TIME_DESC);
  139. filter(pF);
  140. // TODO fix broken test
  141. // check(i, h, e, c, b, a);
  142. }
  143. @Test
  144. public void test5() throws Exception {
  145. // TODO --simplify-merges
  146. filter(pF);
  147. // TODO fix broken test
  148. // check(i, e, c, b, a);
  149. }
  150. @Test
  151. public void test6() throws Exception {
  152. filter(pF);
  153. check(i, b, a);
  154. }
  155. @Test
  156. public void test7() throws Exception {
  157. rw.sort(RevSort.TOPO);
  158. filter(pF);
  159. check(i, b, a);
  160. }
  161. }