for-each-ref: Fix sort with multiple keys
The linked list describing sort options was not correctly set up in opt_parse_sort. In the result, contrary to the documentation, only the last of multiple --sort options to git-for-each-ref was taken into account. This commit fixes it. Signed-off-by: Kacper Kornet <draenog@pld-linux.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Kacper Kornet committed
Aug 21, 2012 at 09:47 UTC
3b51222ceceed022f45193db19c57cf53f0164df
2 files changed
+4
-2
builtin/for-each-ref.c
+3
-1
@@ -962,7 +962,9 @@ static int opt_parse_sort(const struct option *opt, const char *arg, int unset)
962
if (!arg) /* should --no-sort void the list ? */
963
return -1;
964
965
- *sort_tail = s = xcalloc(1, sizeof(*s));
965
+ s = xcalloc(1, sizeof(*s));
966
+ s->next = *sort_tail;
967
+ *sort_tail = s;
968
969
if (*arg == '-') {
970
s->reverse = 1;
t/t6300-for-each-ref.sh
+1
-1
@@ -461,7 +461,7 @@ cat >expected <<\EOF
461
90b5ebede4899eda64893bc2a4c8f1d6fb6dfc40 <committer@example.com> refs/tags/bogo
462
EOF
463
464
-test_expect_failure 'Verify sort with multiple keys' '
464
+test_expect_success 'Verify sort with multiple keys' '
465
git for-each-ref --format="%(objectname) %(taggeremail) %(refname)" --sort=objectname --sort=taggeremail \
466
refs/tags/bogo refs/tags/master > actual &&
467
test_cmp expected actual