[PATCH] gitweb: Use @diff_opts, default ('M'), as git-diff and git-diff-tree paramete

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
Signed-off-by: Junio C Hamano <junkio@xxxxxxx>
---
As requested, gitweb now uses '-M' without '-C' as option 
to git-diff-tree thorough the script.

I'm not that sure about last chunk, changing git_rss. I didn't review
that function, and I'm not sure if we should add '-M' there...

I've added Junio to sob, because the comments are his.


 gitweb/gitweb.perl |   33 ++++++++++++++++++++++++---------
 1 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 6918947..99c74f1 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;
 
@@ -2613,7 +2623,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");
@@ -2720,7 +2730,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>;
@@ -2735,7 +2745,7 @@ sub git_blobdiff {
 			}
 
 			# 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'
@@ -2769,7 +2779,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");
 	}
@@ -2804,7 +2815,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")
@@ -2889,7 +2900,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");
 
@@ -2900,7 +2911,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 {
@@ -3209,9 +3221,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'}) .
-- 
1.4.1.1

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]