{"thread":{"id":"40675","subject":"[PATCH v4] ref-filter: fallback on alphabetical comparison","startedAt":"2015-10-30T08:45:28Z","lastAt":"2015-10-30T22:54:12Z","messageCount":3,"participants":["Karthik Nayak","Johannes Sixt","Junio C Hamano"],"isPatch":true,"patchVersion":4,"patchTotal":null},"messages":[{"id":"272520","messageId":"1446194728-7944-1-git-send-email-Karthik.188@gmail.com","threadId":"40675","inReplyTo":null,"subject":"[PATCH v4] ref-filter: fallback on alphabetical comparison","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2015-10-30T08:45:28Z","receivedAt":"2015-10-30T08:45:28Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"In ref-filter.c the comparison of refs while sorting is handled by\ncmp_ref_sorting() function. When sorting as per numerical values\n(e.g. --sort=objectsize) there is no fallback comparison when both\nrefs hold the same value. This can cause unexpected results (i.e. the\norder of listing refs with equal values cannot be pre-determined) as\npointed out by Johannes Sixt ($gmane/280117).\n\nHence, fallback to alphabetical comparison based on the refname\nwhenever the other criterion is equal.\n\nA test in t3203 was expecting that branch-two sorts before HEAD, which\nhappened to be how qsort(3) on Linux sorted the array, but (1) that\noutcome was not even guaranteed, and (2) once we start breaking ties\nwith the refname, \"HEAD\" should sort before \"branch-two\" so the\noriginal expectation was inconsistent with the criterion we now use.\n\nUpdate it to match the new world order, which we can now depend on\nbeing stable.\n\nHelped-by: Junio C Hamano <gitster@pobox.com>\nReported-by: Johannes Sixt <j6t@kdbg.org>\nSigned-off-by: Karthik Nayak <Karthik.188@gmail.com>\n---\n ref-filter.c             | 2 +-\n t/t3203-branch-output.sh | 2 +-\n 2 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 046e73b..7b33cb8 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -1698,7 +1698,7 @@ static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, stru\n \t\tif (va->ul < vb->ul)\n \t\t\tcmp = -1;\n \t\telse if (va->ul == vb->ul)\n-\t\t\tcmp = 0;\n+\t\t\tcmp = strcmp(a->refname, b->refname);\n \t\telse\n \t\t\tcmp = 1;\n \t}\ndiff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh\nindex f77971c..9f2d482 100755\n--- a/t/t3203-branch-output.sh\n+++ b/t/t3203-branch-output.sh\n@@ -158,8 +158,8 @@ EOF\n \n test_expect_success 'git branch `--sort` option' '\n \tcat >expect <<-\\EOF &&\n-\t  branch-two\n \t* (HEAD detached from fromtag)\n+\t  branch-two\n \t  branch-one\n \t  master\n \tEOF\n-- \n2.6.2\n"},{"id":"272595","messageId":"5633F489.60008@kdbg.org","threadId":"40675","inReplyTo":"1446194728-7944-1-git-send-email-Karthik.188@gmail.com","subject":"Re: [PATCH v4] ref-filter: fallback on alphabetical comparison","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2015-10-30T22:51:53Z","receivedAt":"2015-10-30T22:51:53Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 30.10.2015 um 09:45 schrieb Karthik Nayak:\n> In ref-filter.c the comparison of refs while sorting is handled by\n> cmp_ref_sorting() function. When sorting as per numerical values\n> (e.g. --sort=objectsize) there is no fallback comparison when both\n> refs hold the same value. This can cause unexpected results (i.e. the\n> order of listing refs with equal values cannot be pre-determined) as\n> pointed out by Johannes Sixt ($gmane/280117).\n>\n> Hence, fallback to alphabetical comparison based on the refname\n> whenever the other criterion is equal.\n>\n> A test in t3203 was expecting that branch-two sorts before HEAD, which\n> happened to be how qsort(3) on Linux sorted the array, but (1) that\n> outcome was not even guaranteed, and (2) once we start breaking ties\n> with the refname, \"HEAD\" should sort before \"branch-two\" so the\n> original expectation was inconsistent with the criterion we now use.\n>\n> Update it to match the new world order, which we can now depend on\n> being stable.\n\nNeedless to say that the patch fixes the test failure on Windows. (I \ntested v2 of the patch.)\n\n-- Hannes\n"},{"id":"272596","messageId":"xmqq1tccj7cb.fsf@gitster.mtv.corp.google.com","threadId":"40675","inReplyTo":"5633F489.60008@kdbg.org","subject":"Re: [PATCH v4] ref-filter: fallback on alphabetical comparison","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-10-30T22:54:12Z","receivedAt":"2015-10-30T22:54:12Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Sixt <j6t@kdbg.org> writes:\n\n>> Update it to match the new world order, which we can now depend on\n>> being stable.\n>\n> Needless to say that the patch fixes the test failure on Windows. (I\n> tested v2 of the patch.)\n\nThanks, both.  Queued.\n"}]}