remote: Make ref_remove_duplicates faster for large numbers of refs
The ref_remove_duplicates function was very slow at dealing with very large numbers of refs. This is because it was using a linear search through all remaining refs to find any duplicates of the current ref. Rewriting it to use a string list to keep track of which refs have already been seen and removing duplicates when they are found is much more efficient. Signed-off-by: Julian Phillips <julian@quantumfyre.co.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
e984c54ada
commit
73cf0822b2
41
remote.c
41
remote.c
@ -6,6 +6,7 @@
|
|||||||
#include "revision.h"
|
#include "revision.h"
|
||||||
#include "dir.h"
|
#include "dir.h"
|
||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
|
#include "string-list.h"
|
||||||
|
|
||||||
static struct refspec s_tag_refspec = {
|
static struct refspec s_tag_refspec = {
|
||||||
0,
|
0,
|
||||||
@ -734,29 +735,31 @@ int for_each_remote(each_remote_fn fn, void *priv)
|
|||||||
|
|
||||||
void ref_remove_duplicates(struct ref *ref_map)
|
void ref_remove_duplicates(struct ref *ref_map)
|
||||||
{
|
{
|
||||||
struct ref **posn;
|
struct string_list refs = { NULL, 0, 0, 0 };
|
||||||
struct ref *next;
|
struct string_list_item *item = NULL;
|
||||||
for (; ref_map; ref_map = ref_map->next) {
|
struct ref *prev = NULL, *next = NULL;
|
||||||
|
for (; ref_map; prev = ref_map, ref_map = next) {
|
||||||
|
next = ref_map->next;
|
||||||
if (!ref_map->peer_ref)
|
if (!ref_map->peer_ref)
|
||||||
continue;
|
continue;
|
||||||
posn = &ref_map->next;
|
|
||||||
while (*posn) {
|
item = string_list_lookup(ref_map->peer_ref->name, &refs);
|
||||||
if ((*posn)->peer_ref &&
|
if (item) {
|
||||||
!strcmp((*posn)->peer_ref->name,
|
if (strcmp(((struct ref *)item->util)->name,
|
||||||
ref_map->peer_ref->name)) {
|
ref_map->name))
|
||||||
if (strcmp((*posn)->name, ref_map->name))
|
die("%s tracks both %s and %s",
|
||||||
die("%s tracks both %s and %s",
|
ref_map->peer_ref->name,
|
||||||
ref_map->peer_ref->name,
|
((struct ref *)item->util)->name,
|
||||||
(*posn)->name, ref_map->name);
|
ref_map->name);
|
||||||
next = (*posn)->next;
|
prev->next = ref_map->next;
|
||||||
free((*posn)->peer_ref);
|
free(ref_map->peer_ref);
|
||||||
free(*posn);
|
free(ref_map);
|
||||||
*posn = next;
|
|
||||||
} else {
|
|
||||||
posn = &(*posn)->next;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
item = string_list_insert(ref_map->peer_ref->name, &refs);
|
||||||
|
item->util = ref_map;
|
||||||
}
|
}
|
||||||
|
string_list_clear(&refs, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int remote_has_url(struct remote *remote, const char *url)
|
int remote_has_url(struct remote *remote, const char *url)
|
||||||
|
Reference in New Issue
Block a user