tag: support configuring --sort via .gitconfig
PATCH v2 1/1 tag: support configuring --sort via .gitconfig
Add support for configuring default sort ordering for git tags. Command line option will override this configured value, using the exact same syntax.
---
Repost with changes suggested by Peff. These include fixing documentation to remove duplicatation, and having git-config reference git-tag. Directly assign a tag_sort global that we use for the config and option variable.
Documentation/config.txt | 6 +++++ Documentation/git-tag.txt | 1 + builtin/tag.c | 60 ++++++++++++++++++++++++++++++----------------- t/t7004-tag.sh | 21 +++++++++++++++++ 4 files changed, 67 insertions(+), 21 deletions(-)
Documentation/config.txt +6 -0
@@ -2354,6 +2354,12 @@ submodule.<name>.ignore:: "--ignore-submodules" option. The 'git submodule' commands are not affected by this setting. +tag.sort:: + This variable is used to control the sort ordering of tags. It is + interpreted precisely the same way as "--sort=<value>". If --sort is + given on the command line it will override the selection chosen in the + configuration. See linkgit:git-tag[1] for more details. + tar.umask:: This variable can be used to restrict the permission bits of tar archive entries. The default is 0002, which turns off the
Documentation/git-tag.txt +1 -0
@@ -317,6 +317,7 @@ include::date-formats.txt[] SEE ALSO -------- linkgit:git-check-ref-format[1]. +linkgit:git-config[1]. GIT ---
builtin/tag.c +39 -21
100 lines not on this page · raw message
t/t7004-tag.sh +21 -0
@@ -1423,6 +1423,27 @@ EOF test_cmp expect actual ' +test_expect_success 'configured lexical sort' ' + git config tag.sort "v:refname" && + git tag -l "foo*" >actual && + cat >expect <<EOF && +foo1.3 +foo1.6 +foo1.10 +EOF + test_cmp expect actual +' + +test_expect_success 'option override configured sort' ' + git tag -l --sort=-refname "foo*" >actual && + cat >expect <<EOF && +foo1.6 +foo1.3 +foo1.10 +EOF + test_cmp expect actual +' + run_with_limited_stack () { (ulimit -s 64 && "$@") }
Signature · 1 line
2.0.1.475.g9b8d714
Quoted 3 lines · Jacob Keller
Add support for configuring default sort ordering for git tags. Command line option will override this configured value, using the exact same syntax.
Thanks, this version looks pretty good to me. A few minor comments:
builtin/tag.c static const char tag_template_nocleanup[] = · line 381
Quoted 3 lines
builtin/tag.c +3
-0+if (!strcmp (var,"tag.sort" )) { + tag_sort =parse_sort_string (value); + }
Our style is to usually avoid braces for a one-liner. However, I think would actually make sense to "return 0" from this conditional.
t/t7004-tag.sh EOF · line 1428
Quoted 4 lines
t/t7004-tag.sh +3
-0+test_expect_success 'configured lexical sort' ' + git config tag.sort "v:refname" && + git tag -l "foo*" >actual &&
Please use:
test_config tag.sort "v:refname"
here, which will clean up the config value after the test ends (and thus not pollute any later tests).
Though you will need to add an extra "test_config" to the following test:
t/t7004-tag.sh EOF · line 1438
Quoted 3 lines
t/t7004-tag.sh +2
-0+test_expect_success 'option override configured sort' ' + git tag -l --sort=-refname "foo*" >actual &&
I think that's a good thing, though (it makes it more clear in the second test what is being tested, rather than relying on the state left by the previous test).
-Peff
Quoted 13 lines · Jacob Keller
(quoted diff) +13
-0+static int parse_sort_string(const char *arg) +{ + int sort = 0; + int flags = 0; + + if (*arg == '-') { + flags |= REVERSE_SORT; + arg++; + } + if (starts_with(arg, "version:")) { + sort = VERCMP_SORT; + arg += 8; + } else if (starts_with(arg, "v:")) {
Review
Quoted 10 lines
(quoted diff) +10
-0+ sort = VERCMP_SORT; + arg += 2; + } else + sort = STRCMP_SORT; + if (strcmp(arg, "refname")) + die(_("unsupported sort specification %s"), arg); + sort |= flags; + + return sort; +}
I know this is existing code you are moving, but I noticed it looks ripe for using skip_prefix. Perhaps while we are in the area we should do the following on top of your patch (I'd also be happy for it be squashed in, but that may be too much in one patch).
-- >8 --
Subject: [PATCH] tag: use skip_prefix instead of magic numbers
We can make the parsing of the --sort parameter a bit more readable by having skip_prefix keep our pointer up to date.
--- builtin/tag.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
builtin/tag.c +5 -9
@@ -353,18 +353,14 @@ static int parse_sort_string(const char *arg)int sort =0 ;int flags =0 ; -if (*arg =='-' ) { +if (skip_prefix (arg,"-" , &arg)) flags |=REVERSE_SORT ; - arg++; - } -if (starts_with (arg,"version:" )) { - sort =VERCMP_SORT ; - arg +=8 ; - }else if (starts_with (arg,"v:" )) { + +if (skip_prefix (arg,"version:" , &arg) ||skip_prefix (arg,"v:" , &arg)) sort =VERCMP_SORT ; - arg +=2 ; - }else +else sort =STRCMP_SORT ; +if (strcmp (arg,"refname" ))die (_ ("unsupported sort specification %s" ), arg); sort |= flags;
Signature · 1 line
2.0.0.566.gfe3e6b2
Quoted 22 lines · Jeff King
Quoted 20 lines · Jacob Keller
(quoted diff) +20
-0+static int parse_sort_string(const char *arg) +{ + int sort = 0; + int flags = 0; + + if (*arg == '-') { + flags |= REVERSE_SORT; + arg++; + } + if (starts_with(arg, "version:")) { + sort = VERCMP_SORT; + arg += 8; + } else if (starts_with(arg, "v:")) { + sort = VERCMP_SORT; + arg += 2; + } else + sort = STRCMP_SORT; + if (strcmp(arg, "refname")) + die(_("unsupported sort specification %s"), arg); + sort |= flags;
Quoted 9 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ + return sort; +}I know this is existing code you are moving, but I noticed it looks ripe for using
skip_prefix. Perhaps while we are in the area we should do the following on top of your patch (I'd also be happy for it be squashed in, but that may be too much in one patch).
I am fine with this being another patch or squashed in. I didn't even know that was available :) I also like putting the two equivalent conditionals into the same if block.
Thanks,
Jake
Quoted 39 lines
-- >8 --
Subject: [PATCH] tag: useskip_prefixinstead of magic numbersWe can make the parsing of the --sort parameter a bit more readable by having
skip_prefixkeep our pointer up to date.Signed-off-by Jeff King <[email protected]>--- builtin/tag.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)builtin/tag.c +5
-9@@ -353,18 +353,14 @@ static int parse_sort_string(const char *arg)int sort =0 ;int flags =0 ; -if (*arg =='-' ) { +if (skip_prefix (arg,"-" , &arg)) flags |=REVERSE_SORT ; - arg++; - } -if (starts_with (arg,"version:" )) { - sort =VERCMP_SORT ; - arg +=8 ; - }else if (starts_with (arg,"v:" )) { + +if (skip_prefix (arg,"version:" , &arg) ||skip_prefix (arg,"v:" , &arg)) sort =VERCMP_SORT ; - arg +=2 ; - }else +else sort =STRCMP_SORT ; +if (strcmp (arg,"refname" ))die (_ ("unsupported sort specification %s" ), arg); sort |= flags;
Quoted 4 lines · Jeff King
I know this is existing code you are moving, but I noticed it looks ripe for using
skip_prefix. Perhaps while we are in the area we should do the following on top of your patch (I'd also be happy for it be squashed in, but that may be too much in one patch).
I am tempted to suggest going the other way around, i.e. queue (an equivalent of) this on jk/skip-prefix and merge it to 'next' and then 'master' quickly.
I can go either way, but I tend to prefer building new things on top of obviously correct clean-up, not the other way around.
Quoted 7 lines
-- >8 --
Subject: [PATCH] tag: useskip_prefixinstead of magic numbersWe can make the parsing of the --sort parameter a bit more readable by having
skip_prefixkeep our pointer up to date.Signed-off-by Jeff King <[email protected]>
builtin/tag.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
builtin/tag.c +5 -9
@@ -524,18 +524,14 @@ static int parse_opt_sort(const struct option *opt, const char *arg, int unset)int *sort = opt->value;int flags =0 ; -if (*arg =='-' ) { +if (skip_prefix (arg,"-" , &arg)) flags |=REVERSE_SORT ; - arg++; - } -if (starts_with (arg,"version:" )) { - *sort =VERCMP_SORT ; - arg +=8 ; - }else if (starts_with (arg,"v:" )) { + +if (skip_prefix (arg,"version:" , &arg) ||skip_prefix (arg,"v:" , &arg)) *sort =VERCMP_SORT ; - arg +=2 ; - }else +else *sort =STRCMP_SORT ; +if (strcmp (arg,"refname" ))die (_ ("unsupported sort specification %s" ), arg); *sort |= flags;
Quoted 7 lines · Junio C Hamano
Quoted 4 lines · Jeff King
I know this is existing code you are moving, but I noticed it looks ripe for using
skip_prefix. Perhaps while we are in the area we should do the following on top of your patch (I'd also be happy for it be squashed in, but that may be too much in one patch).
Quoted 6 lines
I am tempted to suggest going the other way around, i.e. queue (an equivalent of) this on jk/skip-prefix and merge it to 'next' and then 'master' quickly.
I can go either way, but I tend to prefer building new things on top of obviously correct clean-up, not the other way around.
Me too. I just didn't want to make more work for Jacob (in having to rebase on top of mine) or for you (in having to do a non-obvious merge a few days from now).
-Peff
Quoted 13 lines · Jeff King
Quoted 11 lines · Junio C Hamano
Quoted 4 lines · Jeff King
I know this is existing code you are moving, but I noticed it looks ripe for using
skip_prefix. Perhaps while we are in the area we should do the following on top of your patch (I'd also be happy for it be squashed in, but that may be too much in one patch).I am tempted to suggest going the other way around, i.e. queue (an equivalent of) this on jk/skip-prefix and merge it to 'next' and then 'master' quickly.
Quoted 8 lines
Quoted 2 lines
I can go either way, but I tend to prefer building new things on top of obviously correct clean-up, not the other way around.
Me too. I just didn't want to make more work for Jacob (in having to rebase on top of mine) or for you (in having to do a non-obvious merge a few days from now).
-Peff
I'm perfectly fine rebasing. :)
Thanks,
Jake
Quoted 17 lines · Jacob E
Quoted 16 lines · Jeff King
Quoted 13 lines · Junio C Hamano
Quoted 4 lines · Jeff King
I know this is existing code you are moving, but I noticed it looks ripe for using
skip_prefix. Perhaps while we are in the area we should do the following on top of your patch (I'd also be happy for it be squashed in, but that may be too much in one patch).I am tempted to suggest going the other way around, i.e. queue (an equivalent of) this on jk/skip-prefix and merge it to 'next' and then 'master' quickly.
I can go either way, but I tend to prefer building new things on top of obviously correct clean-up, not the other way around.
Quoted 7 lines
Quoted 5 lines
Me too. I just didn't want to make more work for Jacob (in having to rebase on top of mine) or for you (in having to do a non-obvious merge a few days from now).
-Peff
I'm perfectly fine rebasing. :)
Alright, thanks.
I am still not ready to push out today's integration result, but when it happens, Peff's "tag: use skip_prefix" should appear at ce85604, as a direct follow-up to the tip of already merged jk/skip-prefix topic which was 67a31f61 (http-push: refactor parsing of remote object names, 2014-06-19).