Re: [PATCH v2] tag: support configuring --sort via .gitconfig

Subsystems: the rest

3 messages, 3 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH v2] tag: support configuring --sort via .gitconfig

From: Junio C Hamano <hidden>
Date: 2016-06-15 23:01:52

Jeff King [off-list ref] writes:
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.
-- >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.

Signed-off-by: Jeff King <redacted>

 builtin/tag.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/builtin/tag.c b/builtin/tag.c
index c6e8a71..1101c19 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -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;

Re: [PATCH v2] tag: support configuring --sort via .gitconfig

From: Jeff King <hidden>
Date: 2016-06-15 23:01:52

On Thu, Jul 10, 2014 at 10:59:36AM -0700, Junio C Hamano wrote:
Jeff King [off-list ref] writes:
quoted
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.
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

Re: [PATCH v2] tag: support configuring --sort via .gitconfig

From: "Keller, Jacob E" <jacob.e.keller@intel.com>
Date: 2016-06-15 23:01:52

On Thu, 2014-07-10 at 15:34 -0400, Jeff King wrote:
On Thu, Jul 10, 2014 at 10:59:36AM -0700, Junio C Hamano wrote:
quoted
Jeff King [off-list ref] writes:
quoted
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.
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help