View Javadoc
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  	@Nullable
44  	final String clientSID;
45  
46  	/**
47  	 * Initialize the common fields of a fetch request.
48  	 *
49  	 * @param wantIds
50  	 *            list of want ids
51  	 * @param depth
52  	 *            how deep to go in the tree
53  	 * @param clientShallowCommits
54  	 *            commits the client has without history
55  	 * @param filterSpec
56  	 *            the filter spec
57  	 * @param clientCapabilities
58  	 *            capabilities sent in the request
59  	 * @param deepenNots
60  	 *            Requests that the shallow clone/fetch should be cut at these
61  	 *            specific revisions instead of a depth.
62  	 * @param deepenSince
63  	 *            Requests that the shallow clone/fetch should be cut at a
64  	 *            specific time, instead of depth
65  	 * @param agent
66  	 *            agent as reported by the client in the request body
67  	 * @param clientSID
68  	 *            agent as reported by the client in the request body
69  	 */
70  	FetchRequest(@NonNull Set<ObjectId> wantIds, int depth,
71  			@NonNull Set<ObjectId> clientShallowCommits,
72  			@NonNull FilterSpec filterSpec,
73  			@NonNull Set<String> clientCapabilities, int deepenSince,
74  			@NonNull List<String> deepenNots, @Nullable String agent,
75  			@Nullable String clientSID) {
76  		this.wantIds = requireNonNull(wantIds);
77  		this.depth = depth;
78  		this.clientShallowCommits = requireNonNull(clientShallowCommits);
79  		this.filterSpec = requireNonNull(filterSpec);
80  		this.clientCapabilities = requireNonNull(clientCapabilities);
81  		this.deepenSince = deepenSince;
82  		this.deepenNots = requireNonNull(deepenNots);
83  		this.agent = agent;
84  		this.clientSID = clientSID;
85  	}
86  
87  	/**
88  	 * @return object ids in the "want" (and "want-ref") lines of the request
89  	 */
90  	@NonNull
91  	Set<ObjectId> getWantIds() {
92  		return wantIds;
93  	}
94  
95  	/**
96  	 * @return the depth set in a "deepen" line. 0 by default.
97  	 */
98  	int getDepth() {
99  		return depth;
100 	}
101 
102 	/**
103 	 * Shallow commits the client already has.
104 	 *
105 	 * These are sent by the client in "shallow" request lines.
106 	 *
107 	 * @return set of commits the client has declared as shallow.
108 	 */
109 	@NonNull
110 	Set<ObjectId> getClientShallowCommits() {
111 		return clientShallowCommits;
112 	}
113 
114 	/**
115 	 * @return the filter spec given in a "filter" line
116 	 */
117 	@NonNull
118 	FilterSpec getFilterSpec() {
119 		return filterSpec;
120 	}
121 
122 	/**
123 	 * Capabilities that the client wants enabled from the server.
124 	 *
125 	 * Capabilities are options that tune the expected response from the server,
126 	 * like "thin-pack", "no-progress" or "ofs-delta". This list should be a
127 	 * subset of the capabilities announced by the server in its first response.
128 	 *
129 	 * These options are listed and well-defined in the git protocol
130 	 * specification.
131 	 *
132 	 * The agent capability is not included in this set. It can be retrieved via
133 	 * {@link #getAgent()}.
134 	 *
135 	 * @return capabilities sent by the client (excluding the "agent"
136 	 *         capability)
137 	 */
138 	@NonNull
139 	Set<String> getClientCapabilities() {
140 		return clientCapabilities;
141 	}
142 
143 	/**
144 	 * The value in a "deepen-since" line in the request, indicating the
145 	 * timestamp where to stop fetching/cloning.
146 	 *
147 	 * @return timestamp in seconds since the epoch, where to stop the shallow
148 	 *         fetch/clone. Defaults to 0 if not set in the request.
149 	 */
150 	int getDeepenSince() {
151 		return deepenSince;
152 	}
153 
154 	/**
155 	 * @return refs received in "deepen-not" lines.
156 	 */
157 	@NonNull
158 	List<String> getDeepenNots() {
159 		return deepenNots;
160 	}
161 
162 	/**
163 	 * @return string identifying the agent (as sent in the request body by the
164 	 *         client)
165 	 */
166 	@Nullable
167 	String getAgent() {
168 		return agent;
169 	}
170 
171 	/**
172 	 * @return string identifying the client session ID (as sent in the request body by the
173 	 *         client)
174 	 */
175 	@Nullable
176 	String getClientSID() {
177 		return clientSID;
178 	}
179 }