From: Jeff King Date: Mon, 21 May 2012 22:17:02 +0000 (-0400) Subject: fetch-pack: sort incoming heads X-Git-Tag: v1.7.11-rc1~16^2~5 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4435968;p=git.git fetch-pack: sort incoming heads There's no reason to preserve the incoming order of the heads we're requested to fetch. By having them sorted, we can replace some of the quadratic algorithms with linear ones. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c index 10db15b18..d9e0ee51b 100644 --- a/builtin/fetch-pack.c +++ b/builtin/fetch-pack.c @@ -1057,6 +1057,11 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix) return ret; } +static int compare_heads(const void *a, const void *b) +{ + return strcmp(*(const char **)a, *(const char **)b); +} + struct ref *fetch_pack(struct fetch_pack_args *my_args, int fd[], struct child_process *conn, const struct ref *ref, @@ -1076,8 +1081,11 @@ struct ref *fetch_pack(struct fetch_pack_args *my_args, st.st_mtime = 0; } - if (heads && nr_heads) + if (heads && nr_heads) { nr_heads = remove_duplicates(nr_heads, heads); + qsort(heads, nr_heads, sizeof(*heads), compare_heads); + } + if (!ref) { packet_flush(fd[1]); die("no matching remote head");