remote: move doc to remote.h and refspec.h
Move the documentation from Documentation/technical/api-remote.txt to remote.h and refspec.h as it's easier for the developers to find the usage information beside the code instead of looking for it in another doc file. N.B. The doc for both push and fetch members of the remote struct aren't moved because they are out of date, as the members were changed from arrays of rspecs to struct refspec 2 years ago. Also documentation/technical/api-remote.txt is removed because the information it has is now redundant and it'll be hard to keep it up to date and synchronized with the documentation in the header file. Signed-off-by: Heba Waly <heba.waly@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Heba Waly committed
Nov 17, 2019 at 21:04 UTC
d27eb356bf253be763ab08733fae723adda27e1c
3 files changed
+70
-130
Documentation/technical/api-remote.txt
deleted
-127
@@ -1,127 +0,0 @@
1
-Remotes configuration API
2
-=========================
3
-
4
-The API in remote.h gives access to the configuration related to
5
-remotes. It handles all three configuration mechanisms historically
6
-and currently used by Git, and presents the information in a uniform
7
-fashion. Note that the code also handles plain URLs without any
8
-configuration, giving them just the default information.
9
-
10
-struct remote
11
--------------
12
-
13
-`name`::
14
-
15
- The user's nickname for the remote
16
-
17
-`url`::
18
-
19
- An array of all of the url_nr URLs configured for the remote
20
-
21
-`pushurl`::
22
-
23
- An array of all of the pushurl_nr push URLs configured for the remote
24
-
25
-`push`::
26
-
27
- An array of refspecs configured for pushing, with
28
- push_refspec being the literal strings, and push_refspec_nr
29
- being the quantity.
30
-
31
-`fetch`::
32
-
33
- An array of refspecs configured for fetching, with
34
- fetch_refspec being the literal strings, and fetch_refspec_nr
35
- being the quantity.
36
-
37
-`fetch_tags`::
38
-
39
- The setting for whether to fetch tags (as a separate rule from
40
- the configured refspecs); -1 means never to fetch tags, 0
41
- means to auto-follow tags based on the default heuristic, 1
42
- means to always auto-follow tags, and 2 means to fetch all
43
- tags.
44
-
45
-`receivepack`, `uploadpack`::
46
-
47
- The configured helper programs to run on the remote side, for
48
- Git-native protocols.
49
-
50
-`http_proxy`::
51
-
52
- The proxy to use for curl (http, https, ftp, etc.) URLs.
53
-
54
-`http_proxy_authmethod`::
55
-
56
- The method used for authenticating against `http_proxy`.
57
-
58
-struct remotes can be found by name with remote_get(), and iterated
59
-through with for_each_remote(). remote_get(NULL) will return the
60
-default remote, given the current branch and configuration.
61
-
62
-struct refspec
63
---------------
64
-
65
-A struct refspec holds the parsed interpretation of a refspec. If it
66
-will force updates (starts with a '+'), force is true. If it is a
67
-pattern (sides end with '*') pattern is true. src and dest are the
68
-two sides (including '*' characters if present); if there is only one
69
-side, it is src, and dst is NULL; if sides exist but are empty (i.e.,
70
-the refspec either starts or ends with ':'), the corresponding side is
71
-"".
72
-
73
-An array of strings can be parsed into an array of struct refspecs
74
-using parse_fetch_refspec() or parse_push_refspec().
75
-
76
-remote_find_tracking(), given a remote and a struct refspec with
77
-either src or dst filled out, will fill out the other such that the
78
-result is in the "fetch" specification for the remote (note that this
79
-evaluates patterns and returns a single result).
80
-
81
-struct branch
82
--------------
83
-
84
-Note that this may end up moving to branch.h
85
-
86
-struct branch holds the configuration for a branch. It can be looked
87
-up with branch_get(name) for "refs/heads/{name}", or with
88
-branch_get(NULL) for HEAD.
89
-
90
-It contains:
91
-
92
-`name`::
93
-
94
- The short name of the branch.
95
-
96
-`refname`::
97
-
98
- The full path for the branch ref.
99
-
100
-`remote_name`::
101
-
102
- The name of the remote listed in the configuration.
103
-
104
-`merge_name`::
105
-
106
- An array of the "merge" lines in the configuration.
107
-
108
-`merge`::
109
-
110
- An array of the struct refspecs used for the merge lines. That
111
- is, merge[i]->dst is a local tracking ref which should be
112
- merged into this branch by default.
113
-
114
-`merge_nr`::
115
-
116
- The number of merge configurations
117
-
118
-branch_has_merge_config() returns true if the given branch has merge
119
-configuration given.
120
-
121
-Other stuff
122
------------
123
-
124
-There is other stuff in remote.h that is related, in general, to the
125
-process of interacting with remotes.
126
-
127
-(Daniel Barkalow)
refspec.h
+16
@@ -20,6 +20,22 @@ struct refspec_item {
20
#define REFSPEC_INIT_FETCH { .fetch = REFSPEC_FETCH }
21
#define REFSPEC_INIT_PUSH { .fetch = REFSPEC_PUSH }
22
23
+/**
24
+ * A struct refspec holds the parsed interpretation of a refspec. If it will
25
+ * force updates (starts with a '+'), force is true. If it is a pattern
26
+ * (sides end with '*') pattern is true. src and dest are the two sides
27
+ * (including '*' characters if present); if there is only one side, it is src,
28
+ * and dst is NULL; if sides exist but are empty (i.e., the refspec either
29
+ * starts or ends with ':'), the corresponding side is "".
30
+ *
31
+ * An array of strings can be parsed into an array of struct refspecs using
32
+ * parse_fetch_refspec() or parse_push_refspec().
33
+ *
34
+ * remote_find_tracking(), given a remote and a struct refspec with either src
35
+ * or dst filled out, will fill out the other such that the result is in the
36
+ * "fetch" specification for the remote (note that this evaluates patterns and
37
+ * returns a single result).
38
+ */
39
struct refspec {
40
struct refspec_item *items;
41
int alloc;
remote.h
+54
-3
@@ -6,6 +6,14 @@
6
#include "hashmap.h"
7
#include "refspec.h"
8
9
+/**
10
+ * The API gives access to the configuration related to remotes. It handles
11
+ * all three configuration mechanisms historically and currently used by Git,
12
+ * and presents the information in a uniform fashion. Note that the code also
13
+ * handles plain URLs without any configuration, giving them just the default
14
+ * information.
15
+ */
16
+
17
enum {
18
REMOTE_UNCONFIGURED = 0,
19
REMOTE_CONFIG,
@@ -16,16 +24,22 @@ enum {
24
struct remote {
25
struct hashmap_entry ent;
26
27
+ /* The user's nickname for the remote */
28
const char *name;
29
+
30
int origin, configured_in_repo;
31
32
const char *foreign_vcs;
33
34
+ /* An array of all of the url_nr URLs configured for the remote */
35
const char **url;
36
+
37
int url_nr;
38
int url_alloc;
39
40
+ /* An array of all of the pushurl_nr push URLs configured for the remote */
41
const char **pushurl;
42
+
43
int pushurl_nr;
44
int pushurl_alloc;
45
@@ -34,32 +48,47 @@ struct remote {
48
struct refspec fetch;
49
50
/*
51
+ * The setting for whether to fetch tags (as a separate rule from the
52
+ * configured refspecs);
53
* -1 to never fetch tags
54
* 0 to auto-follow tags on heuristic (default)
55
* 1 to always auto-follow tags
56
* 2 to always fetch tags
57
*/
58
int fetch_tags;
59
+
60
int skip_default_update;
61
int mirror;
62
int prune;
63
int prune_tags;
64
65
+ /**
66
+ * The configured helper programs to run on the remote side, for
67
+ * Git-native protocols.
68
+ */
69
const char *receivepack;
70
const char *uploadpack;
71
51
- /*
52
- * for curl remotes only
53
- */
72
+ /* The proxy to use for curl (http, https, ftp, etc.) URLs. */
73
char *http_proxy;
74
+
75
+ /* The method used for authenticating against `http_proxy`. */
76
char *http_proxy_authmethod;
77
};
78
79
+/**
80
+ * struct remotes can be found by name with remote_get().
81
+ * remote_get(NULL) will return the default remote, given the current branch
82
+ * and configuration.
83
+ */
84
struct remote *remote_get(const char *name);
85
+
86
struct remote *pushremote_get(const char *name);
87
int remote_is_configured(struct remote *remote, int in_repo);
88
89
typedef int each_remote_fn(struct remote *remote, void *priv);
90
+
91
+/* iterate through struct remotes */
92
int for_each_remote(each_remote_fn fn, void *priv);
93
94
int remote_has_url(struct remote *remote, const char *url);
@@ -194,16 +223,36 @@ struct ref *get_remote_ref(const struct ref *remote_refs, const char *name);
223
*/
224
int remote_find_tracking(struct remote *remote, struct refspec_item *refspec);
225
226
+/**
227
+ * struct branch holds the configuration for a branch. It can be looked up with
228
+ * branch_get(name) for "refs/heads/{name}", or with branch_get(NULL) for HEAD.
229
+ */
230
struct branch {
231
+
232
+ /* The short name of the branch. */
233
const char *name;
234
+
235
+ /* The full path for the branch ref. */
236
const char *refname;
237
238
+ /* The name of the remote listed in the configuration. */
239
const char *remote_name;
240
+
241
const char *pushremote_name;
242
243
+ /* An array of the "merge" lines in the configuration. */
244
const char **merge_name;
245
+
246
+ /**
247
+ * An array of the struct refspecs used for the merge lines. That is,
248
+ * merge[i]->dst is a local tracking ref which should be merged into this
249
+ * branch by default.
250
+ */
251
struct refspec_item **merge;
252
+
253
+ /* The number of merge configurations */
254
int merge_nr;
255
+
256
int merge_alloc;
257
258
const char *push_tracking_ref;
@@ -215,7 +264,9 @@ const char *pushremote_for_branch(struct branch *branch, int *explicit);
264
const char *remote_ref_for_branch(struct branch *branch, int for_push,
265
int *explicit);
266
267
+/* returns true if the given branch has merge configuration given. */
268
int branch_has_merge_config(struct branch *branch);
269
+
270
int branch_merge_matches(struct branch *, int n, const char *);
271
272
/**