t3203: --sort=objectsize failure on Windows
On Windows, I observe a failure of the test case 'git branch --sort option' introduced by aedcb7dc (branch.c: use 'ref-filter' APIs). The reason is that the resulting order generated by qsort is unspecified for entries that compare equal. In fact, the test case sorts 4 entries where there are only 2 different values.
To achieve a deterministic order, perhaps cmp_ref_sorting() should fall back to alphabetic comparison if the other criterion (when used) compares equal?
-- Hannes
PATCH 1/1 ref-filter: fallback on alphabetical comparison
In ref-filter.c the comparison of refs while sorting is handled by cmp_ref_sorting() function. When sorting as per numerical values (e.g. --sort=objectsize) there is no fallback comparison when both refs hold the same value. This can cause unexpected results as pointed out by Johannes Sixt ($gmane/280117).
Hence, fallback to alphabetical comparison based on the refname whenever the other criterion is equal. Fix the test in t3203 in this regard.
--- ref-filter.c | 2 +- t/t3203-branch-output.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
ref-filter.c +1 -1
@@ -1698,7 +1698,7 @@ static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, struif (va->ul < vb->ul) cmp =-1 ;else if (va->ul == vb->ul) - cmp =0 ; + cmp =strcmp (a->refname, b->refname);else cmp =1 ; }
t/t3203-branch-output.sh +1 -1
@@ -158,8 +158,8 @@ EOF test_expect_success 'git branch `--sort` option' ' cat >expect <<-\EOF && - branch-two * (HEAD detached from fromtag) + branch-two branch-one master EOF
Signature · 1 line
2.6.2
Re: [PATCH] ref-filter: fallback on alphabetical comparison
Quoted 5 lines · Karthik Nayak
In
ref-filter.cthe comparison of refs while sorting is handled bycmp_ref_sorting()function. When sorting as per numerical values (e.g. --sort=objectsize) there is no fallback comparison when both refs hold the same value. This can cause unexpected results as pointed out by Johannes Sixt ($gmane/280117).
Please make the commit message self-contained by describing the "unexpected results" here rather than directing readers to chase down the information elsewhere themselves.
Quoted 4 lines
Hence, fallback to alphabetical comparison based on the refname whenever the other criterion is equal. Fix the test in t3203 in this regard.
Signed-off-by Karthik Nayak <[email protected]>
It would not be amiss to add a Reported-by: to credit j6t.
Quoted 30 lines
---
ref-filter.c +1
-1@@ -1698,7 +1698,7 @@ static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, struif (va->ul < vb->ul) cmp =-1 ;else if (va->ul == vb->ul) - cmp =0 ; + cmp =strcmp (a->refname, b->refname);else cmp =1 ; }t/t3203-branch-output.sh +1
-2@@ -158,8 +158,8 @@ EOF test_expect_success 'git branch `--sort` option' ' cat >expect <<-\EOF && - branch-two * (HEAD detached from fromtag) + branch-two branch-one master EOF --2.6.2
Re: [PATCH] ref-filter: fallback on alphabetical comparison
Quoted 11 lines · Eric Sunshine
Quoted 5 lines · Karthik Nayak
In
ref-filter.cthe comparison of refs while sorting is handled bycmp_ref_sorting()function. When sorting as per numerical values (e.g. --sort=objectsize) there is no fallback comparison when both refs hold the same value. This can cause unexpected results as pointed out by Johannes Sixt ($gmane/280117).Please make the commit message self-contained by describing the "unexpected results" here rather than directing readers to chase down the information elsewhere themselves.
Will do.
Quoted 7 lines
Quoted 4 lines
Hence, fallback to alphabetical comparison based on the refname whenever the other criterion is equal. Fix the test in t3203 in this regard.
Signed-off-by Karthik Nayak <[email protected]>It would not be amiss to add a Reported-by: to credit j6t.
Definitely. Thanks for the quick review :)
Signature · 2 lines
Regards, Karthik Nayak
Quoted 5 lines · Johannes Sixt
On Windows, I observe a failure of the test case 'git branch
--sortoption' introduced byaedcb7dc(branch.c: use 'ref-filter' APIs). The reason is that the resulting order generated by qsort is unspecified for entries that compare equal. In fact, the test case sorts 4 entries where there are only 2 different values.
Thanks for reporting the error. Although I couldn't reproduce this on a Linux environment.
I get what the problem is.
Quoted 4 lines
To achieve a deterministic order, perhaps
cmp_ref_sorting()should fall back to alphabetic comparison if the other criterion (when used) compares equal?
Seems like a simple and good way to go around this. will reply with a patch.
Signature · 2 lines
Regards, Karthik Nayak