{"thread":{"id":"8098","subject":"[PATCH 2/3] Move refspec parser from connect.c and cache.h to remote.{c,h}","startedAt":"2007-05-12T02:39:27Z","lastAt":"2007-05-12T07:32:47Z","messageCount":2,"participants":["Daniel Barkalow","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"41892","messageId":"Pine.LNX.4.64.0705112238420.18541@iabervon.org","threadId":"8098","inReplyTo":null,"subject":"[PATCH 2/3] Move refspec parser from connect.c and cache.h to remote.{c,h}","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2007-05-12T02:39:27Z","receivedAt":"2007-05-12T02:39:27Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>\n---\n cache.h     |    2 -\n connect.c   |  240 +---------------------------------------------------------\n http-push.c |    1 +\n remote.c    |  246 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n remote.h    |   12 +++\n send-pack.c |    1 +\n 6 files changed, 261 insertions(+), 241 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 8e76152..46057f8 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -465,8 +465,6 @@ struct ref {\n extern pid_t git_connect(int fd[2], char *url, const char *prog);\n extern int finish_connect(pid_t pid);\n extern int path_match(const char *path, int nr, char **match);\n-extern int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,\n-\t\t      int nr_refspec, char **refspec, int all);\n extern int get_ack(int fd, unsigned char *result_sha1);\n extern struct ref **get_remote_heads(int in, struct ref **list, int nr_match, char **match, unsigned int flags);\n extern int server_supports(const char *feature);\ndiff --git a/connect.c b/connect.c\nindex da89c9c..50ec559 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -4,6 +4,7 @@\n #include \"quote.h\"\n #include \"refs.h\"\n #include \"run-command.h\"\n+#include \"remote.h\"\n \n static char *server_capabilities;\n \n@@ -128,245 +129,6 @@ int path_match(const char *path, int nr, char **match)\n \treturn 0;\n }\n \n-struct refspec {\n-\tchar *src;\n-\tchar *dst;\n-\tchar force;\n-};\n-\n-/*\n- * A:B means fast forward remote B with local A.\n- * +A:B means overwrite remote B with local A.\n- * +A is a shorthand for +A:A.\n- * A is a shorthand for A:A.\n- * :B means delete remote B.\n- */\n-static struct refspec *parse_ref_spec(int nr_refspec, char **refspec)\n-{\n-\tint i;\n-\tstruct refspec *rs = xcalloc(sizeof(*rs), (nr_refspec + 1));\n-\tfor (i = 0; i < nr_refspec; i++) {\n-\t\tchar *sp, *dp, *ep;\n-\t\tsp = refspec[i];\n-\t\tif (*sp == '+') {\n-\t\t\trs[i].force = 1;\n-\t\t\tsp++;\n-\t\t}\n-\t\tep = strchr(sp, ':');\n-\t\tif (ep) {\n-\t\t\tdp = ep + 1;\n-\t\t\t*ep = 0;\n-\t\t}\n-\t\telse\n-\t\t\tdp = sp;\n-\t\trs[i].src = sp;\n-\t\trs[i].dst = dp;\n-\t}\n-\trs[nr_refspec].src = rs[nr_refspec].dst = NULL;\n-\treturn rs;\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)\n-{\n-\tint patlen = strlen(pattern);\n-\tstruct ref *matched_weak = NULL;\n-\tstruct ref *matched = NULL;\n-\tint weak_match = 0;\n-\tint match = 0;\n-\n-\tfor (weak_match = match = 0; refs; refs = refs->next) {\n-\t\tchar *name = refs->name;\n-\t\tint namelen = strlen(name);\n-\t\tint weak_match;\n-\n-\t\tif (namelen < patlen ||\n-\t\t    memcmp(name + namelen - patlen, pattern, patlen))\n-\t\t\tcontinue;\n-\t\tif (namelen != patlen && name[namelen - patlen - 1] != '/')\n-\t\t\tcontinue;\n-\n-\t\t/* A match is \"weak\" if it is with refs outside\n-\t\t * heads or tags, and did not specify the pattern\n-\t\t * in full (e.g. \"refs/remotes/origin/master\") or at\n-\t\t * least from the toplevel (e.g. \"remotes/origin/master\");\n-\t\t * otherwise \"git push $URL master\" would result in\n-\t\t * ambiguity between remotes/origin/master and heads/master\n-\t\t * at the remote site.\n-\t\t */\n-\t\tif (namelen != patlen &&\n-\t\t    patlen != namelen - 5 &&\n-\t\t    prefixcmp(name, \"refs/heads/\") &&\n-\t\t    prefixcmp(name, \"refs/tags/\")) {\n-\t\t\t/* We want to catch the case where only weak\n-\t\t\t * matches are found and there are multiple\n-\t\t\t * matches, and where more than one strong\n-\t\t\t * matches are found, as ambiguous.  One\n-\t\t\t * strong match with zero or more weak matches\n-\t\t\t * are acceptable as a unique match.\n-\t\t\t */\n-\t\t\tmatched_weak = refs;\n-\t\t\tweak_match++;\n-\t\t}\n-\t\telse {\n-\t\t\tmatched = refs;\n-\t\t\tmatch++;\n-\t\t}\n-\t}\n-\tif (!matched) {\n-\t\t*matched_ref = matched_weak;\n-\t\treturn weak_match;\n-\t}\n-\telse {\n-\t\t*matched_ref = matched;\n-\t\treturn match;\n-\t}\n-}\n-\n-static void link_dst_tail(struct ref *ref, struct ref ***tail)\n-{\n-\t**tail = ref;\n-\t*tail = &ref->next;\n-\t**tail = NULL;\n-}\n-\n-static struct ref *try_explicit_object_name(const char *name)\n-{\n-\tunsigned char sha1[20];\n-\tstruct ref *ref;\n-\tint len;\n-\n-\tif (!*name) {\n-\t\tref = xcalloc(1, sizeof(*ref) + 20);\n-\t\tstrcpy(ref->name, \"(delete)\");\n-\t\thashclr(ref->new_sha1);\n-\t\treturn ref;\n-\t}\n-\tif (get_sha1(name, sha1))\n-\t\treturn NULL;\n-\tlen = strlen(name) + 1;\n-\tref = xcalloc(1, sizeof(*ref) + len);\n-\tmemcpy(ref->name, name, len);\n-\thashcpy(ref->new_sha1, sha1);\n-\treturn ref;\n-}\n-\n-static int match_explicit_refs(struct ref *src, struct ref *dst,\n-\t\t\t       struct ref ***dst_tail, struct refspec *rs)\n-{\n-\tint i, errs;\n-\tfor (i = errs = 0; rs[i].src; i++) {\n-\t\tstruct ref *matched_src, *matched_dst;\n-\n-\t\tmatched_src = matched_dst = NULL;\n-\t\tswitch (count_refspec_match(rs[i].src, src, &matched_src)) {\n-\t\tcase 1:\n-\t\t\tbreak;\n-\t\tcase 0:\n-\t\t\t/* The source could be in the get_sha1() format\n-\t\t\t * not a reference name.  :refs/other is a\n-\t\t\t * way to delete 'other' ref at the remote end.\n-\t\t\t */\n-\t\t\tmatched_src = try_explicit_object_name(rs[i].src);\n-\t\t\tif (matched_src)\n-\t\t\t\tbreak;\n-\t\t\terrs = 1;\n-\t\t\terror(\"src refspec %s does not match any.\",\n-\t\t\t      rs[i].src);\n-\t\t\tbreak;\n-\t\tdefault:\n-\t\t\terrs = 1;\n-\t\t\terror(\"src refspec %s matches more than one.\",\n-\t\t\t      rs[i].src);\n-\t\t\tbreak;\n-\t\t}\n-\t\tswitch (count_refspec_match(rs[i].dst, dst, &matched_dst)) {\n-\t\tcase 1:\n-\t\t\tbreak;\n-\t\tcase 0:\n-\t\t\tif (!memcmp(rs[i].dst, \"refs/\", 5)) {\n-\t\t\t\tint len = strlen(rs[i].dst) + 1;\n-\t\t\t\tmatched_dst = xcalloc(1, sizeof(*dst) + len);\n-\t\t\t\tmemcpy(matched_dst->name, rs[i].dst, len);\n-\t\t\t\tlink_dst_tail(matched_dst, dst_tail);\n-\t\t\t}\n-\t\t\telse if (!strcmp(rs[i].src, rs[i].dst) &&\n-\t\t\t\t matched_src) {\n-\t\t\t\t/* pushing \"master:master\" when\n-\t\t\t\t * remote does not have master yet.\n-\t\t\t\t */\n-\t\t\t\tint len = strlen(matched_src->name) + 1;\n-\t\t\t\tmatched_dst = xcalloc(1, sizeof(*dst) + len);\n-\t\t\t\tmemcpy(matched_dst->name, matched_src->name,\n-\t\t\t\t       len);\n-\t\t\t\tlink_dst_tail(matched_dst, dst_tail);\n-\t\t\t}\n-\t\t\telse {\n-\t\t\t\terrs = 1;\n-\t\t\t\terror(\"dst refspec %s does not match any \"\n-\t\t\t\t      \"existing ref on the remote and does \"\n-\t\t\t\t      \"not start with refs/.\", rs[i].dst);\n-\t\t\t}\n-\t\t\tbreak;\n-\t\tdefault:\n-\t\t\terrs = 1;\n-\t\t\terror(\"dst refspec %s matches more than one.\",\n-\t\t\t      rs[i].dst);\n-\t\t\tbreak;\n-\t\t}\n-\t\tif (errs)\n-\t\t\tcontinue;\n-\t\tif (matched_dst->peer_ref) {\n-\t\t\terrs = 1;\n-\t\t\terror(\"dst ref %s receives from more than one src.\",\n-\t\t\t      matched_dst->name);\n-\t\t}\n-\t\telse {\n-\t\t\tmatched_dst->peer_ref = matched_src;\n-\t\t\tmatched_dst->force = rs[i].force;\n-\t\t}\n-\t}\n-\treturn -errs;\n-}\n-\n-static struct ref *find_ref_by_name(struct ref *list, const char *name)\n-{\n-\tfor ( ; list; list = list->next)\n-\t\tif (!strcmp(list->name, name))\n-\t\t\treturn list;\n-\treturn NULL;\n-}\n-\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-\tstruct refspec *rs = parse_ref_spec(nr_refspec, refspec);\n-\n-\tif (nr_refspec)\n-\t\treturn match_explicit_refs(src, dst, dst_tail, rs);\n-\n-\t/* pick the remainder */\n-\tfor ( ; src; src = src->next) {\n-\t\tstruct ref *dst_peer;\n-\t\tif (src->peer_ref)\n-\t\t\tcontinue;\n-\t\tdst_peer = find_ref_by_name(dst, src->name);\n-\t\tif ((dst_peer && dst_peer->peer_ref) || (!dst_peer && !all))\n-\t\t\tcontinue;\n-\t\tif (!dst_peer) {\n-\t\t\t/* Create a new one and link it */\n-\t\t\tint len = strlen(src->name) + 1;\n-\t\t\tdst_peer = xcalloc(1, sizeof(*dst_peer) + len);\n-\t\t\tmemcpy(dst_peer->name, src->name, len);\n-\t\t\thashcpy(dst_peer->new_sha1, src->new_sha1);\n-\t\t\tlink_dst_tail(dst_peer, dst_tail);\n-\t\t}\n-\t\tdst_peer->peer_ref = src;\n-\t}\n-\treturn 0;\n-}\n-\n enum protocol {\n \tPROTO_LOCAL = 1,\n \tPROTO_SSH,\ndiff --git a/http-push.c b/http-push.c\nindex e3f7675..79d2c38 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -9,6 +9,7 @@\n #include \"diff.h\"\n #include \"revision.h\"\n #include \"exec_cmd.h\"\n+#include \"remote.h\"\n \n #include <expat.h>\n \ndiff --git a/remote.c b/remote.c\nindex 1dd2e77..2ac7bc8 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -181,6 +181,44 @@ static void read_config(void)\n \tgit_config(handle_config);\n }\n \n+static struct refspec *parse_ref_spec(int nr_refspec, const char **refspec)\n+{\n+\tint i;\n+\tstruct refspec *rs = xcalloc(sizeof(*rs), nr_refspec);\n+\tfor (i = 0; i < nr_refspec; i++) {\n+\t\tconst char *sp, *ep, *gp;\n+\t\tsp = refspec[i];\n+\t\tif (*sp == '+') {\n+\t\t\trs[i].force = 1;\n+\t\t\tsp++;\n+\t\t}\n+\t\tgp = strchr(sp, '*');\n+\t\tep = strchr(sp, ':');\n+\t\tif (gp && ep && gp > ep)\n+\t\t\tgp = NULL;\n+\t\tif (ep) {\n+\t\t\tif (ep[1]) {\n+\t\t\t\tconst char *glob = strchr(ep + 1, '*');\n+\t\t\t\tif (!glob)\n+\t\t\t\t\tgp = NULL;\n+\t\t\t\tif (gp)\n+\t\t\t\t\trs[i].dest = xstrndup(ep + 1,\n+\t\t\t\t\t\t\t      glob - ep - 1);\n+\t\t\t\telse\n+\t\t\t\t\trs[i].dest = xstrdup(ep + 1);\n+\t\t\t}\n+\t\t} else {\n+\t\t\tep = sp + strlen(sp);\n+\t\t}\n+\t\tif (gp) {\n+\t\t\trs[i].pattern = 1;\n+\t\t\tep = gp;\n+\t\t}\n+\t\trs[i].src = xstrndup(sp, ep - sp);\n+\t}\n+\treturn rs;\n+}\n+\n struct remote *remote_get(const char *name)\n {\n \tstruct remote *ret;\n@@ -199,5 +237,213 @@ struct remote *remote_get(const char *name)\n \t\tadd_uri(ret, name);\n \tif (!ret->uri)\n \t\treturn NULL;\n+\tret->push = parse_ref_spec(ret->push_refspec_nr, ret->push_refspec);\n \treturn ret;\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)\n+{\n+\tint patlen = strlen(pattern);\n+\tstruct ref *matched_weak = NULL;\n+\tstruct ref *matched = NULL;\n+\tint weak_match = 0;\n+\tint match = 0;\n+\n+\tfor (weak_match = match = 0; refs; refs = refs->next) {\n+\t\tchar *name = refs->name;\n+\t\tint namelen = strlen(name);\n+\t\tint weak_match;\n+\n+\t\tif (namelen < patlen ||\n+\t\t    memcmp(name + namelen - patlen, pattern, patlen))\n+\t\t\tcontinue;\n+\t\tif (namelen != patlen && name[namelen - patlen - 1] != '/')\n+\t\t\tcontinue;\n+\n+\t\t/* A match is \"weak\" if it is with refs outside\n+\t\t * heads or tags, and did not specify the pattern\n+\t\t * in full (e.g. \"refs/remotes/origin/master\") or at\n+\t\t * least from the toplevel (e.g. \"remotes/origin/master\");\n+\t\t * otherwise \"git push $URL master\" would result in\n+\t\t * ambiguity between remotes/origin/master and heads/master\n+\t\t * at the remote site.\n+\t\t */\n+\t\tif (namelen != patlen &&\n+\t\t    patlen != namelen - 5 &&\n+\t\t    prefixcmp(name, \"refs/heads/\") &&\n+\t\t    prefixcmp(name, \"refs/tags/\")) {\n+\t\t\t/* We want to catch the case where only weak\n+\t\t\t * matches are found and there are multiple\n+\t\t\t * matches, and where more than one strong\n+\t\t\t * matches are found, as ambiguous.  One\n+\t\t\t * strong match with zero or more weak matches\n+\t\t\t * are acceptable as a unique match.\n+\t\t\t */\n+\t\t\tmatched_weak = refs;\n+\t\t\tweak_match++;\n+\t\t}\n+\t\telse {\n+\t\t\tmatched = refs;\n+\t\t\tmatch++;\n+\t\t}\n+\t}\n+\tif (!matched) {\n+\t\t*matched_ref = matched_weak;\n+\t\treturn weak_match;\n+\t}\n+\telse {\n+\t\t*matched_ref = matched;\n+\t\treturn match;\n+\t}\n+}\n+\n+static void link_dst_tail(struct ref *ref, struct ref ***tail)\n+{\n+\t**tail = ref;\n+\t*tail = &ref->next;\n+\t**tail = NULL;\n+}\n+\n+static struct ref *try_explicit_object_name(const char *name)\n+{\n+\tunsigned char sha1[20];\n+\tstruct ref *ref;\n+\tint len;\n+\n+\tif (!*name) {\n+\t\tref = xcalloc(1, sizeof(*ref) + 20);\n+\t\tstrcpy(ref->name, \"(delete)\");\n+\t\thashclr(ref->new_sha1);\n+\t\treturn ref;\n+\t}\n+\tif (get_sha1(name, sha1))\n+\t\treturn NULL;\n+\tlen = strlen(name) + 1;\n+\tref = xcalloc(1, sizeof(*ref) + len);\n+\tmemcpy(ref->name, name, len);\n+\thashcpy(ref->new_sha1, sha1);\n+\treturn ref;\n+}\n+\n+static int match_explicit_refs(struct ref *src, struct ref *dst,\n+\t\t\t       struct ref ***dst_tail, struct refspec *rs,\n+\t\t\t       int rs_nr)\n+{\n+\tint i, errs;\n+\tfor (i = errs = 0; i < rs_nr; i++) {\n+\t\tstruct ref *matched_src, *matched_dst;\n+\n+\t\tconst char *dest = rs[i].dest;\n+\t\tif (dest == NULL)\n+\t\t\tdest = rs[i].src;\n+\n+\t\tmatched_src = matched_dst = NULL;\n+\t\tswitch (count_refspec_match(rs[i].src, src, &matched_src)) {\n+\t\tcase 1:\n+\t\t\tbreak;\n+\t\tcase 0:\n+\t\t\t/* The source could be in the get_sha1() format\n+\t\t\t * not a reference name.  :refs/other is a\n+\t\t\t * way to delete 'other' ref at the remote end.\n+\t\t\t */\n+\t\t\tmatched_src = try_explicit_object_name(rs[i].src);\n+\t\t\tif (matched_src)\n+\t\t\t\tbreak;\n+\t\t\terrs = 1;\n+\t\t\terror(\"src refspec %s does not match any.\",\n+\t\t\t      rs[i].src);\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\terrs = 1;\n+\t\t\terror(\"src refspec %s matches more than one.\",\n+\t\t\t      rs[i].src);\n+\t\t\tbreak;\n+\t\t}\n+\t\tswitch (count_refspec_match(dest, dst, &matched_dst)) {\n+\t\tcase 1:\n+\t\t\tbreak;\n+\t\tcase 0:\n+\t\t\tif (!memcmp(dest, \"refs/\", 5)) {\n+\t\t\t\tint len = strlen(dest) + 1;\n+\t\t\t\tmatched_dst = xcalloc(1, sizeof(*dst) + len);\n+\t\t\t\tmemcpy(matched_dst->name, dest, len);\n+\t\t\t\tlink_dst_tail(matched_dst, dst_tail);\n+\t\t\t}\n+\t\t\telse if (!strcmp(rs[i].src, dest) &&\n+\t\t\t\t matched_src) {\n+\t\t\t\t/* pushing \"master:master\" when\n+\t\t\t\t * remote does not have master yet.\n+\t\t\t\t */\n+\t\t\t\tint len = strlen(matched_src->name) + 1;\n+\t\t\t\tmatched_dst = xcalloc(1, sizeof(*dst) + len);\n+\t\t\t\tmemcpy(matched_dst->name, matched_src->name,\n+\t\t\t\t       len);\n+\t\t\t\tlink_dst_tail(matched_dst, dst_tail);\n+\t\t\t}\n+\t\t\telse {\n+\t\t\t\terrs = 1;\n+\t\t\t\terror(\"dst refspec %s does not match any \"\n+\t\t\t\t      \"existing ref on the remote and does \"\n+\t\t\t\t      \"not start with refs/.\", rs[i].dest);\n+\t\t\t}\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\terrs = 1;\n+\t\t\terror(\"dst refspec %s matches more than one.\",\n+\t\t\t      dest);\n+\t\t\tbreak;\n+\t\t}\n+\t\tif (errs)\n+\t\t\tcontinue;\n+\t\tif (matched_dst->peer_ref) {\n+\t\t\terrs = 1;\n+\t\t\terror(\"dst ref %s receives from more than one src.\",\n+\t\t\t      matched_dst->name);\n+\t\t}\n+\t\telse {\n+\t\t\tmatched_dst->peer_ref = matched_src;\n+\t\t\tmatched_dst->force = rs[i].force;\n+\t\t}\n+\t}\n+\treturn -errs;\n+}\n+\n+static struct ref *find_ref_by_name(struct ref *list, const char *name)\n+{\n+\tfor ( ; list; list = list->next)\n+\t\tif (!strcmp(list->name, name))\n+\t\t\treturn list;\n+\treturn NULL;\n+}\n+\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+\tstruct refspec *rs =\n+\t\tparse_ref_spec(nr_refspec, (const char **) refspec);\n+\n+\tif (nr_refspec)\n+\t\treturn match_explicit_refs(src, dst, dst_tail, rs, nr_refspec);\n+\n+\t/* pick the remainder */\n+\tfor ( ; src; src = src->next) {\n+\t\tstruct ref *dst_peer;\n+\t\tif (src->peer_ref)\n+\t\t\tcontinue;\n+\t\tdst_peer = find_ref_by_name(dst, src->name);\n+\t\tif ((dst_peer && dst_peer->peer_ref) || (!dst_peer && !all))\n+\t\t\tcontinue;\n+\t\tif (!dst_peer) {\n+\t\t\t/* Create a new one and link it */\n+\t\t\tint len = strlen(src->name) + 1;\n+\t\t\tdst_peer = xcalloc(1, sizeof(*dst_peer) + len);\n+\t\t\tmemcpy(dst_peer->name, src->name, len);\n+\t\t\thashcpy(dst_peer->new_sha1, src->new_sha1);\n+\t\t\tlink_dst_tail(dst_peer, dst_tail);\n+\t\t}\n+\t\tdst_peer->peer_ref = src;\n+\t}\n+\treturn 0;\n+}\ndiff --git a/remote.h b/remote.h\nindex 73747a8..79cedde 100644\n--- a/remote.h\n+++ b/remote.h\n@@ -8,6 +8,7 @@ struct remote {\n \tint uri_nr;\n \n \tconst char **push_refspec;\n+\tstruct refspec *push;\n \tint push_refspec_nr;\n \n \tconst char *receivepack;\n@@ -15,4 +16,15 @@ struct remote {\n \n struct remote *remote_get(const char *name);\n \n+struct refspec {\n+\tunsigned force : 1;\n+\tunsigned pattern : 1;\n+\n+\tconst char *src;\n+\tchar *dest;\n+};\n+\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 #endif\ndiff --git a/send-pack.c b/send-pack.c\nindex d5b5162..6851043 100644\n--- a/send-pack.c\n+++ b/send-pack.c\n@@ -4,6 +4,7 @@\n #include \"refs.h\"\n #include \"pkt-line.h\"\n #include \"run-command.h\"\n+#include \"remote.h\"\n \n static const char send_pack_usage[] =\n \"git-send-pack [--all] [--force] [--receive-pack=<git-receive-pack>] [--verbose] [--thin] [<host>:]<directory> [<ref>...]\\n\"\n-- \n1.5.2.rc2.45.g3d9b43-dirty\n"},{"id":"41900","messageId":"7v7ire5wf4.fsf@assigned-by-dhcp.cox.net","threadId":"8098","inReplyTo":"Pine.LNX.4.64.0705112238420.18541@iabervon.org","subject":"Re: [PATCH 2/3] Move refspec parser from connect.c and cache.h to remote.{c,h}","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-05-12T07:32:47Z","receivedAt":"2007-05-12T07:32:47Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Daniel Barkalow <barkalow@iabervon.org> writes:\n\n> diff --git a/remote.c b/remote.c\n> index 1dd2e77..2ac7bc8 100644\n> --- a/remote.c\n> +++ b/remote.c\n> @@ -181,6 +181,44 @@ static void read_config(void)\n> + ...\n> +static int match_explicit_refs(struct ref *src, struct ref *dst,\n> +\t\t\t       struct ref ***dst_tail, struct refspec *rs,\n> +\t\t\t       int rs_nr)\n> +{\n> +\tint i, errs;\n> +\tfor (i = errs = 0; i < rs_nr; i++) {\n> +\t\tstruct ref *matched_src, *matched_dst;\n> +\n> +\t\tconst char *dest = rs[i].dest;\n> +\t\tif (dest == NULL)\n> +\t\t\tdest = rs[i].src;\n\nI am not a big fan of gratuitous renaming of structure members\nand variables such as this s/dst/dest/, especially when the\nchange breaks consistency (between src vs dst -- you left\nmatched_dst intact).\n\n> ...\n> +\t\tswitch (count_refspec_match(dest, dst, &matched_dst)) {\n> ...\n> +\t\tcase 0:\n> +\t\t\tif (!memcmp(dest, \"refs/\", 5)) {\n> ...\n> +\t\t\telse {\n> +\t\t\t\terrs = 1;\n> +\t\t\t\terror(\"dst refspec %s does not match any \"\n> +\t\t\t\t      \"existing ref on the remote and does \"\n> +\t\t\t\t      \"not start with refs/.\", rs[i].dest);\n> +\t\t\t}\n\nI think you meant to say 'dest' instead of 'rs[i].dest' here.\n\n> +...\n> +\t}\n> +\treturn -errs;\n> +}\n"}]}