1
2
3
4
5
6
7
8
9
10
11
12 package org.eclipse.jgit.revwalk;
13
14 import java.io.IOException;
15 import java.util.Collections;
16 import java.util.List;
17 import java.util.Objects;
18
19 import org.eclipse.jgit.errors.IncorrectObjectTypeException;
20 import org.eclipse.jgit.errors.MissingObjectException;
21 import org.eclipse.jgit.lib.AnyObjectId;
22 import org.eclipse.jgit.lib.ObjectId;
23 import org.eclipse.jgit.lib.ObjectReader;
24 import org.eclipse.jgit.lib.Repository;
25
26
27
28
29 public interface DepthWalk {
30
31
32
33
34
35 int getDepth();
36
37
38
39
40
41
42 default int getDeepenSince() {
43 return 0;
44 }
45
46
47
48
49
50 default List<ObjectId> getDeepenNots() {
51 return Collections.emptyList();
52 }
53
54
55
56
57
58
59
60 RevFlag getUnshallowFlag();
61
62
63
64
65
66
67 RevFlag getReinterestingFlag();
68
69
70
71
72
73 RevFlag getDeepenNotFlag();
74
75
76 public static class Commit extends RevCommit {
77
78 int depth;
79
80 boolean isBoundary;
81
82
83
84
85
86 boolean makesChildBoundary;
87
88
89 public int getDepth() {
90 return depth;
91 }
92
93
94
95
96
97
98 public boolean isBoundary() {
99 return isBoundary;
100 }
101
102
103
104
105
106
107
108 protected Commit(AnyObjectId id) {
109 super(id);
110 depth = -1;
111 }
112 }
113
114
115 public class RevWalk extends org.eclipse.jgit.revwalk.RevWalk implements DepthWalk {
116 private final int depth;
117
118 private int deepenSince;
119
120 private List<ObjectId> deepenNots;
121
122 private final RevFlag UNSHALLOW;
123
124 private final RevFlag REINTERESTING;
125
126 private final RevFlag DEEPEN_NOT;
127
128
129
130
131
132 public RevWalk(Repository repo, int depth) {
133 super(repo);
134
135 this.depth = depth;
136 this.deepenNots = Collections.emptyList();
137 this.UNSHALLOW = newFlag("UNSHALLOW");
138 this.REINTERESTING = newFlag("REINTERESTING");
139 this.DEEPEN_NOT = newFlag("DEEPEN_NOT");
140 }
141
142
143
144
145
146 public RevWalk(ObjectReader or, int depth) {
147 super(or);
148
149 this.depth = depth;
150 this.deepenNots = Collections.emptyList();
151 this.UNSHALLOW = newFlag("UNSHALLOW");
152 this.REINTERESTING = newFlag("REINTERESTING");
153 this.DEEPEN_NOT = newFlag("DEEPEN_NOT");
154 }
155
156
157
158
159
160
161
162
163
164
165 public void markRoot(RevCommit c) throws MissingObjectException,
166 IncorrectObjectTypeException, IOException {
167 if (c instanceof Commit)
168 ((Commit) c).depth = 0;
169 super.markStart(c);
170 }
171
172 @Override
173 protected RevCommit createCommit(AnyObjectId id) {
174 return new Commit(id);
175 }
176
177 @Override
178 public int getDepth() {
179 return depth;
180 }
181
182 @Override
183 public int getDeepenSince() {
184 return deepenSince;
185 }
186
187
188
189
190
191
192
193
194 public void setDeepenSince(int limit) {
195 deepenSince = limit;
196 }
197
198 @Override
199 public List<ObjectId> getDeepenNots() {
200 return deepenNots;
201 }
202
203
204
205
206
207
208
209
210
211 public void setDeepenNots(List<ObjectId> deepenNots) {
212 this.deepenNots = Objects.requireNonNull(deepenNots);
213 }
214
215 @Override
216 public RevFlag getUnshallowFlag() {
217 return UNSHALLOW;
218 }
219
220 @Override
221 public RevFlag getReinterestingFlag() {
222 return REINTERESTING;
223 }
224
225 @Override
226 public RevFlag getDeepenNotFlag() {
227 return DEEPEN_NOT;
228 }
229
230
231
232
233 @Override
234 public ObjectWalk toObjectWalkWithSameObjects() {
235 ObjectWalk ow = new ObjectWalk(reader, depth);
236 ow.deepenSince = deepenSince;
237 ow.deepenNots = deepenNots;
238 ow.objects = objects;
239 ow.freeFlags = freeFlags;
240 return ow;
241 }
242 }
243
244
245 public class ObjectWalk extends org.eclipse.jgit.revwalk.ObjectWalk implements DepthWalk {
246 private final int depth;
247
248 private int deepenSince;
249
250 private List<ObjectId> deepenNots;
251
252 private final RevFlag UNSHALLOW;
253
254 private final RevFlag REINTERESTING;
255
256 private final RevFlag DEEPEN_NOT;
257
258
259
260
261
262 public ObjectWalk(Repository repo, int depth) {
263 super(repo);
264
265 this.depth = depth;
266 this.deepenNots = Collections.emptyList();
267 this.UNSHALLOW = newFlag("UNSHALLOW");
268 this.REINTERESTING = newFlag("REINTERESTING");
269 this.DEEPEN_NOT = newFlag("DEEPEN_NOT");
270 }
271
272
273
274
275
276 public ObjectWalk(ObjectReader or, int depth) {
277 super(or);
278
279 this.depth = depth;
280 this.deepenNots = Collections.emptyList();
281 this.UNSHALLOW = newFlag("UNSHALLOW");
282 this.REINTERESTING = newFlag("REINTERESTING");
283 this.DEEPEN_NOT = newFlag("DEEPEN_NOT");
284 }
285
286
287
288
289
290
291
292
293
294
295 public void markRoot(RevObject o) throws MissingObjectException,
296 IncorrectObjectTypeException, IOException {
297 RevObject c = o;
298 while (c instanceof RevTag) {
299 c = ((RevTag) c).getObject();
300 parseHeaders(c);
301 }
302 if (c instanceof Commit)
303 ((Commit) c).depth = 0;
304 super.markStart(o);
305 }
306
307
308
309
310
311
312
313
314
315
316
317
318
319 public void markUnshallow(RevObject c) throws MissingObjectException,
320 IncorrectObjectTypeException, IOException {
321 if (c instanceof RevCommit)
322 c.add(UNSHALLOW);
323 super.markStart(c);
324 }
325
326 @Override
327 protected RevCommit createCommit(AnyObjectId id) {
328 return new Commit(id);
329 }
330
331 @Override
332 public int getDepth() {
333 return depth;
334 }
335
336 @Override
337 public int getDeepenSince() {
338 return deepenSince;
339 }
340
341 @Override
342 public List<ObjectId> getDeepenNots() {
343 return deepenNots;
344 }
345
346 @Override
347 public RevFlag getUnshallowFlag() {
348 return UNSHALLOW;
349 }
350
351 @Override
352 public RevFlag getReinterestingFlag() {
353 return REINTERESTING;
354 }
355
356 @Override
357 public RevFlag getDeepenNotFlag() {
358 return DEEPEN_NOT;
359 }
360 }
361 }