From deaa01a9f59875dcfd0c9e08ce48f4168f29cb81 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Fri, 8 Jun 2007 13:29:49 +0200 Subject: [PATCH] gitweb: Create special from-file/to-file header for combined diff Instead of using default, diff(1) like from-file/to-file header for combined diff (for a merge commit), which looks like: --- a/git-gui/git-gui.sh +++ b/_git-gui/git-gui.sh_ (where _link_ denotes [hidden] hyperlink), create from-file(n)/to-file header, using "--- /__" for each of parents, e.g.: --- 1/_git-gui/git-gui.sh_ --- 2/_git-gui.sh_ +++ b/_git-gui/git-gui.sh_ Test it on one of merge commits involving rename, e.g. 95f97567c1887d77f3a46b42d8622c76414d964d (rename at top) 5bac4a671907604b5fb4e24ff682d5b0e8431931 (file from one branch) This is mainly meant to easier see renames in a merge commit. Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index aee4f239ae..13114bc9c6 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -1064,19 +1064,35 @@ sub format_diff_from_to_header { $line = $from_line; #assert($line =~ m/^---/) if DEBUG; - # no extra formatting "^--- /dev/null" - if ($line =~ m!^--- "?a/!) { - if (!$diffinfo->{'nparents'} && # multiple 'from' - $from->{'href'}) { - $line = '--- a/' . - $cgi->a({-href=>$from->{'href'}, -class=>"path"}, - esc_path($from->{'file'})); - } else { - $line = '--- a/' . - esc_path($from->{'file'}); + # no extra formatting for "^--- /dev/null" + if (! $diffinfo->{'nparents'}) { + # ordinary (single parent) diff + if ($line =~ m!^--- "?a/!) { + if ($from->{'href'}) { + $line = '--- a/' . + $cgi->a({-href=>$from->{'href'}, -class=>"path"}, + esc_path($from->{'file'})); + } else { + $line = '--- a/' . + esc_path($from->{'file'}); + } + } + $result .= qq!
$line
\n!; + + } else { + # combined diff (merge commit) + for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) { + if ($from->{'href'}[$i]) { + $line = '--- ' . + ($i+1) . "/" . + $cgi->a({-href=>$from->{'href'}[$i], -class=>"path"}, + esc_path($from->{'file'}[$i])); + } else { + $line = '--- /dev/null'; + } + $result .= qq!
$line
\n!; } } - $result .= qq!
$line
\n!; $line = $to_line; #assert($line =~ m/^\+\+\+/) if DEBUG; -- 2.11.4.GIT