1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.transport;
11
12 import static java.util.Objects.requireNonNull;
13
14 import java.util.ArrayList;
15 import java.util.Collections;
16 import java.util.HashSet;
17 import java.util.List;
18 import java.util.Set;
19
20 import org.eclipse.jgit.annotations.NonNull;
21 import org.eclipse.jgit.annotations.Nullable;
22 import org.eclipse.jgit.lib.ObjectId;
23
24
25
26
27
28
29
30
31
32 public final class FetchV2Request extends FetchRequest {
33 private final List<ObjectId> peerHas;
34
35 private final List<String> wantedRefs;
36
37 private final boolean doneReceived;
38
39 private final boolean waitForDone;
40
41 @NonNull
42 private final List<String> serverOptions;
43
44 private final boolean sidebandAll;
45
46 @NonNull
47 private final List<String> packfileUriProtocols;
48
49 FetchV2Request(@NonNull List<ObjectId> peerHas,
50 @NonNull List<String> wantedRefs,
51 @NonNull Set<ObjectId> wantIds,
52 @NonNull Set<ObjectId> clientShallowCommits, int deepenSince,
53 @NonNull List<String> deepenNotRefs, int depth,
54 @NonNull FilterSpec filterSpec,
55 boolean doneReceived, boolean waitForDone,
56 @NonNull Set<String> clientCapabilities,
57 @Nullable String agent, @NonNull List<String> serverOptions,
58 boolean sidebandAll, @NonNull List<String> packfileUriProtocols) {
59 super(wantIds, depth, clientShallowCommits, filterSpec,
60 clientCapabilities, deepenSince,
61 deepenNotRefs, agent);
62 this.peerHas = requireNonNull(peerHas);
63 this.wantedRefs = requireNonNull(wantedRefs);
64 this.doneReceived = doneReceived;
65 this.waitForDone = waitForDone;
66 this.serverOptions = requireNonNull(serverOptions);
67 this.sidebandAll = sidebandAll;
68 this.packfileUriProtocols = packfileUriProtocols;
69 }
70
71
72
73
74 @NonNull
75 List<ObjectId> getPeerHas() {
76 return peerHas;
77 }
78
79
80
81
82
83
84 @NonNull
85 public List<String> getWantedRefs() {
86 return wantedRefs;
87 }
88
89
90
91
92 boolean wasDoneReceived() {
93 return doneReceived;
94 }
95
96
97
98
99 boolean wasWaitForDoneReceived() {
100 return waitForDone;
101 }
102
103
104
105
106
107
108
109
110
111 @NonNull
112 public List<String> getServerOptions() {
113 return serverOptions;
114 }
115
116
117
118
119 boolean getSidebandAll() {
120 return sidebandAll;
121 }
122
123 @NonNull
124 List<String> getPackfileUriProtocols() {
125 return packfileUriProtocols;
126 }
127
128
129 static Builder builder() {
130 return new Builder();
131 }
132
133
134 static final class Builder {
135 final List<ObjectId> peerHas = new ArrayList<>();
136
137 final List<String> wantedRefs = new ArrayList<>();
138
139 final Set<ObjectId> wantIds = new HashSet<>();
140
141 final Set<ObjectId> clientShallowCommits = new HashSet<>();
142
143 final List<String> deepenNotRefs = new ArrayList<>();
144
145 final Set<String> clientCapabilities = new HashSet<>();
146
147 int depth;
148
149 int deepenSince;
150
151 FilterSpec filterSpec = FilterSpec.NO_FILTER;
152
153 boolean doneReceived;
154
155 boolean waitForDone;
156
157 @Nullable
158 String agent;
159
160 final List<String> serverOptions = new ArrayList<>();
161
162 boolean sidebandAll;
163
164 final List<String> packfileUriProtocols = new ArrayList<>();
165
166 private Builder() {
167 }
168
169
170
171
172
173
174 Builder addPeerHas(ObjectId objectId) {
175 peerHas.add(objectId);
176 return this;
177 }
178
179
180
181
182
183
184
185
186 Builder addWantedRef(String refName) {
187 wantedRefs.add(refName);
188 return this;
189 }
190
191
192
193
194
195
196 Builder addClientCapability(String clientCapability) {
197 clientCapabilities.add(clientCapability);
198 return this;
199 }
200
201
202
203
204
205
206 Builder addWantId(ObjectId wantId) {
207 wantIds.add(wantId);
208 return this;
209 }
210
211
212
213
214
215
216 Builder addClientShallowCommit(ObjectId shallowOid) {
217 clientShallowCommits.add(shallowOid);
218 return this;
219 }
220
221
222
223
224
225
226 Builder setDepth(int d) {
227 depth = d;
228 return this;
229 }
230
231
232
233
234
235 int getDepth() {
236 return depth;
237 }
238
239
240
241
242
243 boolean hasDeepenNotRefs() {
244 return !deepenNotRefs.isEmpty();
245 }
246
247
248
249
250
251
252 Builder addDeepenNotRef(String deepenNotRef) {
253 deepenNotRefs.add(deepenNotRef);
254 return this;
255 }
256
257
258
259
260
261
262 Builder setDeepenSince(int value) {
263 deepenSince = value;
264 return this;
265 }
266
267
268
269
270
271 int getDeepenSince() {
272 return deepenSince;
273 }
274
275
276
277
278
279
280 Builder setFilterSpec(@NonNull FilterSpec filter) {
281 filterSpec = requireNonNull(filter);
282 return this;
283 }
284
285
286
287
288
289
290 Builder setDoneReceived() {
291 doneReceived = true;
292 return this;
293 }
294
295
296
297
298
299
300 Builder setWaitForDone() {
301 waitForDone = true;
302 return this;
303 }
304
305
306
307
308
309
310
311
312
313
314 Builder setAgent(@Nullable String agentValue) {
315 agent = agentValue;
316 return this;
317 }
318
319
320
321
322
323
324
325
326
327
328
329 Builder addServerOption(@NonNull String value) {
330 serverOptions.add(value);
331 return this;
332 }
333
334
335
336
337
338 Builder setSidebandAll(boolean value) {
339 sidebandAll = value;
340 return this;
341 }
342
343 Builder addPackfileUriProtocol(@NonNull String value) {
344 packfileUriProtocols.add(value);
345 return this;
346 }
347
348
349
350
351 FetchV2Request build() {
352 return new FetchV2Request(peerHas, wantedRefs, wantIds,
353 clientShallowCommits, deepenSince, deepenNotRefs,
354 depth, filterSpec, doneReceived, waitForDone, clientCapabilities,
355 agent, Collections.unmodifiableList(serverOptions),
356 sidebandAll,
357 Collections.unmodifiableList(packfileUriProtocols));
358 }
359 }
360 }