git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: pclouds@gmail.com
Cc: git@vger.kernel.org, gitster@pobox.com,
	"SZEDER Gábor" <szeder.dev@gmail.com>
Subject: [PATCH v2 03/21] diff-parseopt: convert --dirstat and friends
Date: Sat, 16 Feb 2019 18:33:28 +0700	[thread overview]
Message-ID: <20190216113346.25000-4-pclouds@gmail.com> (raw)
In-Reply-To: <20190216113346.25000-1-pclouds@gmail.com>

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.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.21.0.rc0.328.g0e39304f8d


  parent reply	other threads:[~2019-02-16 11:34 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-07 10:33 [PATCH 00/21] nd/diff-parseopt part 2 Nguyễn Thái Ngọc Duy
2019-02-07 10:33 ` [PATCH 01/21] diff.c: convert --patch-with-raw Nguyễn Thái Ngọc Duy
2019-02-07 10:33 ` [PATCH 02/21] diff.c: convert --numstat and --shortstat Nguyễn Thái Ngọc Duy
2019-02-07 10:33 ` [PATCH 03/21] diff.c: convert --dirstat and friends Nguyễn Thái Ngọc Duy
2019-02-07 10:33 ` [PATCH 04/21] diff.c: convert --check Nguyễn Thái Ngọc Duy
2019-02-07 10:33 ` [PATCH 05/21] diff.c: convert --summary Nguyễn Thái Ngọc Duy
2019-02-07 10:33 ` [PATCH 06/21] diff.c: convert --patch-with-stat Nguyễn Thái Ngọc Duy
2019-02-07 10:33 ` [PATCH 07/21] diff.c: convert --name-only Nguyễn Thái Ngọc Duy
2019-02-07 10:33 ` [PATCH 08/21] diff.c: convert --name-status Nguyễn Thái Ngọc Duy
2019-02-07 10:33 ` [PATCH 09/21] diff.c: convert -s|--no-patch Nguyễn Thái Ngọc Duy
2019-02-07 10:33 ` [PATCH 10/21] diff.c: convert --stat* Nguyễn Thái Ngọc Duy
2019-02-07 10:33 ` [PATCH 11/21] diff.c: convert --[no-]compact-summary Nguyễn Thái Ngọc Duy
2019-02-07 10:33 ` [PATCH 12/21] diff.c: convert --output-* Nguyễn Thái Ngọc Duy
2019-02-07 10:33 ` [PATCH 13/21] diff.c: convert -B|--break-rewrites Nguyễn Thái Ngọc Duy
2019-02-07 10:33 ` [PATCH 14/21] diff.c: convert -M|--find-renames Nguyễn Thái Ngọc Duy
2019-02-07 10:33 ` [PATCH 15/21] diff.c: convert -D|--irreversible-delete Nguyễn Thái Ngọc Duy
2019-02-07 10:33 ` [PATCH 16/21] diff.c: convert -C|--find-copies Nguyễn Thái Ngọc Duy
2019-02-07 10:33 ` [PATCH 17/21] diff.c: convert --find-copies-harder Nguyễn Thái Ngọc Duy
2019-02-07 10:33 ` [PATCH 18/21] diff.c: convert --no-renames|--[no--rename-empty Nguyễn Thái Ngọc Duy
2019-02-07 10:33 ` [PATCH 19/21] diff.c: convert --relative Nguyễn Thái Ngọc Duy
2019-02-07 10:33 ` [PATCH 20/21] diff.c: convert --[no-]minimal Nguyễn Thái Ngọc Duy
2019-02-07 10:33 ` [PATCH 21/21] diff.c: convert --ignore-some-changes Nguyễn Thái Ngọc Duy
2019-02-07 18:43 ` [PATCH 00/21] nd/diff-parseopt part 2 SZEDER Gábor
2019-02-11 17:12   ` Junio C Hamano
2019-02-11 18:35 ` Junio C Hamano
2019-02-16 11:33 ` [PATCH v2 " Nguyễn Thái Ngọc Duy
2019-02-16 11:33   ` [PATCH v2 01/21] diff-parseopt: convert --patch-with-raw Nguyễn Thái Ngọc Duy
2019-02-16 11:33   ` [PATCH v2 02/21] diff-parseopt: convert --numstat and --shortstat Nguyễn Thái Ngọc Duy
2019-02-16 11:33   ` Nguyễn Thái Ngọc Duy [this message]
2019-02-16 11:33   ` [PATCH v2 04/21] diff-parseopt: convert --check Nguyễn Thái Ngọc Duy
2019-02-16 11:33   ` [PATCH v2 05/21] diff-parseopt: convert --summary Nguyễn Thái Ngọc Duy
2019-02-16 11:33   ` [PATCH v2 06/21] diff-parseopt: convert --patch-with-stat Nguyễn Thái Ngọc Duy
2019-02-20 21:56   ` [PATCH v2 00/21] nd/diff-parseopt part 2 Junio C Hamano
2019-02-16 11:36 ` [PATCH v3 " Nguyễn Thái Ngọc Duy
2019-02-16 11:36   ` [PATCH v3 01/21] diff-parseopt: convert --patch-with-raw Nguyễn Thái Ngọc Duy
2019-02-20 20:41     ` Junio C Hamano
2019-02-16 11:36   ` [PATCH v3 02/21] diff-parseopt: convert --numstat and --shortstat Nguyễn Thái Ngọc Duy
2019-02-16 11:36   ` [PATCH v3 03/21] diff-parseopt: convert --dirstat and friends Nguyễn Thái Ngọc Duy
2019-02-17 13:39     ` Andrei Rybak
2019-02-16 11:36   ` [PATCH v3 04/21] diff-parseopt: convert --check Nguyễn Thái Ngọc Duy
2019-02-16 11:36   ` [PATCH v3 05/21] diff-parseopt: convert --summary Nguyễn Thái Ngọc Duy
2019-02-16 11:36   ` [PATCH v3 06/21] diff-parseopt: convert --patch-with-stat Nguyễn Thái Ngọc Duy
2019-02-16 11:36   ` [PATCH v3 07/21] diff-parseopt: convert --name-only Nguyễn Thái Ngọc Duy
2019-02-16 11:36   ` [PATCH v3 08/21] diff-parseopt: convert --name-status Nguyễn Thái Ngọc Duy
2019-02-16 11:36   ` [PATCH v3 09/21] diff-parseopt: convert -s|--no-patch Nguyễn Thái Ngọc Duy
2019-02-16 11:36   ` [PATCH v3 10/21] diff-parseopt: convert --stat* Nguyễn Thái Ngọc Duy
2019-02-20 21:08     ` Junio C Hamano
2019-02-16 11:36   ` [PATCH v3 11/21] diff-parseopt: convert --[no-]compact-summary Nguyễn Thái Ngọc Duy
2019-02-16 11:36   ` [PATCH v3 12/21] diff-parseopt: convert --output-* Nguyễn Thái Ngọc Duy
2019-02-16 11:36   ` [PATCH v3 13/21] diff-parseopt: convert -B|--break-rewrites Nguyễn Thái Ngọc Duy
2019-02-16 11:36   ` [PATCH v3 14/21] diff-parseopt: convert -M|--find-renames Nguyễn Thái Ngọc Duy
2019-02-16 11:36   ` [PATCH v3 15/21] diff-parseopt: convert -D|--irreversible-delete Nguyễn Thái Ngọc Duy
2019-02-16 11:36   ` [PATCH v3 16/21] diff-parseopt: convert -C|--find-copies Nguyễn Thái Ngọc Duy
2019-02-16 11:36   ` [PATCH v3 17/21] diff-parseopt: convert --find-copies-harder Nguyễn Thái Ngọc Duy
2019-02-16 11:36   ` [PATCH v3 18/21] diff-parseopt: convert --no-renames|--[no--rename-empty Nguyễn Thái Ngọc Duy
2019-02-16 11:36   ` [PATCH v3 19/21] diff-parseopt: convert --relative Nguyễn Thái Ngọc Duy
2019-02-16 11:36   ` [PATCH v3 20/21] diff-parseopt: convert --[no-]minimal Nguyễn Thái Ngọc Duy
2019-02-16 11:36   ` [PATCH v3 21/21] diff-parseopt: convert --ignore-some-changes Nguyễn Thái Ngọc Duy
2019-02-21 11:16   ` [PATCH v4 00/21] nd/diff-parseopt-2 updates Nguyễn Thái Ngọc Duy
2019-02-21 11:16     ` [PATCH v4 01/21] diff-parseopt: convert --patch-with-raw Nguyễn Thái Ngọc Duy
2019-02-21 11:16     ` [PATCH v4 02/21] diff-parseopt: convert --numstat and --shortstat Nguyễn Thái Ngọc Duy
2019-02-21 11:16     ` [PATCH v4 03/21] diff-parseopt: convert --dirstat and friends Nguyễn Thái Ngọc Duy
2019-02-21 11:16     ` [PATCH v4 04/21] diff-parseopt: convert --check Nguyễn Thái Ngọc Duy
2019-02-21 11:16     ` [PATCH v4 05/21] diff-parseopt: convert --summary Nguyễn Thái Ngọc Duy
2019-02-21 11:16     ` [PATCH v4 06/21] diff-parseopt: convert --patch-with-stat Nguyễn Thái Ngọc Duy
2019-02-21 11:16     ` [PATCH v4 07/21] diff-parseopt: convert --name-only Nguyễn Thái Ngọc Duy
2019-02-21 11:16     ` [PATCH v4 08/21] diff-parseopt: convert --name-status Nguyễn Thái Ngọc Duy
2019-02-21 11:16     ` [PATCH v4 09/21] diff-parseopt: convert -s|--no-patch Nguyễn Thái Ngọc Duy
2019-02-21 11:16     ` [PATCH v4 10/21] diff-parseopt: convert --stat* Nguyễn Thái Ngọc Duy
2019-02-21 11:16     ` [PATCH v4 11/21] diff-parseopt: convert --[no-]compact-summary Nguyễn Thái Ngọc Duy
2019-02-21 11:16     ` [PATCH v4 12/21] diff-parseopt: convert --output-* Nguyễn Thái Ngọc Duy
2019-02-21 11:16     ` [PATCH v4 13/21] diff-parseopt: convert -B|--break-rewrites Nguyễn Thái Ngọc Duy
2019-02-21 11:16     ` [PATCH v4 14/21] diff-parseopt: convert -M|--find-renames Nguyễn Thái Ngọc Duy
2019-02-21 11:16     ` [PATCH v4 15/21] diff-parseopt: convert -D|--irreversible-delete Nguyễn Thái Ngọc Duy
2019-02-21 11:16     ` [PATCH v4 16/21] diff-parseopt: convert -C|--find-copies Nguyễn Thái Ngọc Duy
2019-02-21 11:16     ` [PATCH v4 17/21] diff-parseopt: convert --find-copies-harder Nguyễn Thái Ngọc Duy
2019-02-21 11:16     ` [PATCH v4 18/21] diff-parseopt: convert --no-renames|--[no--rename-empty Nguyễn Thái Ngọc Duy
2019-02-21 11:16     ` [PATCH v4 19/21] diff-parseopt: convert --relative Nguyễn Thái Ngọc Duy
2019-02-21 11:16     ` [PATCH v4 20/21] diff-parseopt: convert --[no-]minimal Nguyễn Thái Ngọc Duy
2019-02-21 11:16     ` [PATCH v4 21/21] diff-parseopt: convert --ignore-some-changes Nguyễn Thái Ngọc Duy

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20190216113346.25000-4-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=szeder.dev@gmail.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).