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