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