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 "--- <n>/_<filename>_" 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)
  5bac4a6719 (file from one branch)

This is mainly meant to easier see renames in a merge commit.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jakub Narebski 2007-06-08 13:29:49 +02:00 committed by Junio C Hamano
parent 90921740bd
commit deaa01a9f5

View File

@ -1064,19 +1064,35 @@ sub format_diff_from_to_header {
$line = $from_line; $line = $from_line;
#assert($line =~ m/^---/) if DEBUG; #assert($line =~ m/^---/) if DEBUG;
# no extra formatting "^--- /dev/null" # no extra formatting for "^--- /dev/null"
if ($line =~ m!^--- "?a/!) { if (! $diffinfo->{'nparents'}) {
if (!$diffinfo->{'nparents'} && # multiple 'from' # ordinary (single parent) diff
$from->{'href'}) { if ($line =~ m!^--- "?a/!) {
$line = '--- a/' . if ($from->{'href'}) {
$cgi->a({-href=>$from->{'href'}, -class=>"path"}, $line = '--- a/' .
esc_path($from->{'file'})); $cgi->a({-href=>$from->{'href'}, -class=>"path"},
} else { esc_path($from->{'file'}));
$line = '--- a/' . } else {
esc_path($from->{'file'}); $line = '--- a/' .
esc_path($from->{'file'});
}
}
$result .= qq!<div class="diff from_file">$line</div>\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!<div class="diff from_file">$line</div>\n!;
} }
} }
$result .= qq!<div class="diff from_file">$line</div>\n!;
$line = $to_line; $line = $to_line;
#assert($line =~ m/^\+\+\+/) if DEBUG; #assert($line =~ m/^\+\+\+/) if DEBUG;