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