View Javadoc
1   /*
2    * Copyright (C) 2018, 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.Collection;
15  import java.util.Collections;
16  import java.util.HashSet;
17  import java.util.Set;
18  
19  import org.eclipse.jgit.annotations.NonNull;
20  import org.eclipse.jgit.annotations.Nullable;
21  import org.eclipse.jgit.lib.ObjectId;
22  
23  /**
24   * Fetch request in the V0/V1 protocol.
25   */
26  final class FetchV0Request extends FetchRequest {
27  
28  	FetchV0Request(@NonNull Set<ObjectId> wantIds, int depth,
29  			@NonNull Set<ObjectId> clientShallowCommits,
30  			@NonNull FilterSpec filterSpec,
31  			@NonNull Set<String> clientCapabilities, @Nullable String agent) {
32  		super(wantIds, depth, clientShallowCommits, filterSpec,
33  				clientCapabilities, 0, Collections.emptyList(),	agent);
34  	}
35  
36  	static final class Builder {
37  
38  		int depth;
39  
40  		final Set<ObjectId> wantIds = new HashSet<>();
41  
42  		final Set<ObjectId> clientShallowCommits = new HashSet<>();
43  
44  		FilterSpec filterSpec = FilterSpec.NO_FILTER;
45  
46  		final Set<String> clientCaps = new HashSet<>();
47  
48  		String agent;
49  
50  		/**
51  		 * @param objectId
52  		 *            object id received in a "want" line
53  		 * @return this builder
54  		 */
55  		Builder addWantId(ObjectId objectId) {
56  			wantIds.add(objectId);
57  			return this;
58  		}
59  
60  		/**
61  		 * @param d
62  		 *            depth set in a "deepen" line
63  		 * @return this builder
64  		 */
65  		Builder setDepth(int d) {
66  			depth = d;
67  			return this;
68  		}
69  
70  		/**
71  		 * @param shallowOid
72  		 *            object id received in a "shallow" line
73  		 * @return this builder
74  		 */
75  		Builder addClientShallowCommit(ObjectId shallowOid) {
76  			clientShallowCommits.add(shallowOid);
77  			return this;
78  		}
79  
80  		/**
81  		 * @param clientCapabilities
82  		 *            client capabilities sent by the client in the first want
83  		 *            line of the request
84  		 * @return this builder
85  		 */
86  		Builder addClientCapabilities(Collection<String> clientCapabilities) {
87  			clientCaps.addAll(clientCapabilities);
88  			return this;
89  		}
90  
91  		/**
92  		 * @param clientAgent
93  		 *            agent line sent by the client in the request body
94  		 * @return this builder
95  		 */
96  		Builder setAgent(String clientAgent) {
97  			agent = clientAgent;
98  			return this;
99  		}
100 
101 		/**
102 		 * @param filter
103 		 *            the filter set in a filter line
104 		 * @return this builder
105 		 */
106 		Builder setFilterSpec(@NonNull FilterSpec filter) {
107 			filterSpec = requireNonNull(filter);
108 			return this;
109 		}
110 
111 		FetchV0Request build() {
112 			return new FetchV0Request(wantIds, depth, clientShallowCommits,
113 					filterSpec, clientCaps, agent);
114 		}
115 
116 	}
117 }