Skip to content

Commit

Permalink
fetch-pack: sort incoming heads
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed May 22, 2012
1 parent aa3bb87 commit 4435968
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion builtin/fetch-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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");
Expand Down

0 comments on commit 4435968

Please sign in to comment.