ref-filter: fallback on alphabetical comparison
PATCH v3 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 (i.e. the order of listing refs with equal values cannot be pre-determined) 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
Quoted 6 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 (i.e. the order of listing refs with equal values cannot be pre-determined) as pointed out by Johannes Sixt ($gmane/280117).
As we use qsort(), if two members compare as equal, their order in the sorted array is undefined. I think this is a good change.
Quoted 3 lines
Hence, fallback to alphabetical comparison based on the refname whenever the other criterion is equal. Fix the test in t3203 in this regard.
It is unclear what "in this regard" is. Do you mean this (I am not suggesting you to spell these out in a very detailed way in the final log message; I am deliberately being detailed here to help me understand what you really mean)?
A test in t3203 was expecting that branch-two sorts before HEAD, which happened to be how qsort(3) on Linux sorted the array, but
(1) that outcome was not even guaranteed, and (2) once we start breaking ties with the refname, "HEAD" should sort before "branch-two" so the original expectation was inconsistent with the criterion we now use.
Update it to match the new world order, which we can now depend on being stable.
I am not sure about "HEAD" and "branch-two" in the above (it may be comparison between "HEAD" and "refs/heads/branch-two", for example).
Quoted 34 lines
Reported-by Johannes Sixt <[email protected]>Signed-off-by Karthik Nayak <[email protected]>--- 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
Quoted 9 lines · Junio C Hamano
Quoted 3 lines
Hence, fallback to alphabetical comparison based on the refname whenever the other criterion is equal. Fix the test in t3203 in this regard.
It is unclear what "in this regard" is. Do you mean this (I am not suggesting you to spell these out in a very detailed way in the final log message; I am deliberately being detailed here to help me understand what you really mean)?
Quoted 7 lines
A test in t3203 was expecting that branch-two sorts before HEAD, which happened to be how qsort(3) on Linux sorted the array, but
(1) that outcome was not even guaranteed, and (2) once we start breaking ties with the refname, "HEAD" should sort before "branch-two" so the original expectation was inconsistent with the criterion we now use.
Exactly what you're saying, they happened to have the same objectsize. Hence sorting them would put them together, but since we compare the refname's the "HEAD" ref would come before "branch-two".
Quoted 6 lines
Update it to match the new world order, which we can now depend on being stable.
I am not sure about "HEAD" and "branch-two" in the above (it may be comparison between "HEAD" and "refs/heads/branch-two", for example).
It actually is, we consider "refs/heads/branch-two rather then the shortened version of this. It makes sense to classify refs this way, even though this was a side effect of this commit.
Signature · 2 lines
Regards, Karthik Nayak
Quoted 25 lines · Karthik Nayak
Quoted 9 lines · Junio C Hamano
Quoted 3 lines
Hence, fallback to alphabetical comparison based on the refname whenever the other criterion is equal. Fix the test in t3203 in this regard.
It is unclear what "in this regard" is. Do you mean this (I am not suggesting you to spell these out in a very detailed way in the final log message; I am deliberately being detailed here to help me understand what you really mean)?
Quoted 7 lines
A test in t3203 was expecting that branch-two sorts before HEAD, which happened to be how qsort(3) on Linux sorted the array, but
(1) that outcome was not even guaranteed, and (2) once we start breaking ties with the refname, "HEAD" should sort before "branch-two" so the original expectation was inconsistent with the criterion we now use.Exactly what you're saying, they happened to have the same objectsize. Hence sorting them would put them together, but since we compare the refname's the "HEAD" ref would come before "branch-two".
Quoted 3 lines
Update it to match the new world order, which we can now depend on being stable.
Quoted 6 lines
Quoted 2 lines
I am not sure about "HEAD" and "branch-two" in the above (it may be comparison between "HEAD" and "refs/heads/branch-two", for example).
It actually is, we consider "refs/heads/branch-two rather then the shortened version of this. It makes sense to classify refs this way, even though this was a side effect of this commit.
Now these are enough bits of info, that can and needs to be condenced into an updated log message to help future readers.
Thanks.
Quoted 30 lines · Junio C Hamano
Quoted 28 lines · Karthik Nayak
Quoted 9 lines · Junio C Hamano
Quoted 3 lines
Hence, fallback to alphabetical comparison based on the refname whenever the other criterion is equal. Fix the test in t3203 in this regard.
It is unclear what "in this regard" is. Do you mean this (I am not suggesting you to spell these out in a very detailed way in the final log message; I am deliberately being detailed here to help me understand what you really mean)?
Quoted 7 lines
A test in t3203 was expecting that branch-two sorts before HEAD, which happened to be how qsort(3) on Linux sorted the array, but
(1) that outcome was not even guaranteed, and (2) once we start breaking ties with the refname, "HEAD" should sort before "branch-two" so the original expectation was inconsistent with the criterion we now use.Exactly what you're saying, they happened to have the same objectsize. Hence sorting them would put them together, but since we compare the refname's the "HEAD" ref would come before "branch-two".
Quoted 5 lines
Update it to match the new world order, which we can now depend on being stable.
I am not sure about "HEAD" and "branch-two" in the above (it may be comparison between "HEAD" and "refs/heads/branch-two", for example).
Quoted 8 lines
Quoted 3 lines
It actually is, we consider "refs/heads/branch-two rather then the shortened version of this. It makes sense to classify refs this way, even though this was a side effect of this commit.
Now these are enough bits of info, that can and needs to be condenced into an updated log message to help future readers.
Thanks.
Will update and send, thanks :)
Signature · 2 lines
Regards, Karthik Nayak