summaryrefslogtreecommitdiff
path: root/builtin/fetch-pack.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2012-05-21 18:17:02 -0400
committerJunio C Hamano <gitster@pobox.com>2012-05-22 13:31:03 -0700
commit443596850f464c768624e6b6477acadc2aa35e8f (patch)
tree99f8fef9ffe97cf031224797f2cca82e8a6333cc /builtin/fetch-pack.c
parentaa3bb87176d42f1782c5030fa41e6e62492551c0 (diff)
downloadgit-443596850f464c768624e6b6477acadc2aa35e8f.tar.gz
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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/fetch-pack.c')
-rw-r--r--builtin/fetch-pack.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index 10db15b184..d9e0ee51b0 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");