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

gitweb: '--cc' for merges in 'commitdiff' view

Allow choosing between '-c' (combined diff) and '--cc' (compact combined) diff format in 'commitdiff' view for merge (multiparent) commits. Default is now '--cc'. In the bottom part of navigation bar there is link allowing to change diff format: "combined" for '-c' (when using '--cc') and "compact" for '--cc' (when using '-c'), just on the right of "raw" link to 'commitdiff_plain" view. About patchset part of diff --cc output: the difftree (whatchanged table) has "patch" links to anchors to individual patches (on the same page). The --cc option further compresses the patch output by omitting some hunks; when this optimization makes all hunks disappear, the patch is not shown (like in any other "empty diff" case). But the fact that patch has been simplified out is not reflected in the raw (difftree) part of diff output; the raw part is the same for '-c' and '--cc' options. As correcting difftree is rather out of the question, as it would require scanning patchset part before writing out difftree, we add "Simple merge" empty diffs as a place to have anchor to in place of those simplified out and removed patches. 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:33 UTC cd030c3a7053aec0f9dbf321ef139ce02a821f3b
1 file changed +99 -12
gitweb/gitweb.perl
+99 -12
@@ -1122,6 +1122,31 @@ sub format_diff_from_to_header {
1122 return $result;
1123 }
1124
1125 +# create note for patch simplified by combined diff
1126 +sub format_diff_cc_simplified {
1127 + my ($diffinfo, @parents) = @_;
1128 + my $result = '';
1129 +
1130 + $result .= "<div class=\"diff header\">" .
1131 + "diff --cc ";
1132 + if (!is_deleted($diffinfo)) {
1133 + $result .= $cgi->a({-href => href(action=>"blob",
1134 + hash_base=>$hash,
1135 + hash=>$diffinfo->{'to_id'},
1136 + file_name=>$diffinfo->{'to_file'}),
1137 + -class => "path"},
1138 + esc_path($diffinfo->{'to_file'}));
1139 + } else {
1140 + $result .= esc_path($diffinfo->{'to_file'});
1141 + }
1142 + $result .= "</div>\n" . # class="diff header"
1143 + "<div class=\"diff nodifferences\">" .
1144 + "Simple merge" .
1145 + "</div>\n"; # class="diff nodifferences"
1146 +
1147 + return $result;
1148 +}
1149 +
1150 # format patch (diff) line (not to be used for diff headers)
1151 sub format_diff_line {
1152 my $line = shift;
@@ -2973,13 +2998,33 @@ sub git_patchset_body {
2998 # advance raw git-diff output if needed
2999 $patch_idx++ if defined $diffinfo;
3000
2976 - # read and prepare patch information
2977 - if (ref($difftree->[$patch_idx]) eq "HASH") {
2978 - # pre-parsed (or generated by hand)
2979 - $diffinfo = $difftree->[$patch_idx];
2980 - } else {
2981 - $diffinfo = parse_difftree_raw_line($difftree->[$patch_idx]);
3001 + # compact combined diff output can have some patches skipped
3002 + # find which patch (using pathname of result) we are at now
3003 + my $to_name;
3004 + if ($diff_header[0] =~ m!^diff --cc "?(.*)"?$!) {
3005 + $to_name = $1;
3006 }
3007 +
3008 + do {
3009 + # read and prepare patch information
3010 + if (ref($difftree->[$patch_idx]) eq "HASH") {
3011 + # pre-parsed (or generated by hand)
3012 + $diffinfo = $difftree->[$patch_idx];
3013 + } else {
3014 + $diffinfo = parse_difftree_raw_line($difftree->[$patch_idx]);
3015 + }
3016 +
3017 + # check if current raw line has no patch (it got simplified)
3018 + if (defined $to_name && $to_name ne $diffinfo->{'to_file'}) {
3019 + print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3020 + format_diff_cc_simplified($diffinfo, @hash_parents) .
3021 + "</div>\n"; # class="patch"
3022 +
3023 + $patch_idx++;
3024 + $patch_number++;
3025 + }
3026 + } until (!defined $to_name || $to_name eq $diffinfo->{'to_file'} ||
3027 + $patch_idx > $#$difftree);
3028 # modifies %from, %to hashes
3029 parse_from_to_diffinfo($diffinfo, \%from, \%to, @hash_parents);
3030 if ($diffinfo->{'nparents'}) {
@@ -3069,6 +3114,27 @@ sub git_patchset_body {
3114 print "</div>\n"; # class="patch"
3115 }
3116
3117 + # for compact combined (--cc) format, with chunk and patch simpliciaction
3118 + # patchset might be empty, but there might be unprocessed raw lines
3119 + for ($patch_idx++ if $patch_number > 0;
3120 + $patch_idx < @$difftree;
3121 + $patch_idx++) {
3122 + # read and prepare patch information
3123 + if (ref($difftree->[$patch_idx]) eq "HASH") {
3124 + # pre-parsed (or generated by hand)
3125 + $diffinfo = $difftree->[$patch_idx];
3126 + } else {
3127 + $diffinfo = parse_difftree_raw_line($difftree->[$patch_idx]);
3128 + }
3129 +
3130 + # generate anchor for "patch" links in difftree / whatchanged part
3131 + print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3132 + format_diff_cc_simplified($diffinfo, @hash_parents) .
3133 + "</div>\n"; # class="patch"
3134 +
3135 + $patch_number++;
3136 + }
3137 +
3138 if ($patch_number == 0) {
3139 if (@hash_parents > 1) {
3140 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
@@ -4582,7 +4648,11 @@ sub git_commitdiff {
4648 die_error(undef, "Unknown commit object");
4649 }
4650
4585 - # we need to prepare $formats_nav before any parameter munging
4651 + # choose format for commitdiff for merge
4652 + if (! defined $hash_parent && @{$co{'parents'}} > 1) {
4653 + $hash_parent = '--cc';
4654 + }
4655 + # we need to prepare $formats_nav before almost any parameter munging
4656 my $formats_nav;
4657 if ($format eq 'html') {
4658 $formats_nav =
@@ -4590,7 +4660,8 @@ sub git_commitdiff {
4660 hash=>$hash, hash_parent=>$hash_parent)},
4661 "raw");
4662
4593 - if (defined $hash_parent) {
4663 + if (defined $hash_parent &&
4664 + $hash_parent ne '-c' && $hash_parent ne '--cc') {
4665 # commitdiff with two commits given
4666 my $hash_parent_short = $hash_parent;
4667 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
@@ -4622,6 +4693,17 @@ sub git_commitdiff {
4693 ')';
4694 } else {
4695 # merge commit
4696 + if ($hash_parent eq '--cc') {
4697 + $formats_nav .= ' | ' .
4698 + $cgi->a({-href => href(action=>"commitdiff",
4699 + hash=>$hash, hash_parent=>'-c')},
4700 + 'combined');
4701 + } else { # $hash_parent eq '-c'
4702 + $formats_nav .= ' | ' .
4703 + $cgi->a({-href => href(action=>"commitdiff",
4704 + hash=>$hash, hash_parent=>'--cc')},
4705 + 'compact');
4706 + }
4707 $formats_nav .=
4708 ' (merge: ' .
4709 join(' ', map {
@@ -4634,9 +4716,10 @@ sub git_commitdiff {
4716 }
4717
4718 my $hash_parent_param = $hash_parent;
4637 - if (!defined $hash_parent) {
4719 + if (!defined $hash_parent_param) {
4720 + # --cc for multiple parents, --root for parentless
4721 $hash_parent_param =
4639 - @{$co{'parents'}} > 1 ? '-c' : $co{'parent'} || '--root';
4722 + @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
4723 }
4724
4725 # read commitdiff
@@ -4713,10 +4796,14 @@ TEXT
4796
4797 # write patch
4798 if ($format eq 'html') {
4716 - git_difftree_body(\@difftree, $hash, $hash_parent || @{$co{'parents'}});
4799 + my $use_parents = !defined $hash_parent ||
4800 + $hash_parent eq '-c' || $hash_parent eq '--cc';
4801 + git_difftree_body(\@difftree, $hash,
4802 + $use_parents ? @{$co{'parents'}} : $hash_parent);
4803 print "<br/>\n";
4804
4719 - git_patchset_body($fd, \@difftree, $hash, $hash_parent || @{$co{'parents'}});
4805 + git_patchset_body($fd, \@difftree, $hash,
4806 + $use_parents ? @{$co{'parents'}} : $hash_parent);
4807 close $fd;
4808 print "</div>\n"; # class="page_body"
4809 git_footer_html();