{"thread":{"id":"18164","subject":"[PATCH 2/5] Use a single function to match names against patterns","startedAt":"2009-03-06T04:56:18Z","lastAt":"2009-03-07T06:11:29Z","messageCount":2,"participants":["Daniel Barkalow"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"107142","messageId":"alpine.LNX.1.00.0903052355110.19665@iabervon.org","threadId":"18164","inReplyTo":null,"subject":"[PATCH 2/5] Use a single function to match names against patterns","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-03-06T04:56:18Z","receivedAt":"2009-03-06T04:56:18Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"This will help when the matching changes.\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\n---\n remote.c |   12 +++++++++---\n 1 files changed, 9 insertions(+), 3 deletions(-)\n\ndiff --git a/remote.c b/remote.c\nindex d7079c6..709300b 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -719,6 +719,12 @@ int remote_has_url(struct remote *remote, const char *url)\n \treturn 0;\n }\n \n+static int name_fits_pattern(const char *key, const char *name)\n+{\n+\tint ret = !prefixcmp(key, name);\n+\treturn ret;\n+}\n+\n int remote_find_tracking(struct remote *remote, struct refspec *refspec)\n {\n \tint find_src = refspec->src == NULL;\n@@ -742,7 +748,7 @@ int remote_find_tracking(struct remote *remote, struct refspec *refspec)\n \t\tif (!fetch->dst)\n \t\t\tcontinue;\n \t\tif (fetch->pattern) {\n-\t\t\tif (!prefixcmp(needle, key)) {\n+\t\t\tif (name_fits_pattern(key, needle)) {\n \t\t\t\t*result = xmalloc(strlen(value) +\n \t\t\t\t\t\t  strlen(needle) -\n \t\t\t\t\t\t  strlen(key) + 1);\n@@ -1020,7 +1026,7 @@ static const struct refspec *check_pattern_match(const struct refspec *rs,\n \t\t\tcontinue;\n \t\t}\n \n-\t\tif (rs[i].pattern && !prefixcmp(src->name, rs[i].src))\n+\t\tif (rs[i].pattern && name_fits_pattern(rs[i].src, src->name))\n \t\t\treturn rs + i;\n \t}\n \tif (matching_refs != -1)\n@@ -1160,7 +1166,7 @@ static struct ref *get_expanded_map(const struct ref *remote_refs,\n \tfor (ref = remote_refs; ref; ref = ref->next) {\n \t\tif (strchr(ref->name, '^'))\n \t\t\tcontinue; /* a dereference item */\n-\t\tif (!prefixcmp(ref->name, refspec->src)) {\n+\t\tif (name_fits_pattern(refspec->src, ref->name)) {\n \t\t\tconst char *match;\n \t\t\tstruct ref *cpy = copy_ref(ref);\n \t\t\tmatch = ref->name + remote_prefix_len;\n-- \n1.6.1.286.gd33a4.dirty\n"},{"id":"107274","messageId":"alpine.LNX.1.00.0903070104230.19665@iabervon.org","threadId":"18164","inReplyTo":"alpine.LNX.1.00.0903052355110.19665@iabervon.org","subject":"[PATCH v2 2/5] Use a single function to match names against patterns","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-03-07T06:11:29Z","receivedAt":"2009-03-07T06:11:29Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"This will help when the matching changes.\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\n---\nImproved the function name for its eventual use.\n\n remote.c |   12 +++++++++---\n 1 files changed, 9 insertions(+), 3 deletions(-)\n\ndiff --git a/remote.c b/remote.c\nindex d7079c6..2816723 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -719,6 +719,12 @@ int remote_has_url(struct remote *remote, const char *url)\n \treturn 0;\n }\n \n+static int match_name_with_pattern(const char *key, const char *name)\n+{\n+\tint ret = !prefixcmp(key, name);\n+\treturn ret;\n+}\n+\n int remote_find_tracking(struct remote *remote, struct refspec *refspec)\n {\n \tint find_src = refspec->src == NULL;\n@@ -742,7 +748,7 @@ int remote_find_tracking(struct remote *remote, struct refspec *refspec)\n \t\tif (!fetch->dst)\n \t\t\tcontinue;\n \t\tif (fetch->pattern) {\n-\t\t\tif (!prefixcmp(needle, key)) {\n+\t\t\tif (match_name_with_pattern(key, needle)) {\n \t\t\t\t*result = xmalloc(strlen(value) +\n \t\t\t\t\t\t  strlen(needle) -\n \t\t\t\t\t\t  strlen(key) + 1);\n@@ -1020,7 +1026,7 @@ static const struct refspec *check_pattern_match(const struct refspec *rs,\n \t\t\tcontinue;\n \t\t}\n \n-\t\tif (rs[i].pattern && !prefixcmp(src->name, rs[i].src))\n+\t\tif (rs[i].pattern && match_name_with_pattern(rs[i].src, src->name))\n \t\t\treturn rs + i;\n \t}\n \tif (matching_refs != -1)\n@@ -1160,7 +1166,7 @@ static struct ref *get_expanded_map(const struct ref *remote_refs,\n \tfor (ref = remote_refs; ref; ref = ref->next) {\n \t\tif (strchr(ref->name, '^'))\n \t\t\tcontinue; /* a dereference item */\n-\t\tif (!prefixcmp(ref->name, refspec->src)) {\n+\t\tif (match_name_with_pattern(refspec->src, ref->name)) {\n \t\t\tconst char *match;\n \t\t\tstruct ref *cpy = copy_ref(ref);\n \t\t\tmatch = ref->name + remote_prefix_len;\n-- \n1.6.1.286.gd33a4.dirty\n"}]}