threads / patch / 15307

patchAdd --filedirstat diff option

Subject: [PATCH] Add --filedirstat diff option

## tl;dr

12 messages between Sep 1, 2008 and Sep 3, 2008. Diffs are folded; open one to read it.

replies: 11people: 4as markdown or json

Heikki Orsila· Sep 1, 2008, 01:12 UTC · lore

--filedirstat is the same as --dirstat, but it counts "damaged files" instead of "damaged lines" (lines that are added or removed).

Signed-off-by: Heikki Orsila <heikki.orsila@iki.fi>
---
Example of Linux v2.6.25..v2.6.26:
$ git diff --filedirstat v2.6.25..v2.6.26 
   3.3% arch/arm/
   6.0% arch/powerpc/
   3.8% arch/x86/
  12.1% arch/
   3.4% drivers/media/video/
   6.8% drivers/net/
  26.5% drivers/
   6.4% fs/
   4.5% include/linux/
  13.0% include/
   5.9% net/
$ git diff --dirstat v2.6.25..v2.6.26 
   4.9% arch/arm/
   9.0% arch/powerpc/configs/
  14.6% arch/
   5.0% drivers/media/video/
   4.2% drivers/media/
   5.5% drivers/net/sk98lin/
   6.6% drivers/net/wireless/
   5.7% drivers/net/
   4.8% drivers/s390/net/
  17.8% drivers/
   6.4% include/
   5.1% net/
 Documentation/diff-options.txt |    3 +++
 diff.c                         |   11 +++++++++--
 diff.h                         |    1 +
 3 files changed, 13 insertions(+), 2 deletions(-)
Show changes to 3 files +13 −2

Documentation/diff-options.txt, diff.c, diff.h

diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 1759386..6e84f40 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -66,6 +66,9 @@ endif::git-format-patch[]
 	the "--cumulative" flag, which adds up percentages recursively
 	even when they have been already reported for a sub-directory.
 
+--filedirstat[=limit]::
+	Same as --dirstat, but count changed files instead of lines.
+
 --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 135dec4..48f33d6 100644
--- a/diff.c
+++ b/diff.c
@@ -1110,9 +1110,13 @@ static void show_dirstat(struct diff_options *options)
 		/*
 		 * Original minus copied is the removed material,
 		 * added is the new material.  They are both damages
-		 * made to the preimage.
+		 * made to the preimage. In --filedirstat mode, count
+		 * damaged files, not damaged lines. This is done by
+		 * counting only a single damaged line per file.
 		 */
 		damage = (p->one->size - copied) + added;
+		if (options->filedirstat && damage > 0)
+			damage = 1;
 
 		ALLOC_GROW(dir.files, dir.nr + 1, dir.alloc);
 		dir.files[dir.nr].name = name;
@@ -2474,7 +2478,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
 		options->output_format |= DIFF_FORMAT_DIRSTAT;
 	else if (!strcmp(arg, "--cumulative"))
 		options->output_format |= DIFF_FORMAT_CUMULATIVE;
-	else if (!strcmp(arg, "--check"))
+	else if (opt_arg(arg, 'X', "filedirstat", &options->dirstat_percent)) {
+		options->output_format |= DIFF_FORMAT_DIRSTAT;
+		options->filedirstat = 1;
+	} else if (!strcmp(arg, "--check"))
 		options->output_format |= DIFF_FORMAT_CHECKDIFF;
 	else if (!strcmp(arg, "--summary"))
 		options->output_format |= DIFF_FORMAT_SUMMARY;
diff --git a/diff.h b/diff.h
index 50fb5dd..2832bb8 100644
--- a/diff.h
+++ b/diff.h
@@ -86,6 +86,7 @@ struct diff_options {
 	int rename_limit;
 	int warn_on_too_large_rename;
 	int dirstat_percent;
+	int filedirstat;
 	int setup;
 	int abbrev;
 	const char *prefix;
-- 
1.6.0.1
Junio C Hamano· Sep 2, 2008, 06:57 UTC · re: Heikki Orsila · lore

Re: [PATCH] Add --filedirstat diff option

Heikki Orsila <heikki.orsila@iki.fi> writes:
Show 8 quoted lines
> @@ -2474,7 +2478,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
>  		options->output_format |= DIFF_FORMAT_DIRSTAT;
>  	else if (!strcmp(arg, "--cumulative"))
>  		options->output_format |= DIFF_FORMAT_CUMULATIVE;
> -	else if (!strcmp(arg, "--check"))
> +	else if (opt_arg(arg, 'X', "filedirstat", &options->dirstat_percent)) {
> +		options->output_format |= DIFF_FORMAT_DIRSTAT;
> +		options->filedirstat = 1;

Why 'X'? It would never match, confusing to the reader, and risks a sudden change in behaviour when these statements are reordered or somebody mechanically attempts to convert this to parse_options().

Heikki Orsila· Sep 2, 2008, 11:58 UTC · re: Junio C Hamano · lore

Re: [PATCH] Add --filedirstat diff option

On Mon, Sep 01, 2008 at 11:57:46PM -0700, Junio C Hamano wrote:
Show 14 quoted lines
> Heikki Orsila <heikki.orsila@iki.fi> writes:
> 
> > @@ -2474,7 +2478,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
> >  		options->output_format |= DIFF_FORMAT_DIRSTAT;
> >  	else if (!strcmp(arg, "--cumulative"))
> >  		options->output_format |= DIFF_FORMAT_CUMULATIVE;
> > -	else if (!strcmp(arg, "--check"))
> > +	else if (opt_arg(arg, 'X', "filedirstat", &options->dirstat_percent)) {
> > +		options->output_format |= DIFF_FORMAT_DIRSTAT;
> > +		options->filedirstat = 1;
> 
> Why 'X'?  It would never match, confusing to the reader, and risks a
> sudden change in behaviour when these statements are reordered or somebody
> mechanically attempts to convert this to parse_options().

This is embarrassing.. I just copied the previous "dirstat" line.. *grin*

Anyway, what about the concept of filedirstat? Is it agreeable?
-- 
Heikki Orsila
heikki.orsila@iki.fi
http://www.iki.fi/shd
Junio C Hamano· Sep 2, 2008, 23:40 UTC · re: Heikki Orsila · lore

Re: [PATCH] Add --filedirstat diff option

Heikki Orsila <shd@modeemi.fi> writes:
Show 20 quoted lines
> On Mon, Sep 01, 2008 at 11:57:46PM -0700, Junio C Hamano wrote:
>> Heikki Orsila <heikki.orsila@iki.fi> writes:
>> 
>> > @@ -2474,7 +2478,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
>> >  		options->output_format |= DIFF_FORMAT_DIRSTAT;
>> >  	else if (!strcmp(arg, "--cumulative"))
>> >  		options->output_format |= DIFF_FORMAT_CUMULATIVE;
>> > -	else if (!strcmp(arg, "--check"))
>> > +	else if (opt_arg(arg, 'X', "filedirstat", &options->dirstat_percent)) {
>> > +		options->output_format |= DIFF_FORMAT_DIRSTAT;
>> > +		options->filedirstat = 1;
>> 
>> Why 'X'?  It would never match, confusing to the reader, and risks a
>> sudden change in behaviour when these statements are reordered or somebody
>> mechanically attempts to convert this to parse_options().
>
> This is embarrassing.. I just copied the previous "dirstat" line.. 
> *grin*
>
> Anyway, what about the concept of filedirstat? Is it agreeable?
I am neutral.

I do not think the additional code hurts anybody, so I wouldn't say I do not want to have the patch anywhere near my tree, but on the other hand, personally I do not find the feature as interesting or useful as dirstat.

Maybe there are many others who do find this option useful.  I dunno.
Junio C Hamano· Sep 2, 2008, 23:55 UTC · re: Junio C Hamano · lore

Re: [PATCH] Add --filedirstat diff option

Junio C Hamano <gitster@pobox.com> writes:
Show 30 quoted lines
> Heikki Orsila <shd@modeemi.fi> writes:
>
>> On Mon, Sep 01, 2008 at 11:57:46PM -0700, Junio C Hamano wrote:
>>> Heikki Orsila <heikki.orsila@iki.fi> writes:
>>> 
>>> > @@ -2474,7 +2478,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
>>> >  		options->output_format |= DIFF_FORMAT_DIRSTAT;
>>> >  	else if (!strcmp(arg, "--cumulative"))
>>> >  		options->output_format |= DIFF_FORMAT_CUMULATIVE;
>>> > -	else if (!strcmp(arg, "--check"))
>>> > +	else if (opt_arg(arg, 'X', "filedirstat", &options->dirstat_percent)) {
>>> > +		options->output_format |= DIFF_FORMAT_DIRSTAT;
>>> > +		options->filedirstat = 1;
>>> 
>>> Why 'X'?  It would never match, confusing to the reader, and risks a
>>> sudden change in behaviour when these statements are reordered or somebody
>>> mechanically attempts to convert this to parse_options().
>>
>> This is embarrassing.. I just copied the previous "dirstat" line.. 
>> *grin*
>>
>> Anyway, what about the concept of filedirstat? Is it agreeable?
>
> I am neutral.
>
> I do not think the additional code hurts anybody, so I wouldn't say I do
> not want to have the patch anywhere near my tree, but on the other hand,
> personally I do not find the feature as interesting or useful as dirstat.
>
> Maybe there are many others who do find this option useful.  I dunno.

While I was thinking about potential issues before queuing this, I realized that I forgot to mention one thing.

The name.

"filedirstat" is simply too long to type, and it has a certain "Huh?" factor --- is it about file, or is it about directory?

This option essentially is just the dirstat but with different logic to compute how big the damage is. Conceptually, the original one gives one "damage point" to each added or deleted line.

        $ git show --dirstat=<one-point-per-line>

and yours awards one point to each file, whatever the size of the damage is.

        $ git show --dirstat=<one-point-per-file>

I cannot come up with a short-and-sweet name for one-point-per-X offhand, but expressing this variant as an option to --dirstat will leave the door open for other people to come up with different system to award damage points. Perhaps

	$ git show --dirstat=exclude-typofixes
might even be not just interesting but useful ;-)

Again, I mention this not because I want to reject the patch, but because I hope other people with better UI taste may come up with an alternative before I finish handling other patches.

Heikki Orsila· Sep 3, 2008, 00:08 UTC · re: Junio C Hamano · lore

Re: [PATCH] Add --filedirstat diff option

On Tue, Sep 02, 2008 at 04:55:39PM -0700, Junio C Hamano wrote:
Show 26 quoted lines
> realized that I forgot to mention one thing.
> 
> The name.
> 
> "filedirstat" is simply too long to type, and it has a certain "Huh?"
> factor --- is it about file, or is it about directory?
> 
> This option essentially is just the dirstat but with different logic to
> compute how big the damage is.  Conceptually, the original one gives one
> "damage point" to each added or deleted line.
> 
>         $ git show --dirstat=<one-point-per-line>
> 
> and yours awards one point to each file, whatever the size of the damage
> is.
> 
>         $ git show --dirstat=<one-point-per-file>
> 
> I cannot come up with a short-and-sweet name for one-point-per-X offhand,
> but expressing this variant as an option to --dirstat will leave the door
> open for other people to come up with different system to award damage
> points.  Perhaps
> 
> 	$ git show --dirstat=exclude-typofixes
> 
> might even be not just interesting but useful ;-)

I wouldn't add new semantics for --dirstat=x since it's easy to add new options. We already have --cumulative, so adding options is not new. How about "--dirstat --filemode"? It's long, but it is obvious. I don't think length is relevant here. A shorter but obscure syntax would be "--dirstat2" :-)

-- 
Heikki Orsila
heikki.orsila@iki.fi
http://www.iki.fi/shd
Junio C Hamano· Sep 3, 2008, 00:28 UTC · re: Heikki Orsila · lore

Re* [PATCH] Add --filedirstat diff option

Heikki Orsila <shd@modeemi.fi> writes:
Show 5 quoted lines
> I wouldn't add new semantics for --dirstat=x since it's easy to add 
> new options. We already have --cumulative, so adding options is not 
> new. How about "--dirstat --filemode"? It's long, but it is obvious. I 
> don't think length is relevant here. A shorter but obscure syntax would 
> be "--dirstat2" :-) 

I wouldn't actually buy "easy to add" argument. Following the easiest-to-implement path down often result in inconsistent and messy UI.

IOW, I may use that expression from time to time like: "while it may be easy to add another option, that would lead to many options that depend on other options, with a messy end result", in a negative sense.

But you are right to point out that --cumulative is an option that affects how --dirstat operates. And I think the option parsing of that code is buggy. It should imply --dirstat, shouldn't it?

So I do not mind --filemode or whatever option that is expressed as a word on the command line separate from --dirstat, but we really should consider this and --cumulative conceptually a sub-option to --dirstat.

Here is a sample patch to fix --cumulative (but of course it is untested); I think your --filemode (or whatever its final name is) should hook into the same place as this patch touches, as far as command line parsing is concerned.

-- >8 -- diff --cumulative is a sub-option of --dirstat

The option used to be implemented as if it is a totally independent one, but "git diff --cumulative" would not mean anything without "--dirstat".

This makes --cumulative imply --dirstat.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 diff.c |    9 ++++++---
 diff.h |    2 +-
 2 files changed, 7 insertions(+), 4 deletions(-)
Show changes to diff +7 −4
diff --git c/diff.c w/diff.c
index 135dec4..cbd151b 100644
--- c/diff.c
+++ w/diff.c
@@ -1078,7 +1078,7 @@ static void show_dirstat(struct diff_options *options)
 	dir.alloc = 0;
 	dir.nr = 0;
 	dir.percent = options->dirstat_percent;
-	dir.cumulative = options->output_format & DIFF_FORMAT_CUMULATIVE;
+	dir.cumulative = DIFF_OPT_TST(options, DIRSTAT_CUMULATIVE);
 
 	changed = 0;
 	for (i = 0; i < q->nr; i++) {
@@ -2300,6 +2300,7 @@ void diff_setup(struct diff_options *options)
 	options->break_opt = -1;
 	options->rename_limit = -1;
 	options->dirstat_percent = 3;
+	DIFF_OPT_CLR(options, DIRSTAT_CUMULATIVE);
 	options->context = 3;
 
 	options->change = diff_change;
@@ -2472,8 +2473,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
 		options->output_format |= DIFF_FORMAT_SHORTSTAT;
 	else if (opt_arg(arg, 'X', "dirstat", &options->dirstat_percent))
 		options->output_format |= DIFF_FORMAT_DIRSTAT;
-	else if (!strcmp(arg, "--cumulative"))
-		options->output_format |= DIFF_FORMAT_CUMULATIVE;
+	else if (!strcmp(arg, "--cumulative")) {
+		options->output_format |= DIFF_FORMAT_DIRSTAT;
+		DIFF_OPT_SET(options, DIRSTAT_CUMULATIVE);
+	}
 	else if (!strcmp(arg, "--check"))
 		options->output_format |= DIFF_FORMAT_CHECKDIFF;
 	else if (!strcmp(arg, "--summary"))
diff --git c/diff.h w/diff.h
index 50fb5dd..7f53beb 100644
--- c/diff.h
+++ w/diff.h
@@ -31,7 +31,6 @@ typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
 #define DIFF_FORMAT_PATCH	0x0010
 #define DIFF_FORMAT_SHORTSTAT	0x0020
 #define DIFF_FORMAT_DIRSTAT	0x0040
-#define DIFF_FORMAT_CUMULATIVE	0x0080
 
 /* These override all above */
 #define DIFF_FORMAT_NAME	0x0100
@@ -64,6 +63,7 @@ typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
 #define DIFF_OPT_CHECK_FAILED        (1 << 16)
 #define DIFF_OPT_RELATIVE_NAME       (1 << 17)
 #define DIFF_OPT_IGNORE_SUBMODULES   (1 << 18)
+#define DIFF_OPT_DIRSTAT_CUMULATIVE  (1 << 19)
 #define DIFF_OPT_TST(opts, flag)    ((opts)->flags & DIFF_OPT_##flag)
 #define DIFF_OPT_SET(opts, flag)    ((opts)->flags |= DIFF_OPT_##flag)
 #define DIFF_OPT_CLR(opts, flag)    ((opts)->flags &= ~DIFF_OPT_##flag)
Heikki Orsila· Sep 3, 2008, 00:39 UTC · re: Junio C Hamano · lore

Re: Re* [PATCH] Add --filedirstat diff option

On Tue, Sep 02, 2008 at 05:28:59PM -0700, Junio C Hamano wrote:
> But you are right to point out that --cumulative is an option that affects
> how --dirstat operates.  And I think the option parsing of that code is
> buggy.  It should imply --dirstat, shouldn't it?
Yes.
> Here is a sample patch to fix --cumulative (but of course it is untested);
> I think your --filemode (or whatever its final name is) should hook into
> the same place as this patch touches, as far as command line parsing is
> concerned.
I'll prepare something later today..
-- 
Heikki Orsila
heikki.orsila@iki.fi
http://www.iki.fi/shd
Jeff King· Sep 3, 2008, 00:12 UTC · re: Junio C Hamano · lore

Re: [PATCH] Add --filedirstat diff option

On Tue, Sep 02, 2008 at 04:55:39PM -0700, Junio C Hamano wrote:
> "filedirstat" is simply too long to type, and it has a certain "Huh?"
> factor --- is it about file, or is it about directory?
I had the same thought when I saw the original patch...
Show 5 quoted lines
> This option essentially is just the dirstat but with different logic to
> compute how big the damage is.  Conceptually, the original one gives one
> "damage point" to each added or deleted line.
> 
>         $ git show --dirstat=<one-point-per-line>
...and I thought of --dirstat-byfile. So maybe:
  --dirstat=byfile
and
  --dirstat=byline
defaulting to byline (or by-line if preferred).
-Peff
Heikki Orsila· Sep 3, 2008, 00:18 UTC · re: Jeff King · lore

Re: [PATCH] Add --filedirstat diff option

On Tue, Sep 02, 2008 at 08:12:54PM -0400, Jeff King wrote:
> ...and I thought of --dirstat-byfile. So maybe:

I like --dirstat-byfile more than --dirstat=byfile as dirstat already takes a cut-off percent parameter.

-- 
Heikki Orsila
heikki.orsila@iki.fi
http://www.iki.fi/shd
Junio C Hamano· Sep 3, 2008, 00:44 UTC · re: Jeff King · lore

Re: [PATCH] Add --filedirstat diff option

Jeff King <peff@peff.net> writes:
Show 22 quoted lines
> On Tue, Sep 02, 2008 at 04:55:39PM -0700, Junio C Hamano wrote:
>
>> "filedirstat" is simply too long to type, and it has a certain "Huh?"
>> factor --- is it about file, or is it about directory?
>
> I had the same thought when I saw the original patch...
>
>> This option essentially is just the dirstat but with different logic to
>> compute how big the damage is.  Conceptually, the original one gives one
>> "damage point" to each added or deleted line.
>> 
>>         $ git show --dirstat=<one-point-per-line>
>
> ...and I thought of --dirstat-byfile. So maybe:
>
>   --dirstat=byfile
>
> and
>
>   --dirstat=byline
>
> defaulting to byline (or by-line if preferred).

As Heikki points out (and I missed this initially myself), --dirstat[=x] already exists and it gives the cut-off-point.

Perhaps "--dirstat-by-file" that implies "--dirstat" (with the understanding (and documentation) that "--dirstat" is a shorthand for "--dirstat-by-line" that does not exist)?

Jeff King· Sep 3, 2008, 12:47 UTC · re: Junio C Hamano · lore

Re: [PATCH] Add --filedirstat diff option

On Tue, Sep 02, 2008 at 05:44:55PM -0700, Junio C Hamano wrote:
> Perhaps "--dirstat-by-file" that implies "--dirstat" (with the
> understanding (and documentation) that "--dirstat" is a shorthand for
> "--dirstat-by-line" that does not exist)?
Makes sense to me.
-Peff

← back to recent threads