git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/3] tag: use skip_prefix instead of magic numbers

From
Jacob Keller <jacob.e.keller@intel.com>
Date
Jul 11, 2014, 17:24 UTC
Message-ID
<1405099447-27555-1-git-send-email-jacob.e.keller@intel.com>

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
Next: Jacob Keller
Message 1 of 15 in “tag: use skip_prefix instead of magic numbers”
  1. 1/3 tag: use skip_prefix instead of magic numbersJacob Keller, Jul 11, 2014
  2. 2/3 tag: fix --sort tests to use cat<<-\EOF formatJacob Keller, Jul 11, 2014
  3. 3/3 tag: support configuring --sort via .gitconfigJacob Keller, Jul 11, 2014
  4. Jeff KingJul 11, 2014
  5. Keller, Jacob EJul 11, 2014
  6. Jeff KingJul 11, 2014
  7. Keller, Jacob EJul 11, 2014
  8. Junio C HamanoJul 11, 2014
  9. Keller, Jacob EJul 11, 2014
  10. Jeff KingJul 12, 2014
  11. Junio C HamanoJul 13, 2014
  12. Keller, Jacob EJul 14, 2014
  13. Jeff KingJul 11, 2014
  14. Keller, Jacob EJul 11, 2014
  15. Junio C HamanoJul 11, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.