From: Karthik Nayak <karthik.188@gmail.com>
To: Eric Sunshine <sunshine@sunshineco.com>
Cc: Git List <git@vger.kernel.org>,
Christian Couder <christian.couder@gmail.com>,
Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Subject: Re: [PATCH v3 4/9] ref-filter: add support to sort by version
Date: Mon, 20 Jul 2015 22:04:57 +0530 [thread overview]
Message-ID: <CAOLa=ZR8d37s4rHuDuASzb_YEs-UBRN0AiY2scEJQe+jFdGxEA@mail.gmail.com> (raw)
In-Reply-To: <CAPig+cRkwy_Dq3oYgHdNH6naaUDHZ_6DPopec1EG3aNwz56rzA@mail.gmail.com>
On Mon, Jul 20, 2015 at 7:09 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
>
> To agree with the actual code: s/version_cmp/versioncmp/
>
Yeah! will change.
>
> Assuming I'm a reader without prior knowledge, the first question
> which pops into my mind is "what's the difference between
> 'version:refname' and 'v:refname'?" Is one just shorthand for the
> other, or is there some subtle difference in behavior, or what? The
> documentation should explain this better.
>
Will include more explanation.
> Also, why are there parentheses around 'version:refname' or
> 'v:refname'? And, you should use backticks rather than apostrophes, as
> is done with the other field names.
>
Wanted to show that they are the same command. Seems confusing now that
you mentioned, will change it.
>> In any case, a field name that refers to a field inapplicable to
>> the object referred by the ref does not cause an error. It
>> diff --git a/ref-filter.c b/ref-filter.c
>> index 82731ac..85c561e 100644
>> --- a/ref-filter.c
>> +++ b/ref-filter.c
>> @@ -1169,18 +1170,22 @@ static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, stru
>>
>> get_ref_atom_value(a, s->atom, &va);
>> get_ref_atom_value(b, s->atom, &vb);
>> - switch (cmp_type) {
>> - case FIELD_STR:
>> - cmp = strcmp(va->s, vb->s);
>> - break;
>> - default:
>> - if (va->ul < vb->ul)
>> - cmp = -1;
>> - else if (va->ul == vb->ul)
>> - cmp = 0;
>> - else
>> - cmp = 1;
>> - break;
>> + if (s->version)
>> + cmp = versioncmp(va->s, vb->s);
>> + else {
>> + switch (cmp_type) {
>> + case FIELD_STR:
>> + cmp = strcmp(va->s, vb->s);
>> + break;
>> + default:
>> + if (va->ul < vb->ul)
>> + cmp = -1;
>> + else if (va->ul == vb->ul)
>> + cmp = 0;
>> + else
>> + cmp = 1;
>> + break;
>> + }
>
> The logic might be slightly easier to follow, and give a much less
> noisy diff if you rewrite it like this instead:
>
> if (s->version)
> cmp = versioncmp(va->s, vb->s);
> else if (cmp_type == FIELD_STR)
> cmp = strcmp(va->s, vb->s);
> else {
> if (va->ul < vb->ul)
> cmp = -1;
> else if (va->ul == vb->ul)
> cmp = 0;
> else
> cmp = 1;
> }
>
> Or, if you don't mind a noisy diff, you can outdent the other branches, as well:
>
> if (s->version)
> cmp = versioncmp(va->s, vb->s);
> else if (cmp_type == FIELD_STR)
> cmp = strcmp(va->s, vb->s);
> else if (va->ul < vb->ul)
> cmp = -1;
> else if (va->ul == vb->ul)
> cmp = 0;
> else
> cmp = 1;
>
> (I rather prefer the latter, despite the noisy diff.)
>
Err! just didn't want to existing code. Your latter code usage seems
easier and simpler to follow. Will use that thanks :D
>> }
>> return (s->reverse) ? -cmp : cmp;
>> }
>> diff --git a/ref-filter.h b/ref-filter.h
>> index 7dfdea0..6f1646b 100644
>> --- a/ref-filter.h
>> +++ b/ref-filter.h
>> @@ -25,7 +25,7 @@ struct atom_value {
>> struct ref_sorting {
>> struct ref_sorting *next;
>> int atom; /* index into used_atom array (internal) */
>> - unsigned reverse : 1;
>> + unsigned reverse : 1, version : 1;
>
> This is difficult to read. Style elsewhere (if I'm not mistaken) is to
> place the declaration on a line by itself.
>
Yes just checked, thats the style. Thank you.
>> };
>>
>> struct ref_array_item {
>> diff --git a/t/t6302-for-each-ref-filter.sh b/t/t6302-for-each-ref-filter.sh
>> index 505a360..c31fd2f 100755
>> --- a/t/t6302-for-each-ref-filter.sh
>> +++ b/t/t6302-for-each-ref-filter.sh
>> @@ -81,4 +81,30 @@ test_expect_success 'filtering with --contains' '
>> test_cmp expect actual
>> '
>>
>> +test_expect_success 'version sort' '
>> + git tag -l --sort=version:refname | grep "foo" >actual &&
>> + cat >expect <<-\EOF &&
>> + foo1.3
>> + foo1.6
>> + foo1.10
>> + EOF
>> + test_cmp expect actual
>> +'
>> +
>> +test_expect_success 'reverse version sort' '
>> + git tag -l --sort=-version:refname | grep "foo" >actual &&
>
> Maybe use 'v:refname' in one of these tests in order to exercise that
> alias as well?
>
The idea was to only include a minimal test as t7004 has tests for the same,
but I guess a minimal test for 'v:refname' is also required.
--
Regards,
Karthik Nayak
next prev parent reply other threads:[~2015-07-20 16:35 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-18 19:12 [PATCH v3 0/9] Port tag.c to use ref-filter APIs Karthik Nayak
2015-07-18 19:12 ` [PATCH v3 1/9] ref-filter: add option to align atoms to the left Karthik Nayak
2015-07-19 23:49 ` Eric Sunshine
2015-07-20 15:06 ` Karthik Nayak
2015-07-20 16:12 ` Junio C Hamano
2015-07-20 17:47 ` Eric Sunshine
2015-07-20 16:37 ` Junio C Hamano
2015-07-20 17:04 ` Karthik Nayak
2015-07-20 17:22 ` Karthik Nayak
2015-07-20 18:01 ` Eric Sunshine
2015-07-20 18:23 ` Karthik Nayak
2015-07-20 17:29 ` Junio C Hamano
2015-07-21 18:00 ` Karthik Nayak
2015-07-22 18:44 ` Matthieu Moy
2015-07-23 14:32 ` Karthik Nayak
2015-07-18 19:12 ` [PATCH v3 2/9] ref-filter: add option to filter only tags Karthik Nayak
2015-07-18 19:12 ` [PATCH v3 3/9] ref-filter: support printing N lines from tag annotation Karthik Nayak
2015-07-20 0:02 ` Eric Sunshine
2015-07-20 15:17 ` Karthik Nayak
2015-07-18 19:12 ` [PATCH v3 4/9] ref-filter: add support to sort by version Karthik Nayak
2015-07-20 1:39 ` Eric Sunshine
2015-07-20 16:34 ` Karthik Nayak [this message]
2015-07-18 19:12 ` [PATCH v3 5/9] ref-filter: add option to match literal pattern Karthik Nayak
2015-07-20 6:24 ` Eric Sunshine
2015-07-20 8:01 ` Christian Couder
2015-07-20 18:12 ` Eric Sunshine
2015-07-21 19:27 ` Karthik Nayak
2015-07-22 19:20 ` Matthieu Moy
2015-07-18 19:12 ` [PATCH v3 6/9] tag.c: use 'ref-filter' data structures Karthik Nayak
2015-07-18 22:00 ` [PATCH v3 7/9] tag.c: use 'ref-filter' APIs Karthik Nayak
2015-07-18 22:00 ` [PATCH v3 8/9] tag.c: implement '--format' option Karthik Nayak
2015-07-22 19:38 ` Matthieu Moy
2015-07-18 22:00 ` [PATCH v3 9/9] tag.c: implement '--merged' and '--no-merged' options Karthik Nayak
2015-07-19 19:20 ` Christian Couder
2015-07-21 19:28 ` Karthik Nayak
2015-07-22 19:40 ` Matthieu Moy
2015-07-23 16:20 ` Karthik Nayak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAOLa=ZR8d37s4rHuDuASzb_YEs-UBRN0AiY2scEJQe+jFdGxEA@mail.gmail.com' \
--to=karthik.188@gmail.com \
--cc=Matthieu.Moy@grenoble-inp.fr \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).