From 6bcf4b46c9a4ba7a6e5c78201c619fa41ac76a99 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Sun, 27 Aug 2006 23:49:36 +0200 Subject: [PATCH] gitweb: Use @diff_opts, default ('M'), as git-diff and git-diff-tree paramete Added new global configuration variable @diff_opts, which holds additional options (parameters) to git-diff and git-diff-tree, usually dealing rename/copying detection. Default value is '-M', taken from git_commit subroutine. Description of options and their approximate cost by Junio C Hamano. Changes: * git_commitdiff, git_blobdiff and git_blobdiff_plain now use '-M' instead of '-M', '-C' * git-diff now uses the same options as git-diff-tree * git_comittdiff_plain now uses '-M' instead of '-B' and is now rename-aware * git_rss uses now '-M' instead of () Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 8d28207b1..1430a7a8a 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -141,6 +141,16 @@ sub feature_snapshot { return ($ctype, $suffix, $command); } +# rename detection options for git-diff and git-diff-tree +# - default is '-M', with the cost proportional to +# (number of removed files) * (number of new files). +# - more costly is '-C' (or '-C', '-M'), with the cost proportional to +# (number of changed files + number of removed files) * (number of new files) +# - even more costly is '-C', '--find-copies-harder' with cost +# (number of files in the original tree) * (number of new files) +# - one might want to include '-B' option, e.g. '-B', '-M' +our @diff_opts = ('-M'); # taken from git_commit + our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++"; require $GITWEB_CONFIG if -e $GITWEB_CONFIG; @@ -2593,7 +2603,7 @@ sub git_commit { if (!defined $parent) { $parent = "--root"; } - open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash + open my $fd, "-|", $GIT, "diff-tree", '-r', @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"); @@ -2700,7 +2710,7 @@ sub git_blobdiff { if (defined $hash_base && defined $hash_parent_base) { if (defined $file_name) { # read raw output - open $fd, "-|", $GIT, "diff-tree", '-r', '-M', '-C', $hash_parent_base, $hash_base, + open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base, "--", $file_name or die_error(undef, "Open git-diff-tree failed"); @difftree = map { chomp; $_ } <$fd>; @@ -2718,7 +2728,7 @@ sub git_blobdiff { # try to find filename from $hash # read filtered raw output - open $fd, "-|", $GIT, "diff-tree", '-r', '-M', '-C', $hash_parent_base, $hash_base + open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base or die_error(undef, "Open git-diff-tree failed"); @difftree = # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c' @@ -2752,7 +2762,8 @@ sub git_blobdiff { } # open patch output - open $fd, "-|", $GIT, "diff-tree", '-r', '-p', '-M', '-C', $hash_parent_base, $hash_base, + open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts, + '-p', $hash_parent_base, $hash_base, "--", $file_name or die_error(undef, "Open git-diff-tree failed"); } @@ -2787,7 +2798,7 @@ sub git_blobdiff { } # open patch output - open $fd, "-|", $GIT, "diff", '-p', $hash_parent, $hash + open $fd, "-|", $GIT, "diff", '-p', @diff_opts, $hash_parent, $hash or die_error(undef, "Open git-diff failed"); } else { die_error('404 Not Found', "Missing one of the blob diff parameters") @@ -2872,7 +2883,7 @@ sub git_commitdiff { my $fd; my @difftree; if ($format eq 'html') { - open $fd, "-|", $GIT, "diff-tree", '-r', '-M', '-C', + open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts, "--patch-with-raw", "--full-index", $hash_parent, $hash or die_error(undef, "Open git-diff-tree failed"); @@ -2883,7 +2894,8 @@ sub git_commitdiff { } } elsif ($format eq 'plain') { - open $fd, "-|", $GIT, "diff-tree", '-r', '-p', '-B', $hash_parent, $hash + open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts, + '-p', $hash_parent, $hash or die_error(undef, "Open git-diff-tree failed"); } else { @@ -3192,9 +3204,12 @@ XML last; } my %cd = parse_date($co{'committer_epoch'}); - open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next; + open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts, + $co{'parent'}, $co{'id'} + or next; my @difftree = map { chomp; $_ } <$fd>; - close $fd or next; + close $fd + or next; print "\n" . "" . sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) . -- 2.26.2