Skip to content

Commit

Permalink
for-each-ref: Fix sort with multiple keys
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Kacper Kornet authored and Junio C Hamano committed Aug 21, 2012
1 parent 912072d commit 3b51222
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion builtin/for-each-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,9 @@ static int opt_parse_sort(const struct option *opt, const char *arg, int unset)
if (!arg) /* should --no-sort void the list ? */
return -1;

*sort_tail = s = xcalloc(1, sizeof(*s));
s = xcalloc(1, sizeof(*s));
s->next = *sort_tail;
*sort_tail = s;

if (*arg == '-') {
s->reverse = 1;
Expand Down
2 changes: 1 addition & 1 deletion t/t6300-for-each-ref.sh
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ cat >expected <<\EOF
90b5ebede4899eda64893bc2a4c8f1d6fb6dfc40 <committer@example.com> refs/tags/bogo
EOF

test_expect_failure 'Verify sort with multiple keys' '
test_expect_success 'Verify sort with multiple keys' '
git for-each-ref --format="%(objectname) %(taggeremail) %(refname)" --sort=objectname --sort=taggeremail \
refs/tags/bogo refs/tags/master > actual &&
test_cmp expected actual
Expand Down

0 comments on commit 3b51222

Please sign in to comment.