git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] tag: use skip_prefix instead of magic numbers
@ 2014-07-11 17:24 Jacob Keller
  2014-07-11 17:24 ` [PATCH 2/3] tag: fix --sort tests to use cat<<-\EOF format Jacob Keller
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Jacob Keller @ 2014-07-11 17:24 UTC (permalink / raw)
  To: git; +Cc: Jacob Keller

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

Authored-by: Jeff King <peff@peff.net>
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
---
 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

^ permalink raw reply related	[flat|nested] 18+ messages in thread
* [PATCH 1/3] tag: use skip_prefix instead of magic numbers
@ 2014-07-11 20:51 Jacob Keller
  2014-07-11 20:51 ` [PATCH 2/3] tag: fix --sort tests to use cat<<-\EOF format Jacob Keller
  0 siblings, 1 reply; 18+ messages in thread
From: Jacob Keller @ 2014-07-11 20:51 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Jacob Keller

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

^ permalink raw reply related	[flat|nested] 18+ messages in thread
* [PATCH 1/3] tag: use skip_prefix instead of magic numbers
@ 2014-07-11 21:38 Jacob Keller
  2014-07-11 21:38 ` [PATCH 2/3] tag: fix --sort tests to use cat<<-\EOF format Jacob Keller
  0 siblings, 1 reply; 18+ messages in thread
From: Jacob Keller @ 2014-07-11 21:38 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Jacob Keller

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>
---
 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

^ permalink raw reply related	[flat|nested] 18+ messages in thread
* [PATCH 1/3] tag: use skip_prefix instead of magic numbers
@ 2014-07-11 22:55 Jacob Keller
  2014-07-11 22:55 ` [PATCH 2/3] tag: fix --sort tests to use cat<<-\EOF format Jacob Keller
  0 siblings, 1 reply; 18+ messages in thread
From: Jacob Keller @ 2014-07-11 22:55 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Jacob Keller

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 issue with patch in that we dropped the reset to STRCMP_SORT, discovered
by Junio.

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

diff --git a/builtin/tag.c b/builtin/tag.c
index ef765563388c..9d7643f127e7 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:")) {
+
+	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
+	else
 		*sort = STRCMP_SORT;
+
 	if (strcmp(arg, "refname"))
 		die(_("unsupported sort specification %s"), arg);
 	*sort |= flags;
-- 
2.0.1.475.g9b8d714

^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2014-07-14 22:08 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-11 17:24 [PATCH 1/3] tag: use skip_prefix instead of magic numbers Jacob Keller
2014-07-11 17:24 ` [PATCH 2/3] tag: fix --sort tests to use cat<<-\EOF format Jacob Keller
2014-07-11 17:24 ` [PATCH 3/3 v5] tag: support configuring --sort via .gitconfig Jacob Keller
2014-07-11 17:46   ` Jeff King
2014-07-11 18:11     ` Keller, Jacob E
2014-07-11 18:22       ` Jeff King
2014-07-11 20:36         ` Keller, Jacob E
2014-07-11 21:54     ` Junio C Hamano
2014-07-11 22:12       ` Keller, Jacob E
2014-07-12  1:17       ` Jeff King
2014-07-13 17:01         ` Junio C Hamano
2014-07-14 22:08           ` Keller, Jacob E
2014-07-11 17:50 ` [PATCH 1/3] tag: use skip_prefix instead of magic numbers Jeff King
2014-07-11 18:04   ` Keller, Jacob E
2014-07-11 18:42   ` Junio C Hamano
  -- strict thread matches above, loose matches on Subject: below --
2014-07-11 20:51 Jacob Keller
2014-07-11 20:51 ` [PATCH 2/3] tag: fix --sort tests to use cat<<-\EOF format Jacob Keller
2014-07-11 21:38 [PATCH 1/3] tag: use skip_prefix instead of magic numbers Jacob Keller
2014-07-11 21:38 ` [PATCH 2/3] tag: fix --sort tests to use cat<<-\EOF format Jacob Keller
2014-07-11 22:55 [PATCH 1/3] tag: use skip_prefix instead of magic numbers Jacob Keller
2014-07-11 22:55 ` [PATCH 2/3] tag: fix --sort tests to use cat<<-\EOF format Jacob Keller

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).