您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

RevWalkPathFilter6012Test.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright (C) 2009-2010, Google Inc. and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.revwalk;
  11. import static org.junit.Assert.assertEquals;
  12. import static org.junit.Assert.assertNotNull;
  13. import java.lang.reflect.Field;
  14. import java.util.Collections;
  15. import java.util.HashMap;
  16. import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
  17. import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
  18. import org.eclipse.jgit.treewalk.filter.TreeFilter;
  19. import org.junit.Before;
  20. import org.junit.Test;
  21. // Note: Much of this test case is broken as it depends upon
  22. // the graph applying topological sorting *before* doing merge
  23. // simplification. It also depends upon a difference between
  24. // full history and non-full history for a path, something we
  25. // don't quite yet have a distiction for in JGit.
  26. //
  27. public class RevWalkPathFilter6012Test extends RevWalkTestCase {
  28. private static final String pA = "pA", pF = "pF", pE = "pE";
  29. private RevCommit a, b, c, d, e, f, g, h, i;
  30. private HashMap<RevCommit, String> byName;
  31. @Override
  32. @Before
  33. public void setUp() throws Exception {
  34. super.setUp();
  35. // Test graph was stolen from git-core t6012-rev-list-simplify
  36. // (by Junio C Hamano in 65347030590bcc251a9ff2ed96487a0f1b9e9fa8)
  37. //
  38. final RevBlob zF = blob("zF");
  39. final RevBlob zH = blob("zH");
  40. final RevBlob zI = blob("zI");
  41. final RevBlob zS = blob("zS");
  42. final RevBlob zY = blob("zY");
  43. a = commit(tree(file(pF, zH)));
  44. b = commit(tree(file(pF, zI)), a);
  45. c = commit(tree(file(pF, zI)), a);
  46. d = commit(tree(file(pA, zS), file(pF, zI)), c);
  47. parseBody(d);
  48. e = commit(d.getTree(), d, b);
  49. f = commit(tree(file(pA, zS), file(pE, zY), file(pF, zI)), e);
  50. parseBody(f);
  51. g = commit(tree(file(pE, zY), file(pF, zI)), b);
  52. h = commit(f.getTree(), g, f);
  53. i = commit(tree(file(pA, zS), file(pE, zY), file(pF, zF)), h);
  54. byName = new HashMap<>();
  55. for (Field z : RevWalkPathFilter6012Test.class.getDeclaredFields()) {
  56. if (z.getType() == RevCommit.class)
  57. byName.put((RevCommit) z.get(this), z.getName());
  58. }
  59. }
  60. protected void check(RevCommit... order) throws Exception {
  61. markStart(i);
  62. final StringBuilder act = new StringBuilder();
  63. for (RevCommit z : rw) {
  64. final String name = byName.get(z);
  65. assertNotNull(name);
  66. act.append(name);
  67. act.append(' ');
  68. }
  69. final StringBuilder exp = new StringBuilder();
  70. for (RevCommit z : order) {
  71. final String name = byName.get(z);
  72. assertNotNull(name);
  73. exp.append(name);
  74. exp.append(' ');
  75. }
  76. assertEquals(exp.toString(), act.toString());
  77. }
  78. protected void filter(String path) {
  79. rw.setTreeFilter(AndTreeFilter.create(PathFilterGroup
  80. .createFromStrings(Collections.singleton(path)),
  81. TreeFilter.ANY_DIFF));
  82. }
  83. @Test
  84. public void test1() throws Exception {
  85. // TODO --full-history
  86. check(i, h, g, f, e, d, c, b, a);
  87. }
  88. @Test
  89. public void test2() throws Exception {
  90. // TODO --full-history
  91. filter(pF);
  92. // TODO fix broken test
  93. // check(i, h, e, c, b, a);
  94. }
  95. @Test
  96. public void test3() throws Exception {
  97. // TODO --full-history
  98. rw.sort(RevSort.TOPO);
  99. filter(pF);
  100. // TODO fix broken test
  101. // check(i, h, e, c, b, a);
  102. }
  103. @Test
  104. public void test4() throws Exception {
  105. // TODO --full-history
  106. rw.sort(RevSort.COMMIT_TIME_DESC);
  107. filter(pF);
  108. // TODO fix broken test
  109. // check(i, h, e, c, b, a);
  110. }
  111. @Test
  112. public void test5() throws Exception {
  113. // TODO --simplify-merges
  114. filter(pF);
  115. // TODO fix broken test
  116. // check(i, e, c, b, a);
  117. }
  118. @Test
  119. public void test6() throws Exception {
  120. filter(pF);
  121. check(i, b, a);
  122. }
  123. @Test
  124. public void test7() throws Exception {
  125. rw.sort(RevSort.TOPO);
  126. filter(pF);
  127. check(i, b, a);
  128. }
  129. }