Skip to content

Commit

Permalink
Remove duplicate ref matches in fetch
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Daniel Barkalow authored and Shawn O. Pearce committed Oct 16, 2007
1 parent 2b5a06e commit 2467a4f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions builtin-fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ static struct ref *get_ref_map(struct transport *transport,
ref_map->merge = 1;
}
}
ref_remove_duplicates(ref_map);

return ref_map;
}
Expand Down
27 changes: 27 additions & 0 deletions remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,33 @@ int for_each_remote(each_remote_fn fn, void *priv)
return result;
}

void ref_remove_duplicates(struct ref *ref_map)
{
struct ref **posn;
struct ref *next;
for (; ref_map; ref_map = ref_map->next) {
if (!ref_map->peer_ref)
continue;
posn = &ref_map->next;
while (*posn) {
if ((*posn)->peer_ref &&
!strcmp((*posn)->peer_ref->name,
ref_map->peer_ref->name)) {
if (strcmp((*posn)->name, ref_map->name))
die("%s tracks both %s and %s",
ref_map->peer_ref->name,
(*posn)->name, ref_map->name);
next = (*posn)->next;
free((*posn)->peer_ref);
free(*posn);
*posn = next;
} else {
posn = &(*posn)->next;
}
}
}
}

int remote_has_url(struct remote *remote, const char *url)
{
int i;
Expand Down
5 changes: 5 additions & 0 deletions remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ struct ref *alloc_ref(unsigned namelen);
*/
void free_refs(struct ref *ref);

/*
* Removes and frees any duplicate refs in the map.
*/
void ref_remove_duplicates(struct ref *ref_map);

struct refspec *parse_ref_spec(int nr_refspec, const char **refspec);

int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
Expand Down

0 comments on commit 2467a4f

Please sign in to comment.