{"thread":{"id":"8113","subject":"[PATCH 3/3] Add handlers for fetch-side configuration of remotes.","startedAt":"2007-05-12T15:46:03Z","lastAt":"2007-05-12T15:46:03Z","messageCount":1,"participants":["Daniel Barkalow"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"41933","messageId":"Pine.LNX.4.64.0705121144460.18541@iabervon.org","threadId":"8113","inReplyTo":null,"subject":"[PATCH 3/3] Add handlers for fetch-side configuration of remotes.","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2007-05-12T15:46:03Z","receivedAt":"2007-05-12T15:46:03Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"These follow the pattern of the push side configuration, but aren't\ntaken from anywhere else, because git-fetch is still in shell.\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\n---\n remote.c |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n remote.h |   10 ++++++++++\n 2 files changed, 69 insertions(+), 0 deletions(-)\n\ndiff --git a/remote.c b/remote.c\nindex 1deada1..450b12d 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -17,6 +17,15 @@ static void add_push_refspec(struct remote *remote, const char *ref)\n \tremote->push_refspec_nr = nr;\n }\n \n+static void add_fetch_refspec(struct remote *remote, const char *ref)\n+{\n+\tint nr = remote->fetch_refspec_nr + 1;\n+\tremote->fetch_refspec =\n+\t\txrealloc(remote->fetch_refspec, nr * sizeof(char *));\n+\tremote->fetch_refspec[nr-1] = ref;\n+\tremote->fetch_refspec_nr = nr;\n+}\n+\n static void add_uri(struct remote *remote, const char *uri)\n {\n \tint nr = remote->uri_nr + 1;\n@@ -74,6 +83,9 @@ static void read_remotes_file(struct remote *remote)\n \t\t} else if (!prefixcmp(buffer, \"Push:\")) {\n \t\t\tvalue_list = 1;\n \t\t\ts = buffer + 5;\n+\t\t} else if (!prefixcmp(buffer, \"Pull:\")) {\n+\t\t\tvalue_list = 2;\n+\t\t\ts = buffer + 5;\n \t\t} else\n \t\t\tcontinue;\n \n@@ -93,6 +105,9 @@ static void read_remotes_file(struct remote *remote)\n \t\tcase 1:\n \t\t\tadd_push_refspec(remote, xstrdup(s));\n \t\t\tbreak;\n+\t\tcase 2:\n+\t\t\tadd_fetch_refspec(remote, xstrdup(s));\n+\t\t\tbreak;\n \t\t}\n \t}\n \tfclose(f);\n@@ -155,6 +170,8 @@ static int handle_config(const char *key, const char *value)\n \t\tadd_uri(remote, xstrdup(value));\n \t} else if (!strcmp(subkey, \".push\")) {\n \t\tadd_push_refspec(remote, xstrdup(value));\n+\t} else if (!strcmp(subkey, \".fetch\")) {\n+\t\tadd_fetch_refspec(remote, xstrdup(value));\n \t} else if (!strcmp(subkey, \".receivepack\")) {\n \t\tif (!remote->receivepack)\n \t\t\tremote->receivepack = xstrdup(value);\n@@ -238,10 +255,52 @@ struct remote *remote_get(const char *name)\n \t\tadd_uri(ret, name);\n \tif (!ret->uri)\n \t\treturn NULL;\n+\tret->fetch = parse_ref_spec(ret->fetch_refspec_nr, ret->fetch_refspec);\n \tret->push = parse_ref_spec(ret->push_refspec_nr, ret->push_refspec);\n \treturn ret;\n }\n \n+int remote_has_uri(struct remote *remote, const char *uri)\n+{\n+\tint i;\n+\tfor (i = 0; i < remote->uri_nr; i++) {\n+\t\tif (!strcmp(remote->uri[i], uri))\n+\t\t\treturn 1;\n+\t}\n+\treturn 0;\n+}\n+\n+int remote_find_tracking(struct remote *remote, struct refspec *refspec)\n+{\n+\tint i;\n+\tfor (i = 0; i < remote->fetch_refspec_nr; i++) {\n+\t\tstruct refspec *fetch = &remote->fetch[i];\n+\t\tif (!fetch->dest)\n+\t\t\tcontinue;\n+\t\tif (fetch->pattern) {\n+\t\t\tif (!prefixcmp(refspec->src, fetch->src)) {\n+\t\t\t\trefspec->dest =\n+\t\t\t\t\txmalloc(strlen(fetch->dest) +\n+\t\t\t\t\t\tstrlen(refspec->src) -\n+\t\t\t\t\t\tstrlen(fetch->src) + 1);\n+\t\t\t\tstrcpy(refspec->dest, fetch->dest);\n+\t\t\t\tstrcpy(refspec->dest + strlen(fetch->dest),\n+\t\t\t\t       refspec->src + strlen(fetch->src));\n+\t\t\t\trefspec->force = fetch->force;\n+\t\t\t\treturn 0;\n+\t\t\t}\n+\t\t} else {\n+\t\t\tif (!strcmp(refspec->src, fetch->src)) {\n+\t\t\t\trefspec->dest = xstrdup(fetch->dest);\n+\t\t\t\trefspec->force = fetch->force;\n+\t\t\t\treturn 0;\n+\t\t\t}\n+\t\t}\n+\t}\n+\trefspec->dest = NULL;\n+\treturn -1;\n+}\n+\n static int count_refspec_match(const char *pattern,\n \t\t\t       struct ref *refs,\n \t\t\t       struct ref **matched_ref)\ndiff --git a/remote.h b/remote.h\nindex 3bc035b..babb135 100644\n--- a/remote.h\n+++ b/remote.h\n@@ -11,11 +11,17 @@ struct remote {\n \tstruct refspec *push;\n \tint push_refspec_nr;\n \n+\tconst char **fetch_refspec;\n+\tstruct refspec *fetch;\n+\tint fetch_refspec_nr;\n+\n \tconst char *receivepack;\n };\n \n struct remote *remote_get(const char *name);\n \n+int remote_has_uri(struct remote *remote, const char *uri);\n+\n struct refspec {\n \tunsigned force : 1;\n \tunsigned pattern : 1;\n@@ -27,4 +33,8 @@ struct refspec {\n int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,\n \t       int nr_refspec, char **refspec, int all);\n \n+/** For the given remote, reads the refspec's src and sets the other fields.\n+ **/\n+int remote_find_tracking(struct remote *remote, struct refspec *refspec);\n+\n #endif\n-- \n1.5.2.rc2.45.g3d9b43-dirty\n"}]}