1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 package org.eclipse.jgit.revwalk;
45
46 import static org.junit.Assert.assertEquals;
47 import static org.junit.Assert.assertNotNull;
48
49 import java.lang.reflect.Field;
50 import java.util.Collections;
51 import java.util.HashMap;
52
53 import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
54 import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
55 import org.eclipse.jgit.treewalk.filter.TreeFilter;
56 import org.junit.Before;
57 import org.junit.Test;
58
59
60
61
62
63
64
65 public class RevWalkPathFilter6012Test extends RevWalkTestCase {
66 private static final String pA = "pA", pF = "pF", pE = "pE";
67
68 private RevCommit a, b, c, d, e, f, g, h, i;
69
70 private HashMap<RevCommit, String> byName;
71
72 @Override
73 @Before
74 public void setUp() throws Exception {
75 super.setUp();
76
77
78
79
80 final RevBlob zF = blob("zF");
81 final RevBlob zH = blob("zH");
82 final RevBlob zI = blob("zI");
83 final RevBlob zS = blob("zS");
84 final RevBlob zY = blob("zY");
85
86 a = commit(tree(file(pF, zH)));
87 b = commit(tree(file(pF, zI)), a);
88 c = commit(tree(file(pF, zI)), a);
89 d = commit(tree(file(pA, zS), file(pF, zI)), c);
90 parseBody(d);
91 e = commit(d.getTree(), d, b);
92 f = commit(tree(file(pA, zS), file(pE, zY), file(pF, zI)), e);
93 parseBody(f);
94 g = commit(tree(file(pE, zY), file(pF, zI)), b);
95 h = commit(f.getTree(), g, f);
96 i = commit(tree(file(pA, zS), file(pE, zY), file(pF, zF)), h);
97
98 byName = new HashMap<>();
99 for (Field z : RevWalkPathFilter6012Test.class.getDeclaredFields()) {
100 if (z.getType() == RevCommit.class)
101 byName.put((RevCommit) z.get(this), z.getName());
102 }
103 }
104
105 protected void check(RevCommit... order) throws Exception {
106 markStart(i);
107 final StringBuilder act = new StringBuilder();
108 for (RevCommit z : rw) {
109 final String name = byName.get(z);
110 assertNotNull(name);
111 act.append(name);
112 act.append(' ');
113 }
114 final StringBuilder exp = new StringBuilder();
115 for (RevCommit z : order) {
116 final String name = byName.get(z);
117 assertNotNull(name);
118 exp.append(name);
119 exp.append(' ');
120 }
121 assertEquals(exp.toString(), act.toString());
122 }
123
124 protected void filter(String path) {
125 rw.setTreeFilter(AndTreeFilter.create(PathFilterGroup
126 .createFromStrings(Collections.singleton(path)),
127 TreeFilter.ANY_DIFF));
128 }
129
130 @Test
131 public void test1() throws Exception {
132
133 check(i, h, g, f, e, d, c, b, a);
134 }
135
136 @Test
137 public void test2() throws Exception {
138
139 filter(pF);
140
141
142 }
143
144 @Test
145 public void test3() throws Exception {
146
147 rw.sort(RevSort.TOPO);
148 filter(pF);
149
150
151 }
152
153 @Test
154 public void test4() throws Exception {
155
156 rw.sort(RevSort.COMMIT_TIME_DESC);
157 filter(pF);
158
159
160 }
161
162 @Test
163 public void test5() throws Exception {
164
165 filter(pF);
166
167
168 }
169
170 @Test
171 public void test6() throws Exception {
172 filter(pF);
173 check(i, b, a);
174 }
175
176 @Test
177 public void test7() throws Exception {
178 rw.sort(RevSort.TOPO);
179 filter(pF);
180 check(i, b, a);
181 }
182 }