Add handlers for fetch-side configuration of remotes.
These follow the pattern of the push side configuration, but aren't taken from anywhere else, because git-fetch is still in shell. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Daniel Barkalow committed
May 12, 2007 at 11:46 UTC
5d46c9d41febe5fe85f94f7db2b190d8abf1e71e
2 files changed
+70
remote.c
+59
@@ -17,6 +17,15 @@ static void add_push_refspec(struct remote *remote, const char *ref)
17
remote->push_refspec_nr = nr;
18
}
19
20
+static void add_fetch_refspec(struct remote *remote, const char *ref)
21
+{
22
+ int nr = remote->fetch_refspec_nr + 1;
23
+ remote->fetch_refspec =
24
+ xrealloc(remote->fetch_refspec, nr * sizeof(char *));
25
+ remote->fetch_refspec[nr-1] = ref;
26
+ remote->fetch_refspec_nr = nr;
27
+}
28
+
29
static void add_uri(struct remote *remote, const char *uri)
30
{
31
int nr = remote->uri_nr + 1;
@@ -74,6 +83,9 @@ static void read_remotes_file(struct remote *remote)
83
} else if (!prefixcmp(buffer, "Push:")) {
84
value_list = 1;
85
s = buffer + 5;
86
+ } else if (!prefixcmp(buffer, "Pull:")) {
87
+ value_list = 2;
88
+ s = buffer + 5;
89
} else
90
continue;
91
@@ -93,6 +105,9 @@ static void read_remotes_file(struct remote *remote)
105
case 1:
106
add_push_refspec(remote, xstrdup(s));
107
break;
108
+ case 2:
109
+ add_fetch_refspec(remote, xstrdup(s));
110
+ break;
111
}
112
}
113
fclose(f);
@@ -174,6 +189,8 @@ static int handle_config(const char *key, const char *value)
189
add_uri(remote, xstrdup(value));
190
} else if (!strcmp(subkey, ".push")) {
191
add_push_refspec(remote, xstrdup(value));
192
+ } else if (!strcmp(subkey, ".fetch")) {
193
+ add_fetch_refspec(remote, xstrdup(value));
194
} else if (!strcmp(subkey, ".receivepack")) {
195
if (!remote->receivepack)
196
remote->receivepack = xstrdup(value);
@@ -257,10 +274,52 @@ struct remote *remote_get(const char *name)
274
add_uri(ret, name);
275
if (!ret->uri)
276
return NULL;
277
+ ret->fetch = parse_ref_spec(ret->fetch_refspec_nr, ret->fetch_refspec);
278
ret->push = parse_ref_spec(ret->push_refspec_nr, ret->push_refspec);
279
return ret;
280
}
281
282
+int remote_has_uri(struct remote *remote, const char *uri)
283
+{
284
+ int i;
285
+ for (i = 0; i < remote->uri_nr; i++) {
286
+ if (!strcmp(remote->uri[i], uri))
287
+ return 1;
288
+ }
289
+ return 0;
290
+}
291
+
292
+int remote_find_tracking(struct remote *remote, struct refspec *refspec)
293
+{
294
+ int i;
295
+ for (i = 0; i < remote->fetch_refspec_nr; i++) {
296
+ struct refspec *fetch = &remote->fetch[i];
297
+ if (!fetch->dst)
298
+ continue;
299
+ if (fetch->pattern) {
300
+ if (!prefixcmp(refspec->src, fetch->src)) {
301
+ refspec->dst =
302
+ xmalloc(strlen(fetch->dst) +
303
+ strlen(refspec->src) -
304
+ strlen(fetch->src) + 1);
305
+ strcpy(refspec->dst, fetch->dst);
306
+ strcpy(refspec->dst + strlen(fetch->dst),
307
+ refspec->src + strlen(fetch->src));
308
+ refspec->force = fetch->force;
309
+ return 0;
310
+ }
311
+ } else {
312
+ if (!strcmp(refspec->src, fetch->src)) {
313
+ refspec->dst = xstrdup(fetch->dst);
314
+ refspec->force = fetch->force;
315
+ return 0;
316
+ }
317
+ }
318
+ }
319
+ refspec->dst = NULL;
320
+ return -1;
321
+}
322
+
323
static int count_refspec_match(const char *pattern,
324
struct ref *refs,
325
struct ref **matched_ref)
remote.h
+11
@@ -11,11 +11,17 @@ struct remote {
11
struct refspec *push;
12
int push_refspec_nr;
13
14
+ const char **fetch_refspec;
15
+ struct refspec *fetch;
16
+ int fetch_refspec_nr;
17
+
18
const char *receivepack;
19
};
20
21
struct remote *remote_get(const char *name);
22
23
+int remote_has_uri(struct remote *remote, const char *uri);
24
+
25
struct refspec {
26
unsigned force : 1;
27
unsigned pattern : 1;
@@ -27,4 +33,9 @@ struct refspec {
33
int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
34
int nr_refspec, char **refspec, int all);
35
36
+/*
37
+ * For the given remote, reads the refspec's src and sets the other fields.
38
+ */
39
+int remote_find_tracking(struct remote *remote, struct refspec *refspec);
40
+
41
#endif