]> asedeno.scripts.mit.edu Git - git.git/commitdiff
gitweb: Use @diff_opts, default ('M'), as git-diff and git-diff-tree paramete
authorJakub Narebski <jnareb@gmail.com>
Sun, 27 Aug 2006 21:49:36 +0000 (23:49 +0200)
committerJunio C Hamano <junkio@cox.net>
Sun, 27 Aug 2006 22:35:01 +0000 (15:35 -0700)
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>
gitweb/gitweb.perl

index 8d28207b1f5eb5a0e5f43f0324797f2a9550892a..1430a7a8aa5cb9b881f54df83c06a36412451d5c 100755 (executable)
@@ -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 "<item>\n" .
                      "<title>" .
                      sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) .