path: root/builtin/fetch-pack.c
diff options
authorJeff King <>2012-05-21 22:19:51 (GMT)
committerJunio C Hamano <>2012-05-22 20:31:03 (GMT)
commit9e8e704f0bc14da325aa63f639c6dc782c81e26f (patch)
tree915006dec9c93f6229dc36f7ee6f220d1d9e5b39 /builtin/fetch-pack.c
parented81c76bc3a9440e37b3512c9c2b742c6ca92c6f (diff)
fetch-pack: sort the list of incoming refs
Having the list sorted means we can avoid some quadratic algorithms when comparing lists. These should typically be sorted already, but they do come from the remote, so let's be extra careful. Our ref-sorting implementation does a mergesort, so we do not have to care about performance degrading in the common case that the list is already sorted. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin/fetch-pack.c')
1 files changed, 2 insertions, 0 deletions
diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index e101842..7d708fb 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -777,6 +777,8 @@ static struct ref *do_fetch_pack(int fd[2],
struct ref *ref = copy_ref_list(orig_ref);
unsigned char sha1[20];
+ sort_ref_list(&ref, ref_compare_name);
if (is_repository_shallow() && !server_supports("shallow"))
die("Server does not support shallow clients");
if (server_supports("multi_ack_detailed")) {