remote: refactor some logic into get_stale_heads()
[git/git.git] / remote.h
CommitLineData
5751f490
DB
1#ifndef REMOTE_H
2#define REMOTE_H
3
89cf4c70
MV
4enum {
5 REMOTE_CONFIG,
6 REMOTE_REMOTES,
7 REMOTE_BRANCHES
8};
9
5751f490
DB
10struct remote {
11 const char *name;
89cf4c70 12 int origin;
5751f490 13
28b91f8a
SP
14 const char **url;
15 int url_nr;
2d31347b 16 int url_alloc;
5751f490 17
20346234
MG
18 const char **pushurl;
19 int pushurl_nr;
20 int pushurl_alloc;
21
5751f490 22 const char **push_refspec;
6b62816c 23 struct refspec *push;
5751f490 24 int push_refspec_nr;
2d31347b 25 int push_refspec_alloc;
5751f490 26
5d46c9d4
DB
27 const char **fetch_refspec;
28 struct refspec *fetch;
29 int fetch_refspec_nr;
2d31347b 30 int fetch_refspec_alloc;
5d46c9d4 31
d71ab174
DB
32 /*
33 * -1 to never fetch tags
34 * 0 to auto-follow tags on heuristic (default)
35 * 1 to always auto-follow tags
36 * 2 to always fetch tags
37 */
38 int fetch_tags;
211c8968 39 int skip_default_update;
84bb2dfd 40 int mirror;
d71ab174 41
5751f490 42 const char *receivepack;
0012ba21 43 const char *uploadpack;
14c98218
SV
44
45 /*
46 * for curl remotes only
47 */
48 char *http_proxy;
5751f490
DB
49};
50
51struct remote *remote_get(const char *name);
9a23ba33 52int remote_is_configured(const char *name);
5751f490 53
b42f6927
JS
54typedef int each_remote_fn(struct remote *remote, void *priv);
55int for_each_remote(each_remote_fn fn, void *priv);
56
28b91f8a 57int remote_has_url(struct remote *remote, const char *url);
5d46c9d4 58
6b62816c
DB
59struct refspec {
60 unsigned force : 1;
61 unsigned pattern : 1;
a83619d6 62 unsigned matching : 1;
6b62816c 63
b42f6927 64 char *src;
6b62816c
DB
65 char *dst;
66};
67
e0aaa29f
DB
68extern const struct refspec *tag_refspec;
69
59c69c0c 70struct ref *alloc_ref(const char *name);
737922aa 71
4577370e
DB
72struct ref *copy_ref_list(const struct ref *ref);
73
74int check_ref_type(const struct ref *ref, int flags);
75
dfd255dd
DB
76/*
77 * Frees the entire list and peers of elements.
78 */
79void free_refs(struct ref *ref);
80
be885d96 81int resolve_remote_symref(struct ref *ref, struct ref *list);
ec8452d5 82int ref_newer(const unsigned char *new_sha1, const unsigned char *old_sha1);
be885d96 83
2467a4fa
DB
84/*
85 * Removes and frees any duplicate refs in the map.
86 */
87void ref_remove_duplicates(struct ref *ref_map);
88
24b6177e 89int valid_fetch_refspec(const char *refspec);
46220ca1 90struct refspec *parse_fetch_refspec(int nr_refspec, const char **refspec);
d71ab174 91
6d2bf96e 92int match_refs(struct ref *src, struct ref **dst,
4577370e 93 int nr_refspec, const char **refspec, int all);
6b62816c 94
d71ab174
DB
95/*
96 * Given a list of the remote refs and the specification of things to
97 * fetch, makes a (separate) list of the refs to fetch and the local
98 * refs to store into.
99 *
100 * *tail is the pointer to the tail pointer of the list of results
101 * beforehand, and will be set to the tail pointer of the list of
102 * results afterward.
9ad7c5ae
JH
103 *
104 * missing_ok is usually false, but when we are adding branch.$name.merge
105 * it is Ok if the branch is not at the remote anymore.
d71ab174 106 */
4577370e 107int get_fetch_map(const struct ref *remote_refs, const struct refspec *refspec,
9ad7c5ae 108 struct ref ***tail, int missing_ok);
d71ab174 109
4577370e 110struct ref *get_remote_ref(const struct ref *remote_refs, const char *name);
d71ab174 111
5d46c9d4
DB
112/*
113 * For the given remote, reads the refspec's src and sets the other fields.
114 */
115int remote_find_tracking(struct remote *remote, struct refspec *refspec);
116
cf818348
DB
117struct branch {
118 const char *name;
119 const char *refname;
120
121 const char *remote_name;
122 struct remote *remote;
123
124 const char **merge_name;
125 struct refspec **merge;
126 int merge_nr;
2d31347b 127 int merge_alloc;
cf818348
DB
128};
129
130struct branch *branch_get(const char *name);
131
132int branch_has_merge_config(struct branch *branch);
85682c19 133int branch_merge_matches(struct branch *, int n, const char *);
cf818348 134
28b9d6e5
AW
135/* Flags to match_refs. */
136enum match_refs_flags {
137 MATCH_REFS_NONE = 0,
138 MATCH_REFS_ALL = (1 << 0),
139 MATCH_REFS_MIRROR = (1 << 1),
140};
141
6d21bf96
JH
142/* Reporting of tracking info */
143int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs);
144int format_tracking_info(struct branch *branch, struct strbuf *sb);
145
454e2025 146struct ref *get_local_heads(void);
8ef51733 147/*
4229f1fa
JS
148 * Find refs from a list which are likely to be pointed to by the given HEAD
149 * ref. If 'all' is false, returns the most likely ref; otherwise, returns a
150 * list of all candidate refs. If no match is found (or 'head' is NULL),
151 * returns NULL. All returns are newly allocated and should be freed.
8ef51733 152 */
4229f1fa
JS
153struct ref *guess_remote_head(const struct ref *head,
154 const struct ref *refs,
155 int all);
156
f2ef6075
JS
157/* Return refs which no longer exist on remote */
158struct ref *get_stale_heads(struct remote *remote, struct ref *fetch_map);
159
5751f490 160#endif