{"thread":{"id":"10189","subject":"[PATCH] Remove duplicate ref matches in fetch","startedAt":"2007-10-08T04:25:07Z","lastAt":"2007-10-08T04:25:07Z","messageCount":1,"participants":["Daniel Barkalow"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"55155","messageId":"Pine.LNX.4.64.0710080014000.23070@iabervon.org","threadId":"10189","inReplyTo":null,"subject":"[PATCH] Remove duplicate ref matches in fetch","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2007-10-08T04:25:07Z","receivedAt":"2007-10-08T04:25:07Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"If multiple refspecs matched the same ref, the update would be\nprocessed multiple times. Now having the same destination for the same\nsource has no additional effect, and having the same destination for\ndifferent sources is an error.\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\n---\nI tested this with the usual tests, but (a) they don't include this case \n(yet), and (b) they passed before I fixed a bug. So this should get some \ngood testing, and probably by somebody with valgrind --leak-check to make \nsure I'm deallocating things correctly.\n\n builtin-fetch.c |    1 +\n remote.c        |   27 +++++++++++++++++++++++++++\n remote.h        |    5 +++++\n 3 files changed, 33 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-fetch.c b/builtin-fetch.c\nindex cf7498b..caaca63 100644\n--- a/builtin-fetch.c\n+++ b/builtin-fetch.c\n@@ -112,6 +112,7 @@ static struct ref *get_ref_map(struct transport *transport,\n \t\t\tref_map->merge = 1;\n \t\t}\n \t}\n+\tref_remove_duplicates(ref_map);\n \n \treturn ref_map;\n }\ndiff --git a/remote.c b/remote.c\nindex e7d735b..e2ca4d3 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -380,6 +380,33 @@ int for_each_remote(each_remote_fn fn, void *priv)\n \treturn result;\n }\n \n+void ref_remove_duplicates(struct ref *ref_map)\n+{\n+\tstruct ref **posn;\n+\tstruct ref *next;\n+\tfor (; ref_map; ref_map = ref_map->next) {\n+\t\tif (!ref_map->peer_ref)\n+\t\t\tcontinue;\n+\t\tposn = &ref_map->next;\n+\t\twhile (*posn) {\n+\t\t\tif ((*posn)->peer_ref &&\n+\t\t\t    !strcmp((*posn)->peer_ref->name,\n+\t\t\t\t    ref_map->peer_ref->name)) {\n+\t\t\t\tif (strcmp((*posn)->name, ref_map->name))\n+\t\t\t\t\tdie(\"%s tracks both %s and %s\",\n+\t\t\t\t\t    ref_map->peer_ref->name,\n+\t\t\t\t\t    (*posn)->name, ref_map->name);\n+\t\t\t\tnext = (*posn)->next;\n+\t\t\t\tfree((*posn)->peer_ref);\n+\t\t\t\tfree(*posn);\n+\t\t\t\t*posn = next;\n+\t\t\t} else {\n+\t\t\t\tposn = &(*posn)->next;\n+\t\t\t}\n+\t\t}\n+\t}\n+}\n+\n int remote_has_url(struct remote *remote, const char *url)\n {\n \tint i;\ndiff --git a/remote.h b/remote.h\nindex 05add06..c62636d 100644\n--- a/remote.h\n+++ b/remote.h\n@@ -49,6 +49,11 @@ struct ref *alloc_ref(unsigned namelen);\n  */\n void free_refs(struct ref *ref);\n \n+/*\n+ * Removes and frees any duplicate refs in the map.\n+ */\n+void ref_remove_duplicates(struct ref *ref_map);\n+\n struct refspec *parse_ref_spec(int nr_refspec, const char **refspec);\n \n int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,\n-- \n1.5.3.4.1155.gfe96ee\n"}]}