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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
May 21, 2012 at 18:19 UTC
9e8e704f0bc14da325aa63f639c6dc782c81e26f
1 file changed
+2
builtin/fetch-pack.c
+2
@@ -777,6 +777,8 @@ static struct ref *do_fetch_pack(int fd[2],
777
struct ref *ref = copy_ref_list(orig_ref);
778
unsigned char sha1[20];
779
780
+ sort_ref_list(&ref, ref_compare_name);
781
+
782
if (is_repository_shallow() && !server_supports("shallow"))
783
die("Server does not support shallow clients");
784
if (server_supports("multi_ack_detailed")) {