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

[PATCH 3/5] diff: parse detached options --stat-width n, --stat-name-width n

From
Matthieu Moy <matthieu.moy@imag.fr>
Date
Jul 29, 2010, 08:20 UTC
Message-ID
<1280391629-30017-4-git-send-email-Matthieu.Moy@imag.fr>
In-Reply-To
<1280391629-30017-1-git-send-email-Matthieu.Moy@imag.fr>
Part of a campaign for unstuck forms of options.
[jn: with some refactoring]
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 diff.c |   28 +++++++++++++++++++++++-----
 1 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/diff.c b/diff.c
index d5f5d4b..90b07e1 100644
--- a/diff.c
+++ b/diff.c
@@ -3035,16 +3035,34 @@ static int stat_opt(struct diff_options *options, const char **av)
 	char *end;
 	int width = options->stat_width;
 	int name_width = options->stat_name_width;
+	int argcount = 1;
 
 	arg += strlen("--stat");
 	end = (char *)arg;
 
 	switch (*arg) {
 	case '-':
-		if (!prefixcmp(arg, "-width="))
-			width = strtoul(arg + 7, &end, 10);
-		else if (!prefixcmp(arg, "-name-width="))
-			name_width = strtoul(arg + 12, &end, 10);
+		if (!prefixcmp(arg, "-width")) {
+			arg += strlen("-width");
+			if (*arg == '=')
+				width = strtoul(arg + 1, &end, 10);
+			else if (!*arg && !av[1])
+				die("Option '--stat-width' requires a value");
+			else if (!*arg) {
+				width = strtoul(av[1], &end, 10);
+				argcount = 2;
+			}
+		} else if (!prefixcmp(arg, "-name-width")) {
+			arg += strlen("-name-width");
+			if (*arg == '=')
+				name_width = strtoul(arg + 1, &end, 10);
+			else if (!*arg && !av[1])
+				die("Option '--stat-name-width' requires a value");
+			else if (!*arg) {
+				name_width = strtoul(av[1], &end, 10);
+				argcount = 2;
+			}
+		}
 		break;
 	case '=':
 		width = strtoul(arg+1, &end, 10);
@@ -3058,7 +3076,7 @@ static int stat_opt(struct diff_options *options, const char **av)
 	options->output_format |= DIFF_FORMAT_DIFFSTAT;
 	options->stat_name_width = name_width;
 	options->stat_width = width;
-	return 1;
+	return argcount;
 }
 
 int diff_opt_parse(struct diff_options *options, const char **av, int ac)
-- 
1.7.2.21.ge9796
Previous: Matthieu MoyNext: Matthieu Moy
Message 4 of 25 in “log and diff: accept detached forms (--option value)”
  1. 0/5 log and diff: accept detached forms (--option value)Matthieu Moy, Jul 29, 2010
  2. 1/5 diff: parse detached options like -S fooMatthieu Moy, Jul 29, 2010
  3. 2/5 diff: split off a function for --stat-* option parsingMatthieu Moy, Jul 29, 2010
  4. 3/5 diff: parse detached options --stat-width n, --stat-name-width nMatthieu Moy, Jul 29, 2010
  5. 4/5 log: parse detached options like git log --grep fooMatthieu Moy, Jul 29, 2010
  6. Jonathan NiederJul 29, 2010
  7. Matthieu MoyJul 30, 2010
  8. 1/5 diff: parse detached options like -S fooMatthieu Moy, Jul 30, 2010
  9. Junio C HamanoAug 2, 2010
  10. Matthieu MoyAug 2, 2010
  11. Jonathan NiederAug 2, 2010
  12. 2/5 diff: split off a function for --stat-* option parsingMatthieu Moy, Jul 30, 2010
  13. 3/5 diff: parse detached options --stat-width n, --stat-name-width nMatthieu Moy, Jul 30, 2010
  14. Junio C HamanoAug 2, 2010
  15. Matthieu MoyAug 2, 2010
  16. 4/5 log: parse detached options like git log --grep fooMatthieu Moy, Jul 30, 2010
  17. Junio C HamanoAug 2, 2010
  18. Matthieu MoyAug 2, 2010
  19. Junio C HamanoAug 2, 2010
  20. Matthieu MoyAug 3, 2010
  21. Junio C HamanoAug 3, 2010
  22. Matthieu MoyAug 3, 2010
  23. Miles BaderAug 4, 2010
  24. 5/5 log: parse detached option for --globMatthieu Moy, Jul 30, 2010
  25. 5/5 log: parse detached option for --globMatthieu Moy, Jul 29, 2010

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.