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 <jnareb@gmail.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Jakub Narebski 2006-08-27 23:49:36 +02:00 committed by Junio C Hamano
parent 0aea33762b
commit 6bcf4b46c9

View file

@ -141,6 +141,16 @@ sub feature_snapshot {
return ($ctype, $suffix, $command); 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++"; our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
require $GITWEB_CONFIG if -e $GITWEB_CONFIG; require $GITWEB_CONFIG if -e $GITWEB_CONFIG;
@ -2593,7 +2603,7 @@ sub git_commit {
if (!defined $parent) { if (!defined $parent) {
$parent = "--root"; $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"); or die_error(undef, "Open git-diff-tree failed");
my @difftree = map { chomp; $_ } <$fd>; my @difftree = map { chomp; $_ } <$fd>;
close $fd or die_error(undef, "Reading git-diff-tree failed"); 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 $hash_base && defined $hash_parent_base) {
if (defined $file_name) { if (defined $file_name) {
# read raw output # 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 "--", $file_name
or die_error(undef, "Open git-diff-tree failed"); or die_error(undef, "Open git-diff-tree failed");
@difftree = map { chomp; $_ } <$fd>; @difftree = map { chomp; $_ } <$fd>;
@ -2718,7 +2728,7 @@ sub git_blobdiff {
# try to find filename from $hash # try to find filename from $hash
# read filtered raw output # 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"); or die_error(undef, "Open git-diff-tree failed");
@difftree = @difftree =
# ':100644 100644 03b21826... 3b93d5e7... M ls-files.c' # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
@ -2752,7 +2762,8 @@ sub git_blobdiff {
} }
# open patch output # 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 "--", $file_name
or die_error(undef, "Open git-diff-tree failed"); or die_error(undef, "Open git-diff-tree failed");
} }
@ -2787,7 +2798,7 @@ sub git_blobdiff {
} }
# open patch output # 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"); or die_error(undef, "Open git-diff failed");
} else { } else {
die_error('404 Not Found', "Missing one of the blob diff parameters") die_error('404 Not Found', "Missing one of the blob diff parameters")
@ -2872,7 +2883,7 @@ sub git_commitdiff {
my $fd; my $fd;
my @difftree; my @difftree;
if ($format eq 'html') { 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 "--patch-with-raw", "--full-index", $hash_parent, $hash
or die_error(undef, "Open git-diff-tree failed"); or die_error(undef, "Open git-diff-tree failed");
@ -2883,7 +2894,8 @@ sub git_commitdiff {
} }
} elsif ($format eq 'plain') { } 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"); or die_error(undef, "Open git-diff-tree failed");
} else { } else {
@ -3192,9 +3204,12 @@ sub git_rss {
last; last;
} }
my %cd = parse_date($co{'committer_epoch'}); 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>; my @difftree = map { chomp; $_ } <$fd>;
close $fd or next; close $fd
or next;
print "<item>\n" . print "<item>\n" .
"<title>" . "<title>" .
sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) . sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) .