1 #ifndef TRANSPORT_H
2 #define TRANSPORT_H
3 
4 #include "cache.h"
5 #include "run-command.h"
6 #include "remote.h"
7 #include "list-objects-filter-options.h"
8 #include "string-list.h"
9 
10 struct git_transport_options {
11 	unsigned thin : 1;
12 	unsigned keep : 1;
13 	unsigned followtags : 1;
14 	unsigned check_self_contained_and_connected : 1;
15 	unsigned self_contained_and_connected : 1;
16 	unsigned update_shallow : 1;
17 	unsigned reject_shallow : 1;
18 	unsigned deepen_relative : 1;
19 
20 	/* see documentation of corresponding flag in fetch-pack.h */
21 	unsigned from_promisor : 1;
22 
23 	/*
24 	 * If this transport supports connect or stateless-connect,
25 	 * the corresponding field in struct fetch_pack_args is copied
26 	 * here after fetching.
27 	 *
28 	 * See the definition of connectivity_checked in struct
29 	 * fetch_pack_args for more information.
30 	 */
31 	unsigned connectivity_checked:1;
32 
33 	int depth;
34 	const char *deepen_since;
35 	const struct string_list *deepen_not;
36 	const char *uploadpack;
37 	const char *receivepack;
38 	struct push_cas_option *cas;
39 	struct list_objects_filter_options filter_options;
40 
41 	/*
42 	 * This is only used during fetch. See the documentation of
43 	 * negotiation_tips in struct fetch_pack_args.
44 	 *
45 	 * This field is only supported by transports that support connect or
46 	 * stateless_connect. Set this field directly instead of using
47 	 * transport_set_option().
48 	 */
49 	struct oid_array *negotiation_tips;
50 
51 	/*
52 	 * If allocated, whenever transport_fetch_refs() is called, add known
53 	 * common commits to this oidset instead of fetching any packfiles.
54 	 */
55 	struct oidset *acked_commits;
56 };
57 
58 enum transport_family {
59 	TRANSPORT_FAMILY_ALL = 0,
60 	TRANSPORT_FAMILY_IPV4,
61 	TRANSPORT_FAMILY_IPV6
62 };
63 
64 struct transport {
65 	const struct transport_vtable *vtable;
66 
67 	struct remote *remote;
68 	const char *url;
69 	void *data;
70 	const struct ref *remote_refs;
71 
72 	/**
73 	 * Indicates whether we already called get_refs_list(); set by
74 	 * transport.c::transport_get_remote_refs().
75 	 */
76 	unsigned got_remote_refs : 1;
77 
78 	/*
79 	 * Transports that call take-over destroys the data specific to
80 	 * the transport type while doing so, and cannot be reused.
81 	 */
82 	unsigned cannot_reuse : 1;
83 
84 	/*
85 	 * A hint from caller that it will be performing a clone, not
86 	 * normal fetch. IOW the repository is guaranteed empty.
87 	 */
88 	unsigned cloning : 1;
89 
90 	/*
91 	 * Indicates that the transport is connected via a half-duplex
92 	 * connection and should operate in stateless-rpc mode.
93 	 */
94 	unsigned stateless_rpc : 1;
95 
96 	/*
97 	 * These strings will be passed to the {pre, post}-receive hook,
98 	 * on the remote side, if both sides support the push options capability.
99 	 */
100 	const struct string_list *push_options;
101 
102 	/*
103 	 * These strings will be passed to the remote side on each command
104 	 * request, if both sides support the server-option capability.
105 	 */
106 	const struct string_list *server_options;
107 
108 	struct string_list pack_lockfiles;
109 
110 	signed verbose : 3;
111 	/**
112 	 * Transports should not set this directly, and should use this
113 	 * value without having to check isatty(2), -q/--quiet
114 	 * (transport->verbose < 0), etc. - checking has already been done
115 	 * in transport_set_verbosity().
116 	 **/
117 	unsigned progress : 1;
118 	/*
119 	 * If transport is at least potentially smart, this points to
120 	 * git_transport_options structure to use in case transport
121 	 * actually turns out to be smart.
122 	 */
123 	struct git_transport_options *smart_options;
124 
125 	enum transport_family family;
126 
127 	const struct git_hash_algo *hash_algo;
128 };
129 
130 #define TRANSPORT_PUSH_ALL			(1<<0)
131 #define TRANSPORT_PUSH_FORCE			(1<<1)
132 #define TRANSPORT_PUSH_DRY_RUN			(1<<2)
133 #define TRANSPORT_PUSH_MIRROR			(1<<3)
134 #define TRANSPORT_PUSH_PORCELAIN		(1<<4)
135 #define TRANSPORT_PUSH_SET_UPSTREAM		(1<<5)
136 #define TRANSPORT_RECURSE_SUBMODULES_CHECK	(1<<6)
137 #define TRANSPORT_PUSH_PRUNE			(1<<7)
138 #define TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND	(1<<8)
139 #define TRANSPORT_PUSH_NO_HOOK			(1<<9)
140 #define TRANSPORT_PUSH_FOLLOW_TAGS		(1<<10)
141 #define TRANSPORT_PUSH_CERT_ALWAYS		(1<<11)
142 #define TRANSPORT_PUSH_CERT_IF_ASKED		(1<<12)
143 #define TRANSPORT_PUSH_ATOMIC			(1<<13)
144 #define TRANSPORT_PUSH_OPTIONS			(1<<14)
145 #define TRANSPORT_RECURSE_SUBMODULES_ONLY	(1<<15)
146 #define TRANSPORT_PUSH_FORCE_IF_INCLUDES	(1<<16)
147 
148 int transport_summary_width(const struct ref *refs);
149 
150 /* Returns a transport suitable for the url */
151 struct transport *transport_get(struct remote *, const char *);
152 
153 /*
154  * Check whether a transport is allowed by the environment.
155  *
156  * Type should generally be the URL scheme, as described in
157  * Documentation/git.txt
158  *
159  * from_user specifies if the transport was given by the user.  If unknown pass
160  * a -1 to read from the environment to determine if the transport was given by
161  * the user.
162  *
163  */
164 int is_transport_allowed(const char *type, int from_user);
165 
166 /*
167  * Check whether a transport is allowed by the environment,
168  * and die otherwise.
169  */
170 void transport_check_allowed(const char *type);
171 
172 /* Transport options which apply to git:// and scp-style URLs */
173 
174 /* The program to use on the remote side to send a pack */
175 #define TRANS_OPT_UPLOADPACK "uploadpack"
176 
177 /* The program to use on the remote side to receive a pack */
178 #define TRANS_OPT_RECEIVEPACK "receivepack"
179 
180 /* Transfer the data as a thin pack if not null */
181 #define TRANS_OPT_THIN "thin"
182 
183 /* Check the current value of the remote ref */
184 #define TRANS_OPT_CAS "cas"
185 
186 /* Keep the pack that was transferred if not null */
187 #define TRANS_OPT_KEEP "keep"
188 
189 /* Limit the depth of the fetch if not null */
190 #define TRANS_OPT_DEPTH "depth"
191 
192 /* Limit the depth of the fetch based on time if not null */
193 #define TRANS_OPT_DEEPEN_SINCE "deepen-since"
194 
195 /* Limit the depth of the fetch based on revs if not null */
196 #define TRANS_OPT_DEEPEN_NOT "deepen-not"
197 
198 /* Limit the deepen of the fetch if not null */
199 #define TRANS_OPT_DEEPEN_RELATIVE "deepen-relative"
200 
201 /* Aggressively fetch annotated tags if possible */
202 #define TRANS_OPT_FOLLOWTAGS "followtags"
203 
204 /* Reject shallow repo transport */
205 #define TRANS_OPT_REJECT_SHALLOW "rejectshallow"
206 
207 /* Accept refs that may update .git/shallow without --depth */
208 #define TRANS_OPT_UPDATE_SHALLOW "updateshallow"
209 
210 /* Send push certificates */
211 #define TRANS_OPT_PUSH_CERT "pushcert"
212 
213 /* Indicate that these objects are being fetched by a promisor */
214 #define TRANS_OPT_FROM_PROMISOR "from-promisor"
215 
216 /* Filter objects for partial clone and fetch */
217 #define TRANS_OPT_LIST_OBJECTS_FILTER "filter"
218 
219 /* Request atomic (all-or-nothing) updates when pushing */
220 #define TRANS_OPT_ATOMIC "atomic"
221 
222 /* Require remote changes to be integrated locally. */
223 #define TRANS_OPT_FORCE_IF_INCLUDES "force-if-includes"
224 
225 /**
226  * Returns 0 if the option was used, non-zero otherwise. Prints a
227  * message to stderr if the option is not used.
228  **/
229 int transport_set_option(struct transport *transport, const char *name,
230 			 const char *value);
231 void transport_set_verbosity(struct transport *transport, int verbosity,
232 	int force_progress);
233 
234 #define REJECT_NON_FF_HEAD      0x01
235 #define REJECT_NON_FF_OTHER     0x02
236 #define REJECT_ALREADY_EXISTS   0x04
237 #define REJECT_FETCH_FIRST      0x08
238 #define REJECT_NEEDS_FORCE      0x10
239 #define REJECT_REF_NEEDS_UPDATE 0x20
240 
241 int transport_push(struct repository *repo,
242 		   struct transport *connection,
243 		   struct refspec *rs, int flags,
244 		   unsigned int * reject_reasons);
245 
246 struct transport_ls_refs_options {
247 	/*
248 	 * Optionally, a list of ref prefixes can be provided which can be sent
249 	 * to the server (when communicating using protocol v2) to enable it to
250 	 * limit the ref advertisement.  Since ref filtering is done on the
251 	 * server's end (and only when using protocol v2),
252 	 * transport_get_remote_refs() could return refs which don't match the
253 	 * provided ref_prefixes.
254 	 */
255 	struct strvec ref_prefixes;
256 
257 	/*
258 	 * If unborn_head_target is not NULL, and the remote reports HEAD as
259 	 * pointing to an unborn branch, transport_get_remote_refs() stores the
260 	 * unborn branch in unborn_head_target. It should be freed by the
261 	 * caller.
262 	 */
263 	char *unborn_head_target;
264 };
265 #define TRANSPORT_LS_REFS_OPTIONS_INIT { \
266 	.ref_prefixes = STRVEC_INIT, \
267 }
268 
269 /*
270  * Retrieve refs from a remote.
271  */
272 const struct ref *transport_get_remote_refs(struct transport *transport,
273 					    struct transport_ls_refs_options *transport_options);
274 
275 /*
276  * Fetch the hash algorithm used by a remote.
277  *
278  * This can only be called after fetching the remote refs.
279  */
280 const struct git_hash_algo *transport_get_hash_algo(struct transport *transport);
281 int transport_fetch_refs(struct transport *transport, struct ref *refs);
282 void transport_unlock_pack(struct transport *transport);
283 int transport_disconnect(struct transport *transport);
284 char *transport_anonymize_url(const char *url);
285 void transport_take_over(struct transport *transport,
286 			 struct child_process *child);
287 
288 int transport_connect(struct transport *transport, const char *name,
289 		      const char *exec, int fd[2]);
290 
291 /* Transport methods defined outside transport.c */
292 int transport_helper_init(struct transport *transport, const char *name);
293 int bidirectional_transfer_loop(int input, int output);
294 
295 /* common methods used by transport.c and builtin/send-pack.c */
296 void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int verbose);
297 
298 int transport_refs_pushed(struct ref *ref);
299 
300 void transport_print_push_status(const char *dest, struct ref *refs,
301 		  int verbose, int porcelain, unsigned int *reject_reasons);
302 
303 /* common method used by transport-helper.c and send-pack.c */
304 void reject_atomic_push(struct ref *refs, int mirror_mode);
305 
306 #endif
307