7 #include "string-list.h"
11 struct transport_ls_refs_options
;
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
22 REMOTE_UNCONFIGURED
= 0,
24 #ifndef WITH_BREAKING_CHANGES
27 #endif /* WITH_BREAKING_CHANGES */
33 struct counted_string
*instead_of
;
39 struct rewrite
**rewrite
;
45 struct remote
**remotes
;
48 struct hashmap remotes_hash
;
50 struct hashmap branches_hash
;
52 struct branch
*current_branch
;
53 char *pushremote_name
;
55 struct rewrites rewrites
;
56 struct rewrites rewrites_push
;
61 void remote_state_clear(struct remote_state
*remote_state
);
62 struct remote_state
*remote_state_new(void);
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,
72 struct hashmap_entry ent
;
74 /* The user's nickname for the remote */
77 int origin
, configured_in_repo
;
81 /* An array of all of the url_nr URLs configured for the remote */
83 /* An array of all of the pushurl_nr push URLs configured for the remote */
84 struct strvec pushurl
;
91 * The setting for whether to fetch tags (as a separate rule from the
92 * configured refspecs);
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
100 int skip_default_update
;
106 * The configured helper programs to run on the remote side, for
107 * Git-native protocols.
109 const char *receivepack
;
110 const char *uploadpack
;
112 /* The proxy to use for curl (http, https, ftp, etc.) URLs. */
115 /* The method used for authenticating against `http_proxy`. */
116 char *http_proxy_authmethod
;
118 struct string_list server_options
;
120 enum follow_remote_head_settings follow_remote_head
;
121 const char *no_warn_branch
;
125 * struct remotes can be found by name with remote_get().
126 * remote_get(NULL) will return the default remote, given the current branch
129 struct remote
*remote_get(const char *name
);
130 struct remote
*remote_get_early(const char *name
);
132 struct remote
*pushremote_get(const char *name
);
133 int remote_is_configured(struct remote
*remote
, int in_repo
);
135 typedef int each_remote_fn(struct remote
*remote
, void *priv
);
137 /* iterate through struct remotes */
138 int for_each_remote(each_remote_fn fn
, void *priv
);
140 int remote_has_url(struct remote
*remote
, const char *url
);
141 struct strvec
*push_url_of_remote(struct remote
*remote
);
143 struct ref_push_report
{
145 struct object_id
*old_oid
;
146 struct object_id
*new_oid
;
147 unsigned int forced_update
:1;
148 struct ref_push_report
*next
;
151 void ref_push_report_free(struct ref_push_report
*);
155 struct object_id old_oid
;
156 struct object_id new_oid
;
157 struct object_id old_oid_expect
; /* used by expect-old */
166 /* Need to check if local reflog reaches the remote tip. */
169 * Store the result of the check enabled by "check_reachable";
170 * implies the local reflog does not reach the remote tip.
175 REF_NOT_MATCHED
= 0, /* initial value */
177 REF_UNADVERTISED_NOT_ALLOWED
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
186 enum fetch_head_status
{
187 FETCH_HEAD_MERGE
= -1,
188 FETCH_HEAD_NOT_FOR_MERGE
= 0,
189 FETCH_HEAD_IGNORE
= 1
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
,
200 REF_STATUS_REJECT_STALE
,
201 REF_STATUS_REJECT_SHALLOW
,
202 REF_STATUS_REJECT_REMOTE_UPDATED
,
204 REF_STATUS_REMOTE_REJECT
,
205 REF_STATUS_EXPECTING_REPORT
,
206 REF_STATUS_ATOMIC_PUSH_FAILED
209 struct ref_push_report
*report
;
210 struct ref
*peer_ref
; /* when renaming */
211 char name
[FLEX_ARRAY
]; /* more */
214 #define REF_NORMAL (1u << 0)
215 #define REF_BRANCHES (1u << 1)
216 #define REF_TAGS (1u << 2)
218 struct ref
*find_ref_by_name(const struct ref
*list
, const char *name
);
220 struct ref
*alloc_ref(const char *name
);
221 struct ref
*copy_ref(const struct ref
*ref
);
222 struct ref
*copy_ref_list(const struct ref
*ref
);
223 int count_refspec_match(const char *, struct ref
*refs
, struct ref
**matched_ref
);
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.
228 void tail_link_ref(struct ref
*ref
, struct ref
***tail
);
230 int check_ref_type(const struct ref
*ref
, int flags
);
233 * Free a single ref and its peer, or an entire list of refs and their peers,
236 void free_one_ref(struct ref
*ref
);
237 void free_refs(struct ref
*ref
);
240 struct packet_reader
;
243 struct ref
**get_remote_heads(struct packet_reader
*reader
,
244 struct ref
**list
, unsigned int flags
,
245 struct oid_array
*extra_have
,
246 struct oid_array
*shallow_points
);
248 /* Used for protocol v2 in order to retrieve refs from a remote */
249 struct ref
**get_remote_refs(int fd_out
, struct packet_reader
*reader
,
250 struct ref
**list
, int for_push
,
251 struct transport_ls_refs_options
*transport_options
,
252 const struct string_list
*server_options
,
255 /* Used for protocol v2 in order to retrieve refs from a remote */
257 int get_remote_bundle_uri(int fd_out
, struct packet_reader
*reader
,
258 struct bundle_list
*bundles
, int stateless_rpc
);
260 int resolve_remote_symref(struct ref
*ref
, struct ref
*list
);
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.
269 struct ref
*ref_remove_duplicates(struct ref
*ref_map
);
271 int check_push_refs(struct ref
*src
, struct refspec
*rs
);
272 int match_push_refs(struct ref
*src
, struct ref
**dst
,
273 struct refspec
*rs
, int flags
);
274 void set_ref_status_for_push(struct ref
*remote_refs
, int send_mirror
,
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
280 * refs to store into. Note that negative refspecs are ignored here, and
281 * should be handled separately.
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
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.
290 int get_fetch_map(const struct ref
*remote_refs
, const struct refspec_item
*refspec
,
291 struct ref
***tail
, int missing_ok
);
293 struct ref
*get_remote_ref(const struct ref
*remote_refs
, const char *name
);
296 * For the given remote, reads the refspec's src and sets the other fields.
298 int remote_find_tracking(struct remote
*remote
, struct refspec_item
*refspec
);
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.
305 struct hashmap_entry ent
;
307 /* The short name of the branch. */
310 /* The full path for the branch ref. */
313 /* The name of the remote listed in the configuration. */
316 char *pushremote_name
;
318 /* An array of the "merge" lines in the configuration. */
319 const char **merge_name
;
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
326 struct refspec_item
**merge
;
328 /* The number of merge configurations */
333 const char *push_tracking_ref
;
336 struct branch
*branch_get(const char *name
);
337 const char *remote_for_branch(struct branch
*branch
, int *explicit);
338 const char *pushremote_for_branch(struct branch
*branch
, int *explicit);
339 char *remote_ref_for_branch(struct branch
*branch
, int for_push
);
341 /* returns true if the given branch has merge configuration given. */
342 int branch_has_merge_config(struct branch
*branch
);
344 int branch_merge_matches(struct branch
*, int n
, const char *);
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.
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).
355 const char *branch_get_upstream(struct branch
*branch
, struct strbuf
*err
);
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.
361 * The return value and `err` conventions match those of `branch_get_upstream`.
363 const char *branch_get_push(struct branch
*branch
, struct strbuf
*err
);
365 /* Flags to match_refs. */
366 enum match_refs_flags
{
368 MATCH_REFS_ALL
= (1 << 0),
369 MATCH_REFS_MIRROR
= (1 << 1),
370 MATCH_REFS_PRUNE
= (1 << 2),
371 MATCH_REFS_FOLLOW_TAGS
= (1 << 3)
374 /* Flags for --ahead-behind option. */
375 enum ahead_behind_flags
{
376 AHEAD_BEHIND_UNSPECIFIED
= -1,
377 AHEAD_BEHIND_QUICK
= 0, /* just eq/neq reporting */
378 AHEAD_BEHIND_FULL
= 1, /* traditional a/b reporting */
381 /* Reporting of tracking info */
382 int stat_tracking_info(struct branch
*branch
, int *num_ours
, int *num_theirs
,
383 const char **upstream_name
, int for_push
,
384 enum ahead_behind_flags abf
);
385 int format_tracking_info(struct branch
*branch
, struct strbuf
*sb
,
386 enum ahead_behind_flags abf
,
387 int show_divergence_advice
);
389 struct ref
*get_local_heads(void);
392 * Find refs from a list which are likely to be pointed to by the given HEAD
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.
397 #define REMOTE_GUESS_HEAD_ALL (1 << 0)
398 #define REMOTE_GUESS_HEAD_QUIET (1 << 1)
399 struct ref
*guess_remote_head(const struct ref
*head
,
400 const struct ref
*refs
,
403 /* Return refs which no longer exist on remote */
404 struct ref
*get_stale_heads(struct refspec
*rs
, struct ref
*fetch_map
);
409 struct push_cas_option
{
410 unsigned use_tracking_for_rest
:1;
411 unsigned use_force_if_includes
:1;
413 struct object_id expect
;
414 unsigned use_tracking
:1;
421 int parseopt_push_cas_option(const struct option
*, const char *arg
, int unset
);
422 void clear_cas_option(struct push_cas_option
*);
424 int is_empty_cas(const struct push_cas_option
*);
425 void apply_push_cas(struct push_cas_option
*, struct remote
*, struct ref
*);
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.
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
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.
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
452 * http://a.com/b http://d.org/e http://d.org/e as is
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.
456 char *relative_url(const char *remote_url
, const char *url
,
457 const char *up_path
);
459 int valid_remote_name(const char *name
);