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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Johannes Schindelin <Johannes.Schindelin@xxxxxx> 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";
}

-
: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]