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

[PATCH 03/21] diff.c: convert --dirstat and friends

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Feb 7, 2019, 10:33 UTC
Message-ID
<20190207103326.10693-4-pclouds@gmail.com>
In-Reply-To
<20190207103326.10693-1-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/diff-options.txt |  7 ++++++
 diff.c                         | 39 +++++++++++++++++++++++++---------
 2 files changed, 36 insertions(+), 10 deletions(-)
diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 0711734b12..058d93ec4f 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -148,6 +148,7 @@ These parameters can also be set individually with `--stat-width=<width>`,
 	number of modified files, as well as number of added and deleted
 	lines.
 
+-X<param1,param2,...>::
 --dirstat[=<param1,param2,...>]::
 	Output the distribution of relative amount of changes for each
 	sub-directory. The behavior of `--dirstat` can be customized by
@@ -192,6 +193,12 @@ directories with less than 10% of the total amount of changed files,
 and accumulating child directory counts in the parent directories:
 `--dirstat=files,10,cumulative`.
 
+--cumulative::
+	Synonym for --dirstat=cumulative
+
+--dirstat-by-file[=<param1,param2>...]::
+	Synonym for --dirstat=files,param1,param2...
+
 --summary::
 	Output a condensed summary of extended header information
 	such as creations, renames and mode changes.
diff --git a/diff.c b/diff.c
index 419b6ac4ae..1cdbe8e688 100644
--- a/diff.c
+++ b/diff.c
@@ -4867,6 +4867,22 @@ static int parse_objfind_opt(struct diff_options *opt, const char *arg)
 	return 1;
 }
 
+static int diff_opt_dirstat(const struct option *opt,
+			    const char *arg, int unset)
+{
+	struct diff_options *options = opt->value;
+
+	BUG_ON_OPT_NEG(unset);
+	if (!strcmp(opt->long_name, "cumulative")) {
+		if (arg)
+			BUG("how come --cumulative take a value?");
+		arg = "cumulative";
+	} else if (!strcmp(opt->long_name, "dirstat-by-file"))
+		parse_dirstat_opt(options, "files");
+	parse_dirstat_opt(options, arg ? arg : "");
+	return 0;
+}
+
 static int diff_opt_unified(const struct option *opt,
 			    const char *arg, int unset)
 {
@@ -4911,6 +4927,18 @@ static void prep_parse_options(struct diff_options *options)
 		OPT_BIT_F(0, "shortstat", &options->output_format,
 			  N_("output only the last line of --stat"),
 			  DIFF_FORMAT_SHORTSTAT, PARSE_OPT_NONEG),
+		OPT_CALLBACK_F('X', "dirstat", options, N_("<param1,param2>..."),
+			       N_("output the distribution of relative amount of changes for each sub-directory"),
+			       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
+			       diff_opt_dirstat),
+		OPT_CALLBACK_F(0, "cumulative", options, NULL,
+			       N_("synonym for --dirstat=cumulative"),
+			       PARSE_OPT_NONEG | PARSE_OPT_NOARG,
+			       diff_opt_dirstat),
+		OPT_CALLBACK_F(0, "dirstat-by-file", options, N_("<param1,param2>..."),
+			       N_("synonym for --dirstat=files,param1,param2..."),
+			       PARSE_OPT_NONEG | PARSE_OPT_OPTARG,
+			       diff_opt_dirstat),
 		OPT_END()
 	};
 
@@ -4939,16 +4967,7 @@ int diff_opt_parse(struct diff_options *options,
 		return ac;
 
 	/* Output format options */
-	if (skip_prefix(arg, "-X", &arg) ||
-		 skip_to_optional_arg(arg, "--dirstat", &arg))
-		return parse_dirstat_opt(options, arg);
-	else if (!strcmp(arg, "--cumulative"))
-		return parse_dirstat_opt(options, "cumulative");
-	else if (skip_to_optional_arg(arg, "--dirstat-by-file", &arg)) {
-		parse_dirstat_opt(options, "files");
-		return parse_dirstat_opt(options, arg);
-	}
-	else if (!strcmp(arg, "--check"))
+	if (!strcmp(arg, "--check"))
 		options->output_format |= DIFF_FORMAT_CHECKDIFF;
 	else if (!strcmp(arg, "--summary"))
 		options->output_format |= DIFF_FORMAT_SUMMARY;
-- 
2.20.1.682.gd5861c6d90
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 4 of 80 in “nd/diff-parseopt part 2”
  1. 00/21 nd/diff-parseopt part 2Nguyễn Thái Ngọc Duy, Feb 7, 2019
  2. 01/21 diff.c: convert --patch-with-rawNguyễn Thái Ngọc Duy, Feb 7, 2019
  3. 02/21 diff.c: convert --numstat and --shortstatNguyễn Thái Ngọc Duy, Feb 7, 2019
  4. 03/21 diff.c: convert --dirstat and friendsNguyễn Thái Ngọc Duy, Feb 7, 2019
  5. 04/21 diff.c: convert --checkNguyễn Thái Ngọc Duy, Feb 7, 2019
  6. 05/21 diff.c: convert --summaryNguyễn Thái Ngọc Duy, Feb 7, 2019
  7. 06/21 diff.c: convert --patch-with-statNguyễn Thái Ngọc Duy, Feb 7, 2019
  8. 07/21 diff.c: convert --name-onlyNguyễn Thái Ngọc Duy, Feb 7, 2019
  9. 08/21 diff.c: convert --name-statusNguyễn Thái Ngọc Duy, Feb 7, 2019
  10. 09/21 diff.c: convert -s|--no-patchNguyễn Thái Ngọc Duy, Feb 7, 2019
  11. 10/21 diff.c: convert --stat*Nguyễn Thái Ngọc Duy, Feb 7, 2019
  12. 11/21 diff.c: convert --[no-]compact-summaryNguyễn Thái Ngọc Duy, Feb 7, 2019
  13. 12/21 diff.c: convert --output-*Nguyễn Thái Ngọc Duy, Feb 7, 2019
  14. 13/21 diff.c: convert -B|--break-rewritesNguyễn Thái Ngọc Duy, Feb 7, 2019
  15. 14/21 diff.c: convert -M|--find-renamesNguyễn Thái Ngọc Duy, Feb 7, 2019
  16. 15/21 diff.c: convert -D|--irreversible-deleteNguyễn Thái Ngọc Duy, Feb 7, 2019
  17. 16/21 diff.c: convert -C|--find-copiesNguyễn Thái Ngọc Duy, Feb 7, 2019
  18. 17/21 diff.c: convert --find-copies-harderNguyễn Thái Ngọc Duy, Feb 7, 2019
  19. 18/21 diff.c: convert --no-renames|--[no--rename-emptyNguyễn Thái Ngọc Duy, Feb 7, 2019
  20. 19/21 diff.c: convert --relativeNguyễn Thái Ngọc Duy, Feb 7, 2019
  21. 20/21 diff.c: convert --[no-]minimalNguyễn Thái Ngọc Duy, Feb 7, 2019
  22. 21/21 diff.c: convert --ignore-some-changesNguyễn Thái Ngọc Duy, Feb 7, 2019
  23. SZEDER GáborFeb 7, 2019
  24. Junio C HamanoFeb 11, 2019
  25. Junio C HamanoFeb 11, 2019
  26. 00/21 nd/diff-parseopt part 2Nguyễn Thái Ngọc Duy, Feb 16, 2019
  27. 01/21 diff-parseopt: convert --patch-with-rawNguyễn Thái Ngọc Duy, Feb 16, 2019
  28. 02/21 diff-parseopt: convert --numstat and --shortstatNguyễn Thái Ngọc Duy, Feb 16, 2019
  29. 03/21 diff-parseopt: convert --dirstat and friendsNguyễn Thái Ngọc Duy, Feb 16, 2019
  30. 04/21 diff-parseopt: convert --checkNguyễn Thái Ngọc Duy, Feb 16, 2019
  31. 05/21 diff-parseopt: convert --summaryNguyễn Thái Ngọc Duy, Feb 16, 2019
  32. 06/21 diff-parseopt: convert --patch-with-statNguyễn Thái Ngọc Duy, Feb 16, 2019
  33. Junio C HamanoFeb 20, 2019
  34. 00/21 nd/diff-parseopt part 2Nguyễn Thái Ngọc Duy, Feb 16, 2019
  35. 01/21 diff-parseopt: convert --patch-with-rawNguyễn Thái Ngọc Duy, Feb 16, 2019
  36. Junio C HamanoFeb 20, 2019
  37. 02/21 diff-parseopt: convert --numstat and --shortstatNguyễn Thái Ngọc Duy, Feb 16, 2019
  38. 03/21 diff-parseopt: convert --dirstat and friendsNguyễn Thái Ngọc Duy, Feb 16, 2019
  39. Andrei RybakFeb 17, 2019
  40. 04/21 diff-parseopt: convert --checkNguyễn Thái Ngọc Duy, Feb 16, 2019
  41. 05/21 diff-parseopt: convert --summaryNguyễn Thái Ngọc Duy, Feb 16, 2019
  42. 06/21 diff-parseopt: convert --patch-with-statNguyễn Thái Ngọc Duy, Feb 16, 2019
  43. 07/21 diff-parseopt: convert --name-onlyNguyễn Thái Ngọc Duy, Feb 16, 2019
  44. 08/21 diff-parseopt: convert --name-statusNguyễn Thái Ngọc Duy, Feb 16, 2019
  45. 09/21 diff-parseopt: convert -s|--no-patchNguyễn Thái Ngọc Duy, Feb 16, 2019
  46. 10/21 diff-parseopt: convert --stat*Nguyễn Thái Ngọc Duy, Feb 16, 2019
  47. Junio C HamanoFeb 20, 2019
  48. 11/21 diff-parseopt: convert --[no-]compact-summaryNguyễn Thái Ngọc Duy, Feb 16, 2019
  49. 12/21 diff-parseopt: convert --output-*Nguyễn Thái Ngọc Duy, Feb 16, 2019
  50. 13/21 diff-parseopt: convert -B|--break-rewritesNguyễn Thái Ngọc Duy, Feb 16, 2019
  51. 14/21 diff-parseopt: convert -M|--find-renamesNguyễn Thái Ngọc Duy, Feb 16, 2019
  52. 15/21 diff-parseopt: convert -D|--irreversible-deleteNguyễn Thái Ngọc Duy, Feb 16, 2019
  53. 16/21 diff-parseopt: convert -C|--find-copiesNguyễn Thái Ngọc Duy, Feb 16, 2019
  54. 17/21 diff-parseopt: convert --find-copies-harderNguyễn Thái Ngọc Duy, Feb 16, 2019
  55. 18/21 diff-parseopt: convert --no-renames|--[no--rename-emptyNguyễn Thái Ngọc Duy, Feb 16, 2019
  56. 19/21 diff-parseopt: convert --relativeNguyễn Thái Ngọc Duy, Feb 16, 2019
  57. 20/21 diff-parseopt: convert --[no-]minimalNguyễn Thái Ngọc Duy, Feb 16, 2019
  58. 21/21 diff-parseopt: convert --ignore-some-changesNguyễn Thái Ngọc Duy, Feb 16, 2019
  59. 00/21 nd/diff-parseopt-2 updatesNguyễn Thái Ngọc Duy, Feb 21, 2019
  60. 01/21 diff-parseopt: convert --patch-with-rawNguyễn Thái Ngọc Duy, Feb 21, 2019
  61. 02/21 diff-parseopt: convert --numstat and --shortstatNguyễn Thái Ngọc Duy, Feb 21, 2019
  62. 03/21 diff-parseopt: convert --dirstat and friendsNguyễn Thái Ngọc Duy, Feb 21, 2019
  63. 04/21 diff-parseopt: convert --checkNguyễn Thái Ngọc Duy, Feb 21, 2019
  64. 05/21 diff-parseopt: convert --summaryNguyễn Thái Ngọc Duy, Feb 21, 2019
  65. 06/21 diff-parseopt: convert --patch-with-statNguyễn Thái Ngọc Duy, Feb 21, 2019
  66. 07/21 diff-parseopt: convert --name-onlyNguyễn Thái Ngọc Duy, Feb 21, 2019
  67. 08/21 diff-parseopt: convert --name-statusNguyễn Thái Ngọc Duy, Feb 21, 2019
  68. 09/21 diff-parseopt: convert -s|--no-patchNguyễn Thái Ngọc Duy, Feb 21, 2019
  69. 10/21 diff-parseopt: convert --stat*Nguyễn Thái Ngọc Duy, Feb 21, 2019
  70. 11/21 diff-parseopt: convert --[no-]compact-summaryNguyễn Thái Ngọc Duy, Feb 21, 2019
  71. 12/21 diff-parseopt: convert --output-*Nguyễn Thái Ngọc Duy, Feb 21, 2019
  72. 13/21 diff-parseopt: convert -B|--break-rewritesNguyễn Thái Ngọc Duy, Feb 21, 2019
  73. 14/21 diff-parseopt: convert -M|--find-renamesNguyễn Thái Ngọc Duy, Feb 21, 2019
  74. 15/21 diff-parseopt: convert -D|--irreversible-deleteNguyễn Thái Ngọc Duy, Feb 21, 2019
  75. 16/21 diff-parseopt: convert -C|--find-copiesNguyễn Thái Ngọc Duy, Feb 21, 2019
  76. 17/21 diff-parseopt: convert --find-copies-harderNguyễn Thái Ngọc Duy, Feb 21, 2019
  77. 18/21 diff-parseopt: convert --no-renames|--[no--rename-emptyNguyễn Thái Ngọc Duy, Feb 21, 2019
  78. 19/21 diff-parseopt: convert --relativeNguyễn Thái Ngọc Duy, Feb 21, 2019
  79. 20/21 diff-parseopt: convert --[no-]minimalNguyễn Thái Ngọc Duy, Feb 21, 2019
  80. 21/21 diff-parseopt: convert --ignore-some-changesNguyễn Thái Ngọc Duy, Feb 21, 2019

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.