@matheusbsbs / matheus-bagliano / commits / deaa01a9f5
Fork 0

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) 5bac4a671907604b5fb4e24ff682d5b0e8431931 (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>

Jakub Narebski committed Jun 8, 2007 at 13:29 UTC deaa01a9f59875dcfd0c9e08ce48f4168f29cb81
1 file changed +27 -11
gitweb/gitweb.perl
+27 -11
@@ -1064,19 +1064,35 @@ sub format_diff_from_to_header {
1064
1065 $line = $from_line;
1066 #assert($line =~ m/^---/) if DEBUG;
1067 - # no extra formatting "^--- /dev/null"
1068 - if ($line =~ m!^--- "?a/!) {
1069 - if (!$diffinfo->{'nparents'} && # multiple 'from'
1070 - $from->{'href'}) {
1071 - $line = '--- a/' .
1072 - $cgi->a({-href=>$from->{'href'}, -class=>"path"},
1073 - esc_path($from->{'file'}));
1074 - } else {
1075 - $line = '--- a/' .
1076 - esc_path($from->{'file'});
1067 + # no extra formatting for "^--- /dev/null"
1068 + if (! $diffinfo->{'nparents'}) {
1069 + # ordinary (single parent) diff
1070 + if ($line =~ m!^--- "?a/!) {
1071 + if ($from->{'href'}) {
1072 + $line = '--- a/' .
1073 + $cgi->a({-href=>$from->{'href'}, -class=>"path"},
1074 + esc_path($from->{'file'}));
1075 + } else {
1076 + $line = '--- a/' .
1077 + esc_path($from->{'file'});
1078 + }
1079 + }
1080 + $result .= qq!<div class="diff from_file">$line</div>\n!;
1081 +
1082 + } else {
1083 + # combined diff (merge commit)
1084 + for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1085 + if ($from->{'href'}[$i]) {
1086 + $line = '--- ' .
1087 + ($i+1) . "/" .
1088 + $cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},
1089 + esc_path($from->{'file'}[$i]));
1090 + } else {
1091 + $line = '--- /dev/null';
1092 + }
1093 + $result .= qq!<div class="diff from_file">$line</div>\n!;
1094 }
1095 }
1079 - $result .= qq!<div class="diff from_file">$line</div>\n!;
1096
1097 $line = $to_line;
1098 #assert($line =~ m/^\+\+\+/) if DEBUG;