]> git.ipfire.org Git - thirdparty/git.git/blame - remote.h
The sixth batch
[thirdparty/git.git] / remote.h
CommitLineData
5751f490
DB
1#ifndef REMOTE_H
2#define REMOTE_H
3
8a676bdc 4#include "hash.h"
d0da003d 5#include "hashmap.h"
6bdb304b 6#include "refspec.h"
72da5cfb 7#include "string-list.h"
8e804415 8#include "strvec.h"
28f5d176 9
c4d9c793 10struct option;
39835409
JT
11struct transport_ls_refs_options;
12
d27eb356
HW
13/**
14 * The API gives access to the configuration related to remotes. It handles
15 * all three configuration mechanisms historically and currently used by Git,
16 * and presents the information in a uniform fashion. Note that the code also
17 * handles plain URLs without any configuration, giving them just the default
18 * information.
19 */
20
89cf4c70 21enum {
674468b3 22 REMOTE_UNCONFIGURED = 0,
89cf4c70 23 REMOTE_CONFIG,
8ccc75c2 24#ifndef WITH_BREAKING_CHANGES
89cf4c70
MV
25 REMOTE_REMOTES,
26 REMOTE_BRANCHES
8ccc75c2 27#endif /* WITH_BREAKING_CHANGES */
89cf4c70
MV
28};
29
fd3cb050
GC
30struct rewrite {
31 const char *base;
32 size_t baselen;
33 struct counted_string *instead_of;
34 int instead_of_nr;
35 int instead_of_alloc;
36};
37
38struct rewrites {
39 struct rewrite **rewrite;
40 int rewrite_alloc;
41 int rewrite_nr;
42};
43
44struct remote_state {
45 struct remote **remotes;
46 int remotes_alloc;
47 int remotes_nr;
48 struct hashmap remotes_hash;
49
4a2dcb1a 50 struct hashmap branches_hash;
fd3cb050
GC
51
52 struct branch *current_branch;
1b261c20 53 char *pushremote_name;
fd3cb050
GC
54
55 struct rewrites rewrites;
56 struct rewrites rewrites_push;
085b98f6
GC
57
58 int initialized;
fd3cb050
GC
59};
60
61void remote_state_clear(struct remote_state *remote_state);
62struct remote_state *remote_state_new(void);
63
b7f7d165
BF
64 enum follow_remote_head_settings {
65 FOLLOW_REMOTE_NEVER = -1,
66 FOLLOW_REMOTE_CREATE = 0,
67 FOLLOW_REMOTE_WARN = 1,
68 FOLLOW_REMOTE_ALWAYS = 2,
69 };
70
5751f490 71struct remote {
e2b5038d 72 struct hashmap_entry ent;
d0da003d 73
d27eb356 74 /* The user's nickname for the remote */
5751f490 75 const char *name;
d27eb356 76
e459b073 77 int origin, configured_in_repo;
5751f490 78
1b261c20 79 char *foreign_vcs;
c578f51d 80
d27eb356 81 /* An array of all of the url_nr URLs configured for the remote */
8e804415 82 struct strvec url;
d27eb356 83 /* An array of all of the pushurl_nr push URLs configured for the remote */
8e804415 84 struct strvec pushurl;
20346234 85
6bdb304b 86 struct refspec push;
5751f490 87
e5349abf 88 struct refspec fetch;
5d46c9d4 89
d71ab174 90 /*
d27eb356
HW
91 * The setting for whether to fetch tags (as a separate rule from the
92 * configured refspecs);
d71ab174
DB
93 * -1 to never fetch tags
94 * 0 to auto-follow tags on heuristic (default)
95 * 1 to always auto-follow tags
96 * 2 to always fetch tags
97 */
98 int fetch_tags;
d27eb356 99
211c8968 100 int skip_default_update;
84bb2dfd 101 int mirror;
737c5a9c 102 int prune;
97716d21 103 int prune_tags;
d71ab174 104
d27eb356
HW
105 /**
106 * The configured helper programs to run on the remote side, for
107 * Git-native protocols.
108 */
5751f490 109 const char *receivepack;
0012ba21 110 const char *uploadpack;
14c98218 111
d27eb356 112 /* The proxy to use for curl (http, https, ftp, etc.) URLs. */
14c98218 113 char *http_proxy;
d27eb356
HW
114
115 /* The method used for authenticating against `http_proxy`. */
ef976395 116 char *http_proxy_authmethod;
72da5cfb
XX
117
118 struct string_list server_options;
b7f7d165
BF
119
120 enum follow_remote_head_settings follow_remote_head;
9e2b7005 121 const char *no_warn_branch;
5751f490
DB
122};
123
d27eb356
HW
124/**
125 * struct remotes can be found by name with remote_get().
126 * remote_get(NULL) will return the default remote, given the current branch
127 * and configuration.
128 */
5751f490 129struct remote *remote_get(const char *name);
3c8f60c6 130struct remote *remote_get_early(const char *name);
d27eb356 131
f24f715e 132struct remote *pushremote_get(const char *name);
e459b073 133int remote_is_configured(struct remote *remote, int in_repo);
5751f490 134
b42f6927 135typedef int each_remote_fn(struct remote *remote, void *priv);
d27eb356
HW
136
137/* iterate through struct remotes */
b42f6927
JS
138int for_each_remote(each_remote_fn fn, void *priv);
139
28b91f8a 140int remote_has_url(struct remote *remote, const char *url);
b68118d2 141struct strvec *push_url_of_remote(struct remote *remote);
5d46c9d4 142
15d3af5e 143struct ref_push_report {
a6c30623 144 char *ref_name;
15d3af5e
JX
145 struct object_id *old_oid;
146 struct object_id *new_oid;
147 unsigned int forced_update:1;
148 struct ref_push_report *next;
149};
150
a6c30623
PS
151void ref_push_report_free(struct ref_push_report *);
152
47a59185
JH
153struct ref {
154 struct ref *next;
f4e54d02 155 struct object_id old_oid;
156 struct object_id new_oid;
157 struct object_id old_oid_expect; /* used by expect-old */
47a59185 158 char *symref;
99a1f9ae 159 char *tracking_ref;
47a59185
JH
160 unsigned int
161 force:1,
162 forced_update:1,
91048a95 163 expect_old_sha1:1,
73302051 164 exact_oid:1,
99a1f9ae
SK
165 deletion:1,
166 /* Need to check if local reflog reaches the remote tip. */
167 check_reachable:1,
168 /*
169 * Store the result of the check enabled by "check_reachable";
170 * implies the local reflog does not reach the remote tip.
171 */
172 unreachable:1;
d56583de
MM
173
174 enum {
175 REF_NOT_MATCHED = 0, /* initial value */
176 REF_MATCHED,
177 REF_UNADVERTISED_NOT_ALLOWED
178 } match_status;
47a59185
JH
179
180 /*
181 * Order is important here, as we write to FETCH_HEAD
182 * in numeric order. And the default NOT_FOR_MERGE
183 * should be 0, so that xcalloc'd structures get it
184 * by default.
185 */
58a646a3 186 enum fetch_head_status {
47a59185
JH
187 FETCH_HEAD_MERGE = -1,
188 FETCH_HEAD_NOT_FOR_MERGE = 0,
189 FETCH_HEAD_IGNORE = 1
190 } fetch_head_status;
191
192 enum {
193 REF_STATUS_NONE = 0,
194 REF_STATUS_OK,
195 REF_STATUS_REJECT_NONFASTFORWARD,
196 REF_STATUS_REJECT_ALREADY_EXISTS,
197 REF_STATUS_REJECT_NODELETE,
198 REF_STATUS_REJECT_FETCH_FIRST,
199 REF_STATUS_REJECT_NEEDS_FORCE,
631b5ef2 200 REF_STATUS_REJECT_STALE,
4820a33b 201 REF_STATUS_REJECT_SHALLOW,
99a1f9ae 202 REF_STATUS_REJECT_REMOTE_UPDATED,
47a59185
JH
203 REF_STATUS_UPTODATE,
204 REF_STATUS_REMOTE_REJECT,
4ff17f10
RS
205 REF_STATUS_EXPECTING_REPORT,
206 REF_STATUS_ATOMIC_PUSH_FAILED
47a59185
JH
207 } status;
208 char *remote_status;
63518a57 209 struct ref_push_report *report;
47a59185
JH
210 struct ref *peer_ref; /* when renaming */
211 char name[FLEX_ARRAY]; /* more */
212};
213
214#define REF_NORMAL (1u << 0)
a096e70c 215#define REF_BRANCHES (1u << 1)
47a59185
JH
216#define REF_TAGS (1u << 2)
217
55454427 218struct ref *find_ref_by_name(const struct ref *list, const char *name);
47a59185 219
59c69c0c 220struct ref *alloc_ref(const char *name);
59a57757 221struct ref *copy_ref(const struct ref *ref);
4577370e 222struct ref *copy_ref_list(const struct ref *ref);
55454427 223int count_refspec_match(const char *, struct ref *refs, struct ref **matched_ref);
7a52a8c7
TC
224/*
225 * Put a ref in the tail and prepare tail for adding another one.
226 * *tail is the pointer to the tail of the list of refs.
227 */
228void tail_link_ref(struct ref *ref, struct ref ***tail);
4577370e
DB
229
230int check_ref_type(const struct ref *ref, int flags);
231
dfd255dd 232/*
1027186f
JK
233 * Free a single ref and its peer, or an entire list of refs and their peers,
234 * respectively.
dfd255dd 235 */
1027186f 236void free_one_ref(struct ref *ref);
dfd255dd
DB
237void free_refs(struct ref *ref);
238
910650d2 239struct oid_array;
ad6ac124 240struct packet_reader;
873cd28a 241struct strvec;
ff473221 242struct string_list;
55454427 243struct ref **get_remote_heads(struct packet_reader *reader,
ad6dad09
DL
244 struct ref **list, unsigned int flags,
245 struct oid_array *extra_have,
246 struct oid_array *shallow_points);
47a59185 247
e52449b6 248/* Used for protocol v2 in order to retrieve refs from a remote */
55454427 249struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,
ad6dad09 250 struct ref **list, int for_push,
39835409 251 struct transport_ls_refs_options *transport_options,
b0df0c16
DL
252 const struct string_list *server_options,
253 int stateless_rpc);
47a59185 254
0cfde740
ÆAB
255/* Used for protocol v2 in order to retrieve refs from a remote */
256struct bundle_list;
257int get_remote_bundle_uri(int fd_out, struct packet_reader *reader,
258 struct bundle_list *bundles, int stateless_rpc);
259
be885d96
DB
260int resolve_remote_symref(struct ref *ref, struct ref *list);
261
2467a4fa 262/*
b9afe665
MH
263 * Remove and free all but the first of any entries in the input list
264 * that map the same remote reference to the same local reference. If
265 * there are two entries that map different remote references to the
266 * same local reference, emit an error message and die. Return a
267 * pointer to the head of the resulting list.
2467a4fa 268 */
b9afe665 269struct ref *ref_remove_duplicates(struct ref *ref_map);
2467a4fa 270
afb1aed4 271int check_push_refs(struct ref *src, struct refspec *rs);
29753cdd 272int match_push_refs(struct ref *src, struct ref **dst,
5c7ec846 273 struct refspec *rs, int flags);
20e8b465
TRC
274void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
275 int force_update);
6b62816c 276
d71ab174
DB
277/*
278 * Given a list of the remote refs and the specification of things to
279 * fetch, makes a (separate) list of the refs to fetch and the local
c0192df6
JK
280 * refs to store into. Note that negative refspecs are ignored here, and
281 * should be handled separately.
d71ab174
DB
282 *
283 * *tail is the pointer to the tail pointer of the list of results
284 * beforehand, and will be set to the tail pointer of the list of
285 * results afterward.
9ad7c5ae
JH
286 *
287 * missing_ok is usually false, but when we are adding branch.$name.merge
288 * it is Ok if the branch is not at the remote anymore.
d71ab174 289 */
0ad4a5ff 290int get_fetch_map(const struct ref *remote_refs, const struct refspec_item *refspec,
9ad7c5ae 291 struct ref ***tail, int missing_ok);
d71ab174 292
4577370e 293struct ref *get_remote_ref(const struct ref *remote_refs, const char *name);
d71ab174 294
5d46c9d4
DB
295/*
296 * For the given remote, reads the refspec's src and sets the other fields.
297 */
0ad4a5ff 298int remote_find_tracking(struct remote *remote, struct refspec_item *refspec);
5d46c9d4 299
d27eb356
HW
300/**
301 * struct branch holds the configuration for a branch. It can be looked up with
302 * branch_get(name) for "refs/heads/{name}", or with branch_get(NULL) for HEAD.
303 */
cf818348 304struct branch {
4a2dcb1a 305 struct hashmap_entry ent;
d27eb356
HW
306
307 /* The short name of the branch. */
cf818348 308 const char *name;
d27eb356
HW
309
310 /* The full path for the branch ref. */
cf818348
DB
311 const char *refname;
312
d27eb356 313 /* The name of the remote listed in the configuration. */
1b261c20 314 char *remote_name;
d27eb356 315
1b261c20 316 char *pushremote_name;
cf818348 317
d27eb356 318 /* An array of the "merge" lines in the configuration. */
cf818348 319 const char **merge_name;
d27eb356
HW
320
321 /**
322 * An array of the struct refspecs used for the merge lines. That is,
323 * merge[i]->dst is a local tracking ref which should be merged into this
324 * branch by default.
325 */
0ad4a5ff 326 struct refspec_item **merge;
d27eb356
HW
327
328 /* The number of merge configurations */
cf818348 329 int merge_nr;
d27eb356 330
2d31347b 331 int merge_alloc;
e291c75a
JK
332
333 const char *push_tracking_ref;
cf818348
DB
334};
335
336struct branch *branch_get(const char *name);
f052154d 337const char *remote_for_branch(struct branch *branch, int *explicit);
da66b274 338const char *pushremote_for_branch(struct branch *branch, int *explicit);
f046127b 339char *remote_ref_for_branch(struct branch *branch, int for_push);
cf818348 340
d27eb356 341/* returns true if the given branch has merge configuration given. */
cf818348 342int branch_has_merge_config(struct branch *branch);
d27eb356 343
85682c19 344int branch_merge_matches(struct branch *, int n, const char *);
cf818348 345
a9f9f8cc
JK
346/**
347 * Return the fully-qualified refname of the tracking branch for `branch`.
348 * I.e., what "branch@{upstream}" would give you. Returns NULL if no
349 * upstream is defined.
3a429d0a
JK
350 *
351 * If `err` is not NULL and no upstream is defined, a more specific error
352 * message is recorded there (if the function does not return NULL, then
353 * `err` is not touched).
a9f9f8cc 354 */
3a429d0a 355const char *branch_get_upstream(struct branch *branch, struct strbuf *err);
a9f9f8cc 356
e291c75a
JK
357/**
358 * Return the tracking branch that corresponds to the ref we would push to
359 * given a bare `git push` while `branch` is checked out.
360 *
361 * The return value and `err` conventions match those of `branch_get_upstream`.
362 */
363const char *branch_get_push(struct branch *branch, struct strbuf *err);
364
28b9d6e5
AW
365/* Flags to match_refs. */
366enum match_refs_flags {
367 MATCH_REFS_NONE = 0,
368 MATCH_REFS_ALL = (1 << 0),
6ddba5e2 369 MATCH_REFS_MIRROR = (1 << 1),
c2aba155
JH
370 MATCH_REFS_PRUNE = (1 << 2),
371 MATCH_REFS_FOLLOW_TAGS = (1 << 3)
28b9d6e5
AW
372};
373
d7d1b496
JH
374/* Flags for --ahead-behind option. */
375enum ahead_behind_flags {
fd9b544a
JH
376 AHEAD_BEHIND_UNSPECIFIED = -1,
377 AHEAD_BEHIND_QUICK = 0, /* just eq/neq reporting */
378 AHEAD_BEHIND_FULL = 1, /* traditional a/b reporting */
d7d1b496
JH
379};
380
6d21bf96 381/* Reporting of tracking info */
979cb245 382int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
c646d093
DR
383 const char **upstream_name, int for_push,
384 enum ahead_behind_flags abf);
f39a757d 385int format_tracking_info(struct branch *branch, struct strbuf *sb,
b6f3da51
AH
386 enum ahead_behind_flags abf,
387 int show_divergence_advice);
6d21bf96 388
454e2025 389struct ref *get_local_heads(void);
d5d284df 390
8ef51733 391/*
4229f1fa 392 * Find refs from a list which are likely to be pointed to by the given HEAD
d5d284df
JT
393 * ref. If REMOTE_GUESS_HEAD_ALL is set, return a list of all candidate refs;
394 * otherwise, return the most likely ref. If no match is found (or 'head' is
395 * NULL), returns NULL. All returns are newly allocated and should be freed.
8ef51733 396 */
d5d284df
JT
397#define REMOTE_GUESS_HEAD_ALL (1 << 0)
398#define REMOTE_GUESS_HEAD_QUIET (1 << 1)
4229f1fa
JS
399struct ref *guess_remote_head(const struct ref *head,
400 const struct ref *refs,
d5d284df 401 unsigned flags);
4229f1fa 402
f2ef6075 403/* Return refs which no longer exist on remote */
a2ac50cb 404struct ref *get_stale_heads(struct refspec *rs, struct ref *fetch_map);
f2ef6075 405
28f5d176
JH
406/*
407 * Compare-and-swap
408 */
28f5d176
JH
409struct push_cas_option {
410 unsigned use_tracking_for_rest:1;
99a1f9ae 411 unsigned use_force_if_includes:1;
28f5d176 412 struct push_cas {
b8566f8f 413 struct object_id expect;
28f5d176
JH
414 unsigned use_tracking:1;
415 char *refname;
416 } *entry;
417 int nr;
418 int alloc;
419};
420
55454427 421int parseopt_push_cas_option(const struct option *, const char *arg, int unset);
05372c28 422void clear_cas_option(struct push_cas_option *);
28f5d176 423
55454427 424int is_empty_cas(const struct push_cas_option *);
91048a95
JH
425void apply_push_cas(struct push_cas_option *, struct remote *, struct ref *);
426
1d04e719
DS
427/*
428 * The `url` argument is the URL that navigates to the submodule origin
429 * repo. When relative, this URL is relative to the superproject origin
430 * URL repo. The `up_path` argument, if specified, is the relative
431 * path that navigates from the submodule working tree to the superproject
432 * working tree. Returns the origin URL of the submodule.
433 *
434 * Return either an absolute URL or filesystem path (if the superproject
435 * origin URL is an absolute URL or filesystem path, respectively) or a
436 * relative file system path (if the superproject origin URL is a relative
437 * file system path).
438 *
439 * When the output is a relative file system path, the path is either
440 * relative to the submodule working tree, if up_path is specified, or to
441 * the superproject working tree otherwise.
442 *
443 * NEEDSWORK: This works incorrectly on the domain and protocol part.
444 * remote_url url outcome expectation
445 * http://a.com/b ../c http://a.com/c as is
446 * http://a.com/b/ ../c http://a.com/c same as previous line, but
447 * ignore trailing slash in url
448 * http://a.com/b ../../c http://c error out
449 * http://a.com/b ../../../c http:/c error out
450 * http://a.com/b ../../../../c http:c error out
451 * http://a.com/b ../../../../../c .:c error out
834e3520 452 * http://a.com/b http://d.org/e http://d.org/e as is
1d04e719
DS
453 * NEEDSWORK: Given how chop_last_dir() works, this function is broken
454 * when a local part has a colon in its path component, too.
455 */
456char *relative_url(const char *remote_url, const char *url,
457 const char *up_path);
458
f21ea69d
MS
459int valid_remote_name(const char *name);
460
5751f490 461#endif