View Javadoc
1   /*
2    * Copyright (C) 2018, Google LLC.
3    * and other copyright owners as documented in the project's IP log.
4    *
5    * This program and the accompanying materials are made available
6    * under the terms of the Eclipse Distribution License v1.0 which
7    * accompanies this distribution, is reproduced below, and is
8    * available at http://www.eclipse.org/org/documents/edl-v10.php
9    *
10   * All rights reserved.
11   *
12   * Redistribution and use in source and binary forms, with or
13   * without modification, are permitted provided that the following
14   * conditions are met:
15   *
16   * - Redistributions of source code must retain the above copyright
17   *   notice, this list of conditions and the following disclaimer.
18   *
19   * - Redistributions in binary form must reproduce the above
20   *   copyright notice, this list of conditions and the following
21   *   disclaimer in the documentation and/or other materials provided
22   *   with the distribution.
23   *
24   * - Neither the name of the Eclipse Foundation, Inc. nor the
25   *   names of its contributors may be used to endorse or promote
26   *   products derived from this software without specific prior
27   *   written permission.
28   *
29   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
30   * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
31   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
32   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
38   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42   */
43  package org.eclipse.jgit.transport;
44  
45  import static java.util.Objects.requireNonNull;
46  
47  import java.util.List;
48  import java.util.Set;
49  
50  import org.eclipse.jgit.annotations.NonNull;
51  import org.eclipse.jgit.annotations.Nullable;
52  import org.eclipse.jgit.lib.ObjectId;
53  
54  /**
55   * Common fields between v0/v1/v2 fetch requests.
56   */
57  abstract class FetchRequest {
58  
59  	final Set<ObjectId> wantIds;
60  
61  	final int depth;
62  
63  	final Set<ObjectId> clientShallowCommits;
64  
65  	final long filterBlobLimit;
66  
67  	final Set<String> clientCapabilities;
68  
69  	final int deepenSince;
70  
71  	final List<String> deepenNotRefs;
72  
73  	@Nullable
74  	final String agent;
75  
76  	/**
77  	 * Initialize the common fields of a fetch request.
78  	 *
79  	 * @param wantIds
80  	 *            list of want ids
81  	 * @param depth
82  	 *            how deep to go in the tree
83  	 * @param clientShallowCommits
84  	 *            commits the client has without history
85  	 * @param filterBlobLimit
86  	 *            to exclude blobs on certain conditions
87  	 * @param clientCapabilities
88  	 *            capabilities sent in the request
89  	 * @param deepenNotRefs
90  	 *            Requests that the shallow clone/fetch should be cut at these
91  	 *            specific revisions instead of a depth.
92  	 * @param deepenSince
93  	 *            Requests that the shallow clone/fetch should be cut at a
94  	 *            specific time, instead of depth
95  	 * @param agent
96  	 *            agent as reported by the client in the request body
97  	 */
98  	FetchRequest(@NonNull Set<ObjectId> wantIds, int depth,
99  			@NonNull Set<ObjectId> clientShallowCommits, long filterBlobLimit,
100 			@NonNull Set<String> clientCapabilities, int deepenSince,
101 			@NonNull List<String> deepenNotRefs, @Nullable String agent) {
102 		this.wantIds = requireNonNull(wantIds);
103 		this.depth = depth;
104 		this.clientShallowCommits = requireNonNull(clientShallowCommits);
105 		this.filterBlobLimit = filterBlobLimit;
106 		this.clientCapabilities = requireNonNull(clientCapabilities);
107 		this.deepenSince = deepenSince;
108 		this.deepenNotRefs = requireNonNull(deepenNotRefs);
109 		this.agent = agent;
110 	}
111 
112 	/**
113 	 * @return object ids in the "want" (and "want-ref") lines of the request
114 	 */
115 	@NonNull
116 	Set<ObjectId> getWantIds() {
117 		return wantIds;
118 	}
119 
120 	/**
121 	 * @return the depth set in a "deepen" line. 0 by default.
122 	 */
123 	int getDepth() {
124 		return depth;
125 	}
126 
127 	/**
128 	 * Shallow commits the client already has.
129 	 *
130 	 * These are sent by the client in "shallow" request lines.
131 	 *
132 	 * @return set of commits the client has declared as shallow.
133 	 */
134 	@NonNull
135 	Set<ObjectId> getClientShallowCommits() {
136 		return clientShallowCommits;
137 	}
138 
139 	/**
140 	 * @return the blob limit set in a "filter" line (-1 if not set)
141 	 */
142 	long getFilterBlobLimit() {
143 		return filterBlobLimit;
144 	}
145 
146 	/**
147 	 * Capabilities that the client wants enabled from the server.
148 	 *
149 	 * Capabilities are options that tune the expected response from the server,
150 	 * like "thin-pack", "no-progress" or "ofs-delta". This list should be a
151 	 * subset of the capabilities announced by the server in its first response.
152 	 *
153 	 * These options are listed and well-defined in the git protocol
154 	 * specification.
155 	 *
156 	 * The agent capability is not included in this set. It can be retrieved via
157 	 * {@link #getAgent()}.
158 	 *
159 	 * @return capabilities sent by the client (excluding the "agent"
160 	 *         capability)
161 	 */
162 	@NonNull
163 	Set<String> getClientCapabilities() {
164 		return clientCapabilities;
165 	}
166 
167 	/**
168 	 * The value in a "deepen-since" line in the request, indicating the
169 	 * timestamp where to stop fetching/cloning.
170 	 *
171 	 * @return timestamp in seconds since the epoch, where to stop the shallow
172 	 *         fetch/clone. Defaults to 0 if not set in the request.
173 	 */
174 	int getDeepenSince() {
175 		return deepenSince;
176 	}
177 
178 	/**
179 	 * @return refs received in "deepen-not" lines.
180 	 */
181 	@NonNull
182 	List<String> getDeepenNotRefs() {
183 		return deepenNotRefs;
184 	}
185 
186 	/**
187 	 * @return string identifying the agent (as sent in the request body by the
188 	 *         client)
189 	 */
190 	@Nullable
191 	String getAgent() {
192 		return agent;
193 	}
194 }