@matheusbsbs / matheus-bagliano / commits / 48ef563641
Fork 0

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>

Jeff King committed Mar 22, 2009 at 04:59 UTC 48ef563641d1904f8da2c6fffe700fe6276af8dd
1 file changed +16 -1
builtin-remote.c
+16 -1
@@ -931,6 +931,20 @@ int add_push_to_show_info(struct string_list_item *push_item, void *cb_data)
931 return 0;
932 }
933
934 +/*
935 + * Sorting comparison for a string list that has push_info
936 + * structs in its util field
937 + */
938 +static int cmp_string_with_push(const void *va, const void *vb)
939 +{
940 + const struct string_list_item *a = va;
941 + const struct string_list_item *b = vb;
942 + const struct push_info *a_push = a->util;
943 + const struct push_info *b_push = b->util;
944 + int cmp = strcmp(a->string, b->string);
945 + return cmp ? cmp : strcmp(a_push->dest, b_push->dest);
946 +}
947 +
948 int show_push_info_item(struct string_list_item *item, void *cb_data)
949 {
950 struct show_info *show_info = cb_data;
@@ -1041,7 +1055,8 @@ static int show(int argc, const char **argv)
1055
1056 info.width = info.width2 = 0;
1057 for_each_string_list(add_push_to_show_info, &states.push, &info);
1044 - sort_string_list(info.list);
1058 + qsort(info.list->items, info.list->nr,
1059 + sizeof(*info.list->items), cmp_string_with_push);
1060 if (info.list->nr)
1061 printf(" Local ref%s configured for 'git push'%s:\n",
1062 info.list->nr > 1 ? "s" : "",