git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jacob Keller <jacob.e.keller@intel.com>
To: git@vger.kernel.org
Cc: Jeff King <peff@peff.net>, Jacob Keller <jacob.e.keller@intel.com>
Subject: [PATCH 1/3] tag: use skip_prefix instead of magic numbers
Date: Fri, 11 Jul 2014 13:51:33 -0700	[thread overview]
Message-ID: <1405111895-17451-1-git-send-email-jacob.e.keller@intel.com> (raw)

From: Jeff King <peff@peff.net>

Make the parsing of the --sort parameter more readable by having
skip_prefix keep our pointer up to date.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
---
Fixed authorship. I don't expect this version to be taken, but it helps me in
review, and I figured it is good to send the whole series.

 builtin/tag.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/builtin/tag.c b/builtin/tag.c
index ef765563388c..7ccb6f3c581b 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -524,18 +524,12 @@ 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:")) {
+
+	if (skip_prefix(arg, "version:", &arg) || skip_prefix(arg, "v:", &arg))
 		*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;
-- 
2.0.1.475.g9b8d714

             reply	other threads:[~2014-07-11 20:51 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-11 20:51 Jacob Keller [this message]
2014-07-11 20:51 ` [PATCH 2/3] tag: fix --sort tests to use cat<<-\EOF format Jacob Keller
2014-07-11 20:51 ` [PATCH 3/3] tag: support configuring --sort via .gitconfig Jacob Keller
2014-07-11 20:54   ` Keller, Jacob E
2014-07-11 21:06   ` Jeff King
2014-07-11 21:08     ` Keller, Jacob E
2014-07-11 22:17     ` Junio C Hamano
2014-07-11 22:30       ` Keller, Jacob E
  -- strict thread matches above, loose matches on Subject: below --
2014-07-11 22:55 [PATCH 1/3] tag: use skip_prefix instead of magic numbers Jacob Keller
2014-07-12  1:02 ` Jeff King
2014-07-11 21:38 Jacob Keller
2014-07-11 22:44 ` Junio C Hamano
2014-07-11 22:47   ` Keller, Jacob E
2014-07-11 17:24 Jacob Keller
2014-07-11 17:50 ` Jeff King
2014-07-11 18:04   ` Keller, Jacob E
2014-07-11 18:42   ` Junio C Hamano

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1405111895-17451-1-git-send-email-jacob.e.keller@intel.com \
    --to=jacob.e.keller@intel.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /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.
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 NNTP newsgroup(s).