diff options
author | Jeff King <peff@peff.net> | 2009-03-22 04:59:20 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-03-22 10:20:04 -0700 |
commit | 48ef563641d1904f8da2c6fffe700fe6276af8dd (patch) | |
tree | f86a449fed3e290446d1ea68f2922dd34ee0d259 /builtin-remote.c | |
parent | 8321c56b6bae25a2d70790f452df894be536b32c (diff) | |
download | git-48ef563641d1904f8da2c6fffe700fe6276af8dd.tar.gz |
remote: improve sorting of "configure for git push" list
The data structure used to store this list is a string_list
of sources with the destination in the util member. The
current code just sorts on the source; if a single source is
pushed to two different destination refs at a remote, then
the order in which they are printed is non-deterministic.
This patch implements a comparison using both fields.
Besides being a little nicer on the eyes, giving a stable
sort prevents false negatives in the test suite when
comparing output.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-remote.c')
-rw-r--r-- | builtin-remote.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/builtin-remote.c b/builtin-remote.c index 7b31e554e9..9fdbb6c103 100644 --- a/builtin-remote.c +++ b/builtin-remote.c @@ -931,6 +931,20 @@ int add_push_to_show_info(struct string_list_item *push_item, void *cb_data) return 0; } +/* + * Sorting comparison for a string list that has push_info + * structs in its util field + */ +static int cmp_string_with_push(const void *va, const void *vb) +{ + const struct string_list_item *a = va; + const struct string_list_item *b = vb; + const struct push_info *a_push = a->util; + const struct push_info *b_push = b->util; + int cmp = strcmp(a->string, b->string); + return cmp ? cmp : strcmp(a_push->dest, b_push->dest); +} + int show_push_info_item(struct string_list_item *item, void *cb_data) { struct show_info *show_info = cb_data; @@ -1041,7 +1055,8 @@ static int show(int argc, const char **argv) info.width = info.width2 = 0; for_each_string_list(add_push_to_show_info, &states.push, &info); - sort_string_list(info.list); + qsort(info.list->items, info.list->nr, + sizeof(*info.list->items), cmp_string_with_push); if (info.list->nr) printf(" Local ref%s configured for 'git push'%s:\n", info.list->nr > 1 ? "s" : "", |