1 /*
2 * Copyright (C) 2018, 2022 Google LLC. and others
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Distribution License v. 1.0 which is available at
6 * https://www.eclipse.org/org/documents/edl-v10.php.
7 *
8 * SPDX-License-Identifier: BSD-3-Clause
9 */
10 package org.eclipse.jgit.transport;
11
12 import static java.util.Objects.requireNonNull;
13
14 import java.util.List;
15 import java.util.Set;
16
17 import org.eclipse.jgit.annotations.NonNull;
18 import org.eclipse.jgit.annotations.Nullable;
19 import org.eclipse.jgit.lib.ObjectId;
20
21 /**
22 * Common fields between v0/v1/v2 fetch requests.
23 */
24 abstract class FetchRequest {
25
26 final Set<ObjectId> wantIds;
27
28 final int depth;
29
30 final Set<ObjectId> clientShallowCommits;
31
32 final FilterSpec filterSpec;
33
34 final Set<String> clientCapabilities;
35
36 final int deepenSince;
37
38 final List<String> deepenNots;
39
40 @Nullable
41 final String agent;
42
43 /**
44 * Initialize the common fields of a fetch request.
45 *
46 * @param wantIds
47 * list of want ids
48 * @param depth
49 * how deep to go in the tree
50 * @param clientShallowCommits
51 * commits the client has without history
52 * @param filterSpec
53 * the filter spec
54 * @param clientCapabilities
55 * capabilities sent in the request
56 * @param deepenNots
57 * Requests that the shallow clone/fetch should be cut at these
58 * specific revisions instead of a depth.
59 * @param deepenSince
60 * Requests that the shallow clone/fetch should be cut at a
61 * specific time, instead of depth
62 * @param agent
63 * agent as reported by the client in the request body
64 */
65 FetchRequest(@NonNull Set<ObjectId> wantIds, int depth,
66 @NonNull Set<ObjectId> clientShallowCommits,
67 @NonNull FilterSpec filterSpec,
68 @NonNull Set<String> clientCapabilities, int deepenSince,
69 @NonNull List<String> deepenNots, @Nullable String agent) {
70 this.wantIds = requireNonNull(wantIds);
71 this.depth = depth;
72 this.clientShallowCommits = requireNonNull(clientShallowCommits);
73 this.filterSpec = requireNonNull(filterSpec);
74 this.clientCapabilities = requireNonNull(clientCapabilities);
75 this.deepenSince = deepenSince;
76 this.deepenNots = requireNonNull(deepenNots);
77 this.agent = agent;
78 }
79
80 /**
81 * @return object ids in the "want" (and "want-ref") lines of the request
82 */
83 @NonNull
84 Set<ObjectId> getWantIds() {
85 return wantIds;
86 }
87
88 /**
89 * @return the depth set in a "deepen" line. 0 by default.
90 */
91 int getDepth() {
92 return depth;
93 }
94
95 /**
96 * Shallow commits the client already has.
97 *
98 * These are sent by the client in "shallow" request lines.
99 *
100 * @return set of commits the client has declared as shallow.
101 */
102 @NonNull
103 Set<ObjectId> getClientShallowCommits() {
104 return clientShallowCommits;
105 }
106
107 /**
108 * @return the filter spec given in a "filter" line
109 */
110 @NonNull
111 FilterSpec getFilterSpec() {
112 return filterSpec;
113 }
114
115 /**
116 * Capabilities that the client wants enabled from the server.
117 *
118 * Capabilities are options that tune the expected response from the server,
119 * like "thin-pack", "no-progress" or "ofs-delta". This list should be a
120 * subset of the capabilities announced by the server in its first response.
121 *
122 * These options are listed and well-defined in the git protocol
123 * specification.
124 *
125 * The agent capability is not included in this set. It can be retrieved via
126 * {@link #getAgent()}.
127 *
128 * @return capabilities sent by the client (excluding the "agent"
129 * capability)
130 */
131 @NonNull
132 Set<String> getClientCapabilities() {
133 return clientCapabilities;
134 }
135
136 /**
137 * The value in a "deepen-since" line in the request, indicating the
138 * timestamp where to stop fetching/cloning.
139 *
140 * @return timestamp in seconds since the epoch, where to stop the shallow
141 * fetch/clone. Defaults to 0 if not set in the request.
142 */
143 int getDeepenSince() {
144 return deepenSince;
145 }
146
147 /**
148 * @return refs received in "deepen-not" lines.
149 */
150 @NonNull
151 List<String> getDeepenNots() {
152 return deepenNots;
153 }
154
155 /**
156 * @return string identifying the agent (as sent in the request body by the
157 * client)
158 */
159 @Nullable
160 String getAgent() {
161 return agent;
162 }
163 }