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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
|
/*
* Copyright (C) 2018, 2022 Google LLC. and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
* https://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package org.eclipse.jgit.transport;
import static java.util.Objects.requireNonNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.jgit.annotations.NonNull;
import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.lib.ObjectId;
/**
* Fetch request from git protocol v2.
*
* <p>
* This is used as an input to {@link ProtocolV2Hook}.
*
* @since 5.1
*/
public final class FetchV2Request extends FetchRequest {
private final List<ObjectId> peerHas;
private final List<String> wantedRefs;
private final boolean doneReceived;
private final boolean waitForDone;
@NonNull
private final List<String> serverOptions;
private final boolean sidebandAll;
@NonNull
private final List<String> packfileUriProtocols;
FetchV2Request(@NonNull List<ObjectId> peerHas,
@NonNull List<String> wantedRefs,
@NonNull Set<ObjectId> wantIds,
@NonNull Set<ObjectId> clientShallowCommits, int deepenSince,
@NonNull List<String> deepenNots, int depth,
@NonNull FilterSpec filterSpec,
boolean doneReceived, boolean waitForDone,
@NonNull Set<String> clientCapabilities,
@Nullable String agent, @NonNull List<String> serverOptions,
boolean sidebandAll, @NonNull List<String> packfileUriProtocols,
@Nullable String clientSID) {
super(wantIds, depth, clientShallowCommits, filterSpec,
clientCapabilities, deepenSince,
deepenNots, agent, clientSID);
this.peerHas = requireNonNull(peerHas);
this.wantedRefs = requireNonNull(wantedRefs);
this.doneReceived = doneReceived;
this.waitForDone = waitForDone;
this.serverOptions = requireNonNull(serverOptions);
this.sidebandAll = sidebandAll;
this.packfileUriProtocols = packfileUriProtocols;
}
/**
* Get object ids received in the "have" lines
*
* @return object ids received in the "have" lines
*/
@NonNull
List<ObjectId> getPeerHas() {
return peerHas;
}
/**
* Get list of references received in "want-ref" lines
*
* @return list of references received in "want-ref" lines
*
* @since 5.4
*/
@NonNull
public List<String> getWantedRefs() {
return wantedRefs;
}
/**
* Whether the request had a "done" line
*
* @return true if the request had a "done" line
*/
boolean wasDoneReceived() {
return doneReceived;
}
/**
* Whether the request had a "wait-for-done" line
*
* @return true if the request had a "wait-for-done" line
*/
boolean wasWaitForDoneReceived() {
return waitForDone;
}
/**
* Options received in server-option lines. The caller can choose to act on
* these in an application-specific way
*
* @return Immutable list of server options received in the request
*
* @since 5.2
*/
@NonNull
public List<String> getServerOptions() {
return serverOptions;
}
/**
* Whether "sideband-all" was received
*
* @return true if "sideband-all" was received
*/
boolean getSidebandAll() {
return sidebandAll;
}
@NonNull
List<String> getPackfileUriProtocols() {
return packfileUriProtocols;
}
/**
* Get builder
*
* @return A builder of {@link FetchV2Request}.
*/
static Builder builder() {
return new Builder();
}
/** A builder for {@link FetchV2Request}. */
static final class Builder {
final List<ObjectId> peerHas = new ArrayList<>();
final List<String> wantedRefs = new ArrayList<>();
final Set<ObjectId> wantIds = new HashSet<>();
final Set<ObjectId> clientShallowCommits = new HashSet<>();
final List<String> deepenNots = new ArrayList<>();
final Set<String> clientCapabilities = new HashSet<>();
int depth;
int deepenSince;
FilterSpec filterSpec = FilterSpec.NO_FILTER;
boolean doneReceived;
boolean waitForDone;
@Nullable
String agent;
@Nullable
String clientSID;
final List<String> serverOptions = new ArrayList<>();
boolean sidebandAll;
final List<String> packfileUriProtocols = new ArrayList<>();
private Builder() {
}
/**
* Add object the peer has
*
* @param objectId
* object id received in a "have" line
* @return this builder
*/
Builder addPeerHas(ObjectId objectId) {
peerHas.add(objectId);
return this;
}
/**
* Add Ref received in "want-ref" line and the object-id it refers to
*
* @param refName
* reference name
* @return this builder
*/
Builder addWantedRef(String refName) {
wantedRefs.add(refName);
return this;
}
/**
* Add client capability
*
* @param clientCapability
* capability line sent by the client
* @return this builder
*/
Builder addClientCapability(String clientCapability) {
clientCapabilities.add(clientCapability);
return this;
}
/**
* Add object received in "want" line
*
* @param wantId
* object id received in a "want" line
* @return this builder
*/
Builder addWantId(ObjectId wantId) {
wantIds.add(wantId);
return this;
}
/**
* Add Object received in a "shallow" line
*
* @param shallowOid
* object id received in a "shallow" line
* @return this builder
*/
Builder addClientShallowCommit(ObjectId shallowOid) {
clientShallowCommits.add(shallowOid);
return this;
}
/**
* Set depth received in "deepen" line
*
* @param d
* Depth received in a "deepen" line
* @return this builder
*/
Builder setDepth(int d) {
depth = d;
return this;
}
/**
* Get depth set in request
*
* @return depth set in the request (via a "deepen" line). Defaulting to
* 0 if not set.
*/
int getDepth() {
return depth;
}
/**
* Whether there has been at least one ""deepen not" line
*
* @return true if there has been at least one "deepen not" line in the
* request so far
*/
boolean hasDeepenNots() {
return !deepenNots.isEmpty();
}
/**
* Add reference received in a "deepen not" line
*
* @param deepenNot
* reference received in a "deepen not" line
* @return this builder
*/
Builder addDeepenNot(String deepenNot) {
deepenNots.add(deepenNot);
return this;
}
/**
* Set Unix timestamp received in a "deepen since" line
*
* @param value
* Unix timestamp received in a "deepen since" line
* @return this builder
*/
Builder setDeepenSince(int value) {
deepenSince = value;
return this;
}
/**
* Get shallow since value
*
* @return shallow since value, sent before in a "deepen since" line. 0
* by default.
*/
int getDeepenSince() {
return deepenSince;
}
/**
* Set filter spec
*
* @param filter
* spec set in a "filter" line
* @return this builder
*/
Builder setFilterSpec(@NonNull FilterSpec filter) {
filterSpec = requireNonNull(filter);
return this;
}
/**
* Mark that the "done" line has been received.
*
* @return this builder
*/
Builder setDoneReceived() {
doneReceived = true;
return this;
}
/**
* Mark that the "wait-for-done" line has been received.
*
* @return this builder
*/
Builder setWaitForDone() {
waitForDone = true;
return this;
}
/**
* Value of an agent line received after the command and before the
* arguments. E.g. "agent=a.b.c/1.0" should set "a.b.c/1.0".
*
* @param agentValue
* the client-supplied agent capability, without the leading
* "agent="
* @return this builder
*/
Builder setAgent(@Nullable String agentValue) {
agent = agentValue;
return this;
}
/**
* Set value of client-supplied session capability
*
* @param clientSIDValue
* the client-supplied session capability, without the
* leading "session-id="
* @return this builder
*/
Builder setClientSID(@Nullable String clientSIDValue) {
clientSID = clientSIDValue;
return this;
}
/**
* Records an application-specific option supplied in a server-option
* line, for later retrieval with
* {@link FetchV2Request#getServerOptions}.
*
* @param value
* the client-supplied server-option capability, without
* leading "server-option=".
* @return this builder
*/
Builder addServerOption(@NonNull String value) {
serverOptions.add(value);
return this;
}
/**
* Set whether client sent "sideband-all
*
* @param value
* true if client sent "sideband-all"
* @return this builder
*/
Builder setSidebandAll(boolean value) {
sidebandAll = value;
return this;
}
Builder addPackfileUriProtocol(@NonNull String value) {
packfileUriProtocols.add(value);
return this;
}
/**
* Build initialized fetch request
*
* @return Initialized fetch request
*/
FetchV2Request build() {
return new FetchV2Request(peerHas, wantedRefs, wantIds,
clientShallowCommits, deepenSince, deepenNots,
depth, filterSpec, doneReceived, waitForDone, clientCapabilities,
agent, Collections.unmodifiableList(serverOptions),
sidebandAll,
Collections.unmodifiableList(packfileUriProtocols),
clientSID);
}
}
}
|