Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

RevWalkPathFilter6012Test.java 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. @Override
  65. @Before
  66. public void setUp() throws Exception {
  67. super.setUp();
  68. // Test graph was stolen from git-core t6012-rev-list-simplify
  69. // (by Junio C Hamano in 65347030590bcc251a9ff2ed96487a0f1b9e9fa8)
  70. //
  71. final RevBlob zF = blob("zF");
  72. final RevBlob zH = blob("zH");
  73. final RevBlob zI = blob("zI");
  74. final RevBlob zS = blob("zS");
  75. final RevBlob zY = blob("zY");
  76. a = commit(tree(file(pF, zH)));
  77. b = commit(tree(file(pF, zI)), a);
  78. c = commit(tree(file(pF, zI)), a);
  79. d = commit(tree(file(pA, zS), file(pF, zI)), c);
  80. parseBody(d);
  81. e = commit(d.getTree(), d, b);
  82. f = commit(tree(file(pA, zS), file(pE, zY), file(pF, zI)), e);
  83. parseBody(f);
  84. g = commit(tree(file(pE, zY), file(pF, zI)), b);
  85. h = commit(f.getTree(), g, f);
  86. i = commit(tree(file(pA, zS), file(pE, zY), file(pF, zF)), h);
  87. byName = new HashMap<>();
  88. for (Field z : RevWalkPathFilter6012Test.class.getDeclaredFields()) {
  89. if (z.getType() == RevCommit.class)
  90. byName.put((RevCommit) z.get(this), z.getName());
  91. }
  92. }
  93. protected void check(final RevCommit... order) throws Exception {
  94. markStart(i);
  95. final StringBuilder act = new StringBuilder();
  96. for (final RevCommit z : rw) {
  97. final String name = byName.get(z);
  98. assertNotNull(name);
  99. act.append(name);
  100. act.append(' ');
  101. }
  102. final StringBuilder exp = new StringBuilder();
  103. for (final RevCommit z : order) {
  104. final String name = byName.get(z);
  105. assertNotNull(name);
  106. exp.append(name);
  107. exp.append(' ');
  108. }
  109. assertEquals(exp.toString(), act.toString());
  110. }
  111. protected void filter(final String path) {
  112. rw.setTreeFilter(AndTreeFilter.create(PathFilterGroup
  113. .createFromStrings(Collections.singleton(path)),
  114. TreeFilter.ANY_DIFF));
  115. }
  116. @Test
  117. public void test1() throws Exception {
  118. // TODO --full-history
  119. check(i, h, g, f, e, d, c, b, a);
  120. }
  121. @Test
  122. public void test2() throws Exception {
  123. // TODO --full-history
  124. filter(pF);
  125. // TODO fix broken test
  126. // check(i, h, e, c, b, a);
  127. }
  128. @Test
  129. public void test3() throws Exception {
  130. // TODO --full-history
  131. rw.sort(RevSort.TOPO);
  132. filter(pF);
  133. // TODO fix broken test
  134. // check(i, h, e, c, b, a);
  135. }
  136. @Test
  137. public void test4() throws Exception {
  138. // TODO --full-history
  139. rw.sort(RevSort.COMMIT_TIME_DESC);
  140. filter(pF);
  141. // TODO fix broken test
  142. // check(i, h, e, c, b, a);
  143. }
  144. @Test
  145. public void test5() throws Exception {
  146. // TODO --simplify-merges
  147. filter(pF);
  148. // TODO fix broken test
  149. // check(i, e, c, b, a);
  150. }
  151. @Test
  152. public void test6() throws Exception {
  153. filter(pF);
  154. check(i, b, a);
  155. }
  156. @Test
  157. public void test7() throws Exception {
  158. rw.sort(RevSort.TOPO);
  159. filter(pF);
  160. check(i, b, a);
  161. }
  162. }