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

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

From
Junio C Hamano <junkio@cox.net>
Date
Apr 15, 2006, 12:33 UTC
Message-ID
<7v64lbggrd.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.63.0604151340210.24303@wbgn013.biozentrum.uni-wuerzburg.de>
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";
}
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 4 of 6 in “diff-options: add --patch-with-stat”
  1. diff-options: add --patch-with-statJohannes Schindelin, Apr 15, 2006
  2. Marco CostalbaApr 15, 2006
  3. Johannes SchindelinApr 15, 2006
  4. Junio C HamanoApr 15, 2006
  5. Johannes SchindelinApr 15, 2006
  6. Marco CostalbaApr 15, 2006

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.