threads / patch / 3877

patchdiff-options: add --patch-with-stat

Subject: [PATCH] diff-options: add --patch-with-stat

## tl;dr

6 messages between Apr 15, 2006 and Apr 15, 2006. Diffs are folded; open one to read it.

replies: 5people: 3as markdown or json

Johannes Schindelin· Apr 15, 2006, 11:41 UTC · lore
With this option, git prepends a diffstat in front of the patch.

Since I really, really do not know what a diffstat of a combined diff ("merge diff") should look like, the diffstat is not generated for these.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
	Buggeth, and you shall be given.
	BTW I really would like to have a diffstat for combined diffs.
	Any ideas?
 Documentation/diff-options.txt |    3 +++
 diff.c                         |   17 ++++++++++++++++-
 diff.h                         |    3 +++
 3 files changed, 22 insertions(+), 1 deletions(-)
c06cf94fe5a2f0b004e7b46c0322554e7ec4ff99
Show changes to 3 files +22 −1

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

diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 447e522..c183dc9 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -10,6 +10,9 @@
 --stat::
 	Generate a diffstat instead of a patch.
 
+--patch-with-stat::
+	Generate patch and prepend its diffstat.
+
 -z::
 	\0 line termination on output
 
diff --git a/diff.c b/diff.c
index f1b672d..1b33465 100644
--- a/diff.c
+++ b/diff.c
@@ -1049,6 +1049,10 @@ int diff_opt_parse(struct diff_options *
 	}
 	else if (!strcmp(arg, "--stat"))
 		options->output_format = DIFF_FORMAT_DIFFSTAT;
+	else if (!strcmp(arg, "--patch-with-stat")) {
+		options->output_format = DIFF_FORMAT_PATCH;
+		options->with_stat = 1;
+	}
 	else if (!strcmp(arg, "-z"))
 		options->line_termination = 0;
 	else if (!strncmp(arg, "-l", 2))
@@ -1518,7 +1522,7 @@ void diff_flush(struct diff_options *opt
 	int diff_output_format = options->output_format;
 	struct diffstat_t *diffstat = NULL;
 
-	if (diff_output_format == DIFF_FORMAT_DIFFSTAT) {
+	if (diff_output_format == DIFF_FORMAT_DIFFSTAT || options->with_stat) {
 		diffstat = xcalloc(sizeof (struct diffstat_t), 1);
 		diffstat->xm.consume = diffstat_consume;
 	}
@@ -1530,6 +1534,17 @@ void diff_flush(struct diff_options *opt
 		}
 		putchar(options->line_termination);
 	}
+	if (options->with_stat) {
+		for (i = 0; i < q->nr; i++) {
+			struct diff_filepair *p = q->queue[i];
+			flush_one_pair(p, DIFF_FORMAT_DIFFSTAT, options,
+					diffstat);
+		}
+		show_stats(diffstat);
+		free(diffstat);
+		diffstat = NULL;
+		putchar(options->line_termination);
+	}
 	for (i = 0; i < q->nr; i++) {
 		struct diff_filepair *p = q->queue[i];
 		flush_one_pair(p, diff_output_format, options, diffstat);
diff --git a/diff.h b/diff.h
index 2f8aff2..f783bae 100644
--- a/diff.h
+++ b/diff.h
@@ -25,6 +25,7 @@ struct diff_options {
 	const char *pickaxe;
 	unsigned recursive:1,
 		 with_raw:1,
+		 with_stat:1,
 		 tree_in_recursive:1,
 		 full_index:1;
 	int break_opt;
@@ -120,6 +121,8 @@ #define COMMON_DIFF_OPTIONS_HELP \
 "  --patch-with-raw\n" \
 "                output both a patch and the diff-raw format.\n" \
 "  --stat        show diffstat instead of patch.\n" \
+"  --patch-with-stat\n" \
+"                output a patch and prepend its diffstat.\n" \
 "  --name-only   show only names of changed files.\n" \
 "  --name-status show names and status of changed files.\n" \
 "  --full-index  show full object name on index lines.\n" \
-- 
1.3.0.rc4.ga1167e-dirty
Marco Costalba· Apr 15, 2006, 11:50 UTC · re: Johannes Schindelin · lore

Re: [PATCH] diff-options: add --patch-with-stat

On 4/15/06, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
>
> With this option, git prepends a diffstat in front of the patch.
>
Thanks!  qgit will set this as default!
Show 6 quoted lines
>
>         Buggeth, and you shall be given.
>
>         BTW I really would like to have a diffstat for combined diffs.
>         Any ideas?
>
Well..hem..why do not  count  the (shifted) + and - in the combined diffs ouput?
I suspect this can be a total idiocy, but now I'm missing why.  :-)
Marco
Johannes Schindelin· Apr 15, 2006, 11:56 UTC · re: Marco Costalba · lore

Re: [PATCH] diff-options: add --patch-with-stat

Hi,
On Sat, 15 Apr 2006, Marco Costalba wrote:
Show 7 quoted lines
> On 4/15/06, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
>
> >         BTW I really would like to have a diffstat for combined diffs.
> >         Any ideas?
> 
> Well..hem..why do not count the (shifted) + and - in the combined diffs 
> ouput?

This does not help. The combined diff is so useful, because it contains the information as to which parent has this difference, and which parent has not.

By just counting the plusses and minusses, this information is filtered out.

Ciao, Dscho

Junio C Hamano· Apr 15, 2006, 12:33 UTC · re: Johannes Schindelin · lore

Re: [PATCH] diff-options: add --patch-with-stat

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 	BTW I really would like to have a diffstat for combined diffs.
> 	Any ideas?

While I think combined diffs are somewhat overrated, I think what makes some sense would be to count --cc output for each parent's column, and show something like this:

 Makefile            | +-     +- 
 debian/changelog    | ++++++ ++++++++++++++++++++
 2 files changed, 7 and 91 insertions(+), 1 and 0 deletions(-)

This is for "diff-tree --cc v1.0.0"; the hand-merge (or evil merge) changed from first parent 7(+),1(-) and from second parent 91(+),0(-) respectively.

Count the maximum change per each parent (the above example the second file has the max for both parents but that may not always be the case), add them up to determine how many columns to allocate for each parent (while taking one column gap between each parent into account) and draw normally.

The code that counted this (I did not write code to draw it) is like this:

-- >8 -- #!/usr/bin/perl

use strict; my $filename; my $num_parents = -1; my %stat;

while (<>) {
	chomp;
	if (/^diff --cc (.*)$/) {
		$filename = $1;
		$stat{$filename} = undef;
		next;
	}
	if (/^(\@+) [-+0-9, ]* \1$/) {
		$num_parents = length($1) - 1;
		next;
	}
	next unless (/^([- +]{$num_parents})/);
	my @pfx = split('', $1);
	if (!defined $stat{$filename}) {
		$stat{$filename} = [];
		for (my $i = 0; $i < $num_parents; $i++) {
			push @{$stat{$filename}}, [0, 0];
		}
	}
	for (my $i = 0; $i < $num_parents; $i++) {
		if ($pfx[$i] eq '+') {
			$stat{$filename}[$i][0]++;
		}
		if ($pfx[$i] eq '-') {
			$stat{$filename}[$i][1]++;
		}
	}
}
for my $filename (sort keys %stat) {
	print "$filename	";
	for (my $i = 0; $i < $num_parents; $i++) {
		printf " +%d/-%d",
		$stat{$filename}[$i][0], $stat{$filename}[$i][1];
	}
	print "\n";
}
Johannes Schindelin· Apr 15, 2006, 12:37 UTC · re: Junio C Hamano · lore

Re: [PATCH] diff-options: add --patch-with-stat

Hi,
On Sat, 15 Apr 2006, Junio C Hamano wrote:
Show 12 quoted lines
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 
> > 	BTW I really would like to have a diffstat for combined diffs.
> > 	Any ideas?
> 
> While I think combined diffs are somewhat overrated, I think
> what makes some sense would be to count --cc output for each
> parent's column, and show something like this:
> 
>  Makefile            | +-     +- 
>  debian/changelog    | ++++++ ++++++++++++++++++++
>  2 files changed, 7 and 91 insertions(+), 1 and 0 deletions(-)
Okay. That is a start, altough it will look funny with 12 parents...
I'll do some hacking while you're sleeping.

Ciao, Dscho

Marco Costalba· Apr 15, 2006, 13:01 UTC · re: Johannes Schindelin · lore

Re: [PATCH] diff-options: add --patch-with-stat

On 4/15/06, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
Show 9 quoted lines
> Hi,
>
> On Sat, 15 Apr 2006, Junio C Hamano wrote:
>
> > Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> >
> > >     BTW I really would like to have a diffstat for combined diffs.
> > >     Any ideas?
> >
 Just another idea, from current git:
$ git-diff-tree -r -m --stat 4da8cbc23
4da8cbc234177d6a8cf749d4ef60bd05ec843898
---
 blame.c     |   20 ++++++++++++++------
 diff-tree.c |    2 +-
 diff.h      |    6 +++++-
 git.c       |   15 +++++++++++++--
 http-push.c |    1 +
 rev-list.c  |    1 +
 revision.c  |   26 ++++++++++++--------------
 revision.h  |    7 +++++--
 tree-diff.c |   46 +++++++++++++++++++++++++---------------------
 9 files changed, 77 insertions(+), 47 deletions(-)
4da8cbc234177d6a8cf749d4ef60bd05ec843898
---
 Documentation/diff-options.txt |    3 +
 Documentation/git-apply.txt    |    8 ++-
 Makefile                       |   14 ++++-
 apply.c                        |  123 ++++++++++++++++++++++++++++++++++------
 combine-diff.c                 |   12 ++++
 diff.c                         |   83 ++++++++++++++++-----------
 diff.h                         |    3 +
 http-fetch.c                   |    8 +--
 http-push.c                    |    6 +-
 9 files changed, 199 insertions(+), 61 deletions(-)

$ git-diff-tree -r -c 4da8cbc23 4da8cbc234177d6a8cf749d4ef60bd05ec843898 ::100644 100644 100644 c5372b984a457d0e5bddcf0b334a1a3cdc149cec cc7cc627c88d135c3f8d814449813e73c1ea3430 236095fc9a1a6ffc056be8616c0f83e4e8c7ec2f MM diff.h ::100644 100644 100644 994ee90035c4ae5e055df79cea8621d294190a3f aa0bc1f6f6a51fb39d54dc81b93805f86d19aa46 19a0f772e7bf729755c66ab38f5dfb64ae784f00 MM http-push.c

PROPOSED OUTPUT:
$ git-diff-tree -r -c --stat 4da8cbc23
4da8cbc234177d6a8cf749d4ef60bd05ec843898
---
 diff.h      |    6 +++++-
 http-push.c |    1 +
 2 files changed, 6 insertions(+), 1 deletions(-)
4da8cbc234177d6a8cf749d4ef60bd05ec843898
---
 diff.h      |    3 +++
 http-push.c |    6 +++---
 2 files changed, 6 insertions(+), 3 deletions(-)

I agree Junio ouput is nicer, this one is perhaps more consistent with git-diff-tree -m --stat output.

Marco

← back to recent threads