@matheusbsbs / matheus-bagliano / commits / 2467a4fa03
Fork 0

Remove duplicate ref matches in fetch

If multiple refspecs matched the same ref, the update would be processed multiple times. Now having the same destination for the same source has no additional effect, and having the same destination for different sources is an error. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Lars Hjemli <hjemli@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Daniel Barkalow committed Oct 8, 2007 at 00:25 UTC 2467a4fa03ff849fcf2f6a93b89057aebd49c62b
3 files changed +33
builtin-fetch.c
+1
@@ -112,6 +112,7 @@ static struct ref *get_ref_map(struct transport *transport,
112 ref_map->merge = 1;
113 }
114 }
115 + ref_remove_duplicates(ref_map);
116
117 return ref_map;
118 }
remote.c
+27
@@ -380,6 +380,33 @@ int for_each_remote(each_remote_fn fn, void *priv)
380 return result;
381 }
382
383 +void ref_remove_duplicates(struct ref *ref_map)
384 +{
385 + struct ref **posn;
386 + struct ref *next;
387 + for (; ref_map; ref_map = ref_map->next) {
388 + if (!ref_map->peer_ref)
389 + continue;
390 + posn = &ref_map->next;
391 + while (*posn) {
392 + if ((*posn)->peer_ref &&
393 + !strcmp((*posn)->peer_ref->name,
394 + ref_map->peer_ref->name)) {
395 + if (strcmp((*posn)->name, ref_map->name))
396 + die("%s tracks both %s and %s",
397 + ref_map->peer_ref->name,
398 + (*posn)->name, ref_map->name);
399 + next = (*posn)->next;
400 + free((*posn)->peer_ref);
401 + free(*posn);
402 + *posn = next;
403 + } else {
404 + posn = &(*posn)->next;
405 + }
406 + }
407 + }
408 +}
409 +
410 int remote_has_url(struct remote *remote, const char *url)
411 {
412 int i;
remote.h
+5
@@ -49,6 +49,11 @@ struct ref *alloc_ref(unsigned namelen);
49 */
50 void free_refs(struct ref *ref);
51
52 +/*
53 + * Removes and frees any duplicate refs in the map.
54 + */
55 +void ref_remove_duplicates(struct ref *ref_map);
56 +
57 struct refspec *parse_ref_spec(int nr_refspec, const char **refspec);
58
59 int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,