Skip to contentSkip to conversation

ref-filter: fallback on alphabetical comparison

PATCH Superseded Karthik Nayak 2 participants 3 messages Jun 15, 2016

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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 listting 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
index 046e73b..7b33cb8 100644
@@ -1698,7 +1698,7 @@ static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, stru
 		if (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
index f77971c..9f2d482 100755
@@ -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
#1 lore raw
Quoted 5 lines · Karthik Nayak

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 listting refs with equal values cannot be pre-determined) as

s/listting/listing/

Quoted 42 lines

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
index 046e73b..7b33cb8 100644
@@ -1698,7 +1698,7 @@ static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, stru
                if (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
index f77971c..9f2d482 100755
@@ -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

#2 lore raw
Quoted 8 lines · Eric Sunshine
Quoted 5 lines · Karthik Nayak

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 listting refs with equal values cannot be pre-determined) as

s/listting/listing/

Thanks for pointing out. Should I re-roll?

Signature · 2 lines
Regards,
Karthik Nayak