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
49 import org.eclipse.jgit.errors.IncorrectObjectTypeException;
50 import org.eclipse.jgit.errors.MissingObjectException;
51 import org.eclipse.jgit.lib.AnyObjectId;
52 import org.eclipse.jgit.lib.ObjectReader;
53 import org.eclipse.jgit.lib.Repository;
54
55
56 public interface DepthWalk {
57
58 public int getDepth();
59
60
61 public RevFlag getUnshallowFlag();
62
63
64 public RevFlag getReinterestingFlag();
65
66
67 public static class Commit extends RevCommit {
68
69 int depth;
70
71
72 public int getDepth() {
73 return depth;
74 }
75
76
77
78
79
80
81
82 protected Commit(AnyObjectId id) {
83 super(id);
84 depth = -1;
85 }
86 }
87
88
89 public class RevWalk extends org.eclipse.jgit.revwalk.RevWalk implements DepthWalk {
90 private final int depth;
91
92 private final RevFlag UNSHALLOW;
93
94 private final RevFlag REINTERESTING;
95
96
97
98
99
100 public RevWalk(Repository repo, int depth) {
101 super(repo);
102
103 this.depth = depth;
104 this.UNSHALLOW = newFlag("UNSHALLOW");
105 this.REINTERESTING = newFlag("REINTERESTING");
106 }
107
108
109
110
111
112 public RevWalk(ObjectReader or, int depth) {
113 super(or);
114
115 this.depth = depth;
116 this.UNSHALLOW = newFlag("UNSHALLOW");
117 this.REINTERESTING = newFlag("REINTERESTING");
118 }
119
120
121
122
123
124
125
126
127
128
129 public void markRoot(RevCommit c) throws MissingObjectException,
130 IncorrectObjectTypeException, IOException {
131 if (c instanceof Commit)
132 ((Commit) c).depth = 0;
133 super.markStart(c);
134 }
135
136 @Override
137 protected RevCommit createCommit(AnyObjectId id) {
138 return new Commit(id);
139 }
140
141 @Override
142 public int getDepth() {
143 return depth;
144 }
145
146 @Override
147 public RevFlag getUnshallowFlag() {
148 return UNSHALLOW;
149 }
150
151 @Override
152 public RevFlag getReinterestingFlag() {
153 return REINTERESTING;
154 }
155
156
157
158
159 @Override
160 public ObjectWalk toObjectWalkWithSameObjects() {
161 ObjectWalk ow = new ObjectWalk(reader, depth);
162 ow.objects = objects;
163 ow.freeFlags = freeFlags;
164 return ow;
165 }
166 }
167
168
169 public class ObjectWalk extends org.eclipse.jgit.revwalk.ObjectWalk implements DepthWalk {
170 private final int depth;
171
172 private final RevFlag UNSHALLOW;
173
174 private final RevFlag REINTERESTING;
175
176
177
178
179
180 public ObjectWalk(Repository repo, int depth) {
181 super(repo);
182
183 this.depth = depth;
184 this.UNSHALLOW = newFlag("UNSHALLOW");
185 this.REINTERESTING = newFlag("REINTERESTING");
186 }
187
188
189
190
191
192 public ObjectWalk(ObjectReader or, int depth) {
193 super(or);
194
195 this.depth = depth;
196 this.UNSHALLOW = newFlag("UNSHALLOW");
197 this.REINTERESTING = newFlag("REINTERESTING");
198 }
199
200
201
202
203
204
205
206
207
208
209 public void markRoot(RevObject o) throws MissingObjectException,
210 IncorrectObjectTypeException, IOException {
211 RevObject c = o;
212 while (c instanceof RevTag) {
213 c = ((RevTag) c).getObject();
214 parseHeaders(c);
215 }
216 if (c instanceof Commit)
217 ((Commit) c).depth = 0;
218 super.markStart(o);
219 }
220
221
222
223
224
225
226
227
228
229
230
231
232
233 public void markUnshallow(RevObject c) throws MissingObjectException,
234 IncorrectObjectTypeException, IOException {
235 if (c instanceof RevCommit)
236 c.add(UNSHALLOW);
237 super.markStart(c);
238 }
239
240 @Override
241 protected RevCommit createCommit(AnyObjectId id) {
242 return new Commit(id);
243 }
244
245 @Override
246 public int getDepth() {
247 return depth;
248 }
249
250 @Override
251 public RevFlag getUnshallowFlag() {
252 return UNSHALLOW;
253 }
254
255 @Override
256 public RevFlag getReinterestingFlag() {
257 return REINTERESTING;
258 }
259 }
260 }