# [PATCH] gitweb: Do not show difftree for merges in "commit" view

3 messages from 2006-12-15 to 2006-12-15. Participants: Jakub Narebski, Shawn Pearce.
Thread: https://gitlist.dev/t/43324

## Jakub Narebski, 2006-12-15 15:57

Subject: Re: Avoiding uninteresting merges in Cairo
Message-ID: <200612151657.06909.jnareb@gmail.com>
URL: https://gitlist.dev/e/200612151657.06909.jnareb%40gmail.com
In-Reply-To: <20061215150130.GB17860@spearce.org>

```
Shawn Pearce wrote:
> Jakub Narebski <jnareb@gmail.com> wrote:
>> Carl Worth wrote:
>> 
>>> On Thu, 14 Dec 2006 22:25:30 -0500, Shawn Pearce wrote:
>> 
>>>>  * gitweb made it appear as though a whole lot of Carl's recent
>>>>    work was somehow undone in the merge.
>>> 
>>> That looks like a simple gitweb bug. None of the other tools, (gitk,
>>> git log -p), consider a trivial merge commit like this as having
>>> anything interesting in it worth displaying.
>> 
>> It's not a bug, it is rather lack of feature (or misfeature).
> 
> Its a bug.
> 
> I'm not a gitweb user (meaning I almost never look at something
> in gitweb).  But I'm clearly also not a Git newbie.  ;-)
> 
> I could not fathom why that merge commit was being displayed that
> way in gitweb.  I had to clone the cairo project just so I could
> actually look at the commit with log/show/whatchanged/diff-tree,
> because I couldn't believe what I was seeing from gitweb.

Do you mean "commit" view or "commitdiff" view in gitweb for merges
is confusing?

If it is "commit" view, it is fairly easy to remove difftree/whatchanged
output below commit message for merges. However while git-show nor 
git-diff-tree doesn't show diff for merge messages, the diftree output
in "commit" view might be taken as 'damages'; git diff --summary always
takes summary of diff against first parent.

If it is "commitdiff" view... well, I plan on adding combined diff 
output to commitdiff, but I need raw (whatchanged) output with the
same files which would be shown in git-diff --cc for merges (compact
combined diff output). Otherwise I'd have to use combined (-c) output
in gitweb, rather than more terse --cc output.

-- 
Jakub Narebski

```

## Shawn Pearce, 2006-12-15 16:03

Subject: Re: Avoiding uninteresting merges in Cairo
Message-ID: <20061215160303.GG17860@spearce.org>
URL: https://gitlist.dev/e/20061215160303.GG17860%40spearce.org
In-Reply-To: <200612151657.06909.jnareb@gmail.com>

```
Jakub Narebski <jnareb@gmail.com> wrote:
> Do you mean "commit" view or "commitdiff" view in gitweb for merges
> is confusing?

The commit view was what was confusing me.
 
> If it is "commit" view, it is fairly easy to remove difftree/whatchanged
> output below commit message for merges. However while git-show nor 
> git-diff-tree doesn't show diff for merge messages, the diftree output
> in "commit" view might be taken as 'damages'; git diff --summary always
> takes summary of diff against first parent.

I can see that, but it depends on what the current branch was when
you do the merge.  In the cairo case I was looking at yesterday the
"damages" from the merge were actually what was already considered to
be in the mainline as part of the project due to committer pulling
the remote master into his own master before pushing.

Given that the "push; whoops; pull; push" pattern is so common to
Git I think it is sort of misleading to show a merge like this;
lots of activity may have been pulled in from the central branch
during that pull.

iirc git whatchanged for a merge shows only files which cannot be
found in any of the parents; these the files which the merge commit
itself contributed directly.  If that set is empty then the commit
just isn't shown by git whatchanged.

-- 

```

## Jakub Narebski, 2006-12-15 16:53

Subject: [PATCH] gitweb: Do not show difftree for merges in "commit" view
Message-ID: <11662016252211-git-send-email-jnareb@gmail.com>
URL: https://gitlist.dev/e/11662016252211-git-send-email-jnareb%40gmail.com
In-Reply-To: <20061215160303.GG17860@spearce.org>

```
Do not show difftree against first parent for merges (commits with
more than one parent) in "commit" view, because it usually is
misleading.  git-show and git-whatchanged doesn't show diff for merges
either.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
 gitweb/gitweb.perl |   22 +++++++++++++++-------
 1 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 040ee71..ebf35a1 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3572,14 +3572,19 @@ sub git_commit {
 	my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
 
 	my $parent = $co{'parent'};
+	my $parents = $co{'parents'};
 	if (!defined $parent) {
 		$parent = "--root";
 	}
-	open my $fd, "-|", git_cmd(), "diff-tree", '-r', "--no-commit-id",
-		@diff_opts, $parent, $hash, "--"
-		or die_error(undef, "Open git-diff-tree failed");
-	my @difftree = map { chomp; $_ } <$fd>;
-	close $fd or die_error(undef, "Reading git-diff-tree failed");
+	my @difftree;
+	if (@$parents <= 1) {
+		# difftree output is not printed for merges
+		open my $fd, "-|", git_cmd(), "diff-tree", '-r', "--no-commit-id",
+			@diff_opts, $parent, $hash, "--"
+				or die_error(undef, "Open git-diff-tree failed");
+		@difftree = map { chomp; $_ } <$fd>;
+		close $fd or die_error(undef, "Reading git-diff-tree failed");
+	}
 
 	# non-textual hash id's can be cached
 	my $expires;
@@ -3641,7 +3646,7 @@ sub git_commit {
 	}
 	print "</td>" .
 	      "</tr>\n";
-	my $parents = $co{'parents'};
+
 	foreach my $par (@$parents) {
 		print "<tr>" .
 		      "<td>parent</td>" .
@@ -3663,7 +3668,10 @@ sub git_commit {
 	git_print_log($co{'comment'});
 	print "</div>\n";
 
-	git_difftree_body(\@difftree, $hash, $parent);
+	if (@$parents <= 1) {
+		# do not output difftree/whatchanged for merges
+		git_difftree_body(\@difftree, $hash, $parent);
+	}
 
 	git_footer_html();
 }
-- 
1.4.4.1

```
