Subject: [PATCH] gitweb: Support comparing blobs (files) with different names

From: Jakub Narebski <[email-masked]>
Date: Mon, 26 Mar 2007 18:12:09 +0100

Fix the bug that caused "blobdiff" view called with new style URI
(it means with $hash_base ('hb') and $hash_parent_base ('hpb') denoting
tree-ish, usually commit, which have blobs being compared) for
renamed files (it means with both $file_name ('f') and $file_parent ('fp')
parameters set) to be show as new (added) file diff.

It is done by adding $file_parent ('fp') to the path limiter, meaning
that diff command becomes:

	git diff-tree [options] hpb hb -- fp f

instead of finding hash of a blob using git_get_hash_by_path subroutine
or using extended SHA-1 syntax:

	git diff [options] hpb:fp hp:f

Currently code for "blobdiff" does not support well mixed style URI,
for example asking for diff between blob given by its hash only, or
by hash and filename (without hash of tree-ish / commit), and blob
given by hash base (hash of tree-ish / commit) and filename but without
hash of blob itself, and probably would never will.

Signed-off-by: Jakub Narebski <[email-masked]>
---
Martin, sorry for the confusing suggestion about using tree-ish:path
syntax to compare (generate diff of) two file with different name.

This patch is less invasive and I think better solution.

 gitweb/gitweb.perl |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 5214050..c79bfeb 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3885,7 +3885,7 @@ sub git_blobdiff {
 			# read raw output
 			open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
 				$hash_parent_base, $hash_base,
-				"--", $file_name
+				"--", (defined $file_parent ? $file_parent : ()), $file_name
 				or die_error(undef, "Open git-diff-tree failed");
 			@difftree = map { chomp; $_ } <$fd>;
 			close $fd
@@ -3935,7 +3935,7 @@ sub git_blobdiff {
 		# open patch output
 		open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
 			'-p', $hash_parent_base, $hash_base,
-			"--", $file_name
+			"--", (defined $file_parent ? $file_parent : ()), $file_name
 			or die_error(undef, "Open git-diff-tree failed");
 	}
 
-- 
1.5.0.5