From: mkoegler@auto.tuwien.ac.at (Martin Koegler)
To: Jakub Narebski <jnareb@gmail.com>
Cc: git@vger.kernel.org
Subject: [PATCH 2/7] gitweb: Support comparing blobs with different names
Date: Mon, 16 Apr 2007 22:18:13 +0200 [thread overview]
Message-ID: <20070416201813.GA2592@auto.tuwien.ac.at> (raw)
In-Reply-To: <a209e0308fc80ef0623baef8dca49e61b7bafaab.1176659094.git.mkoegler@auto.tuwien.ac.at>
Currently, blobdiff can only compare blobs with different file
names, if no hb/hpb parameters are present.
This patch adds support for comparing two blobs specified by any
combination of hb/f/h and hpb/fp/hp.
Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>
---
New version, as I found a bug in the expiration handling code.
I unified all blobdiff variants and added support for comparing blobs
with different names.
If h/hp parameter are missing, I need to generate them with
git_get_hash_by_path, as the are needed for the html header, which is
generated before parsing the git-diff output.
I currently ignore all mode changed, as they are part of the tree. I
don't think that displaying a mode change message justifes two call to
git-ls-tree for each blob diff (Currently it only calls git-ls-tree
for each missing h/hp parameter).
gitweb/gitweb.perl | 136 ++++++++++++++++------------------------------------
1 files changed, 41 insertions(+), 95 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index cbd8d03..790041c 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3902,109 +3902,54 @@ sub git_blobdiff {
my $fd;
my @difftree;
my %diffinfo;
- my $expires;
-
- # preparing $fd and %diffinfo for git_patchset_body
- # new style URI
- if (defined $hash_base && defined $hash_parent_base) {
- if (defined $file_name) {
- # read raw output
- open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
- $hash_parent_base, $hash_base,
- "--", (defined $file_parent ? $file_parent : ()), $file_name
- or die_error(undef, "Open git-diff-tree failed");
- @difftree = map { chomp; $_ } <$fd>;
- close $fd
- or die_error(undef, "Reading git-diff-tree failed");
- @difftree
- or die_error('404 Not Found', "Blob diff not found");
-
- } elsif (defined $hash &&
- $hash =~ /[0-9a-fA-F]{40}/) {
- # try to find filename from $hash
-
- # read filtered raw output
- open $fd, "-|", git_cmd(), "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'
- # $hash == to_id
- grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
- map { chomp; $_ } <$fd>;
- close $fd
- or die_error(undef, "Reading git-diff-tree failed");
- @difftree
- or die_error('404 Not Found', "Blob diff not found");
-
- } else {
- die_error('404 Not Found', "Missing one of the blob diff parameters");
- }
+ my $expires = '+1d';
- if (@difftree > 1) {
- die_error('404 Not Found', "Ambiguous blob diff specification");
- }
-
- %diffinfo = parse_difftree_raw_line($difftree[0]);
- $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
- $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
-
- $hash_parent ||= $diffinfo{'from_id'};
- $hash ||= $diffinfo{'to_id'};
+ $file_parent ||= $file_name;
- # non-textual hash id's can be cached
- if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
- $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
- $expires = '+1d';
- }
+ # non-textual hash id's can be cached
+ if (defined $hash && $hash !~ m/^[0-9a-fA-F]{40}$/) {
+ $expires = undef;
+ } elsif (defined $hash_parent && $hash_parent !~ m/^[0-9a-fA-F]{40}$/) {
+ $expires = undef;
+ } elsif (defined $hash_base && $hash_base !~ m/^[0-9a-fA-F]{40}$/) {
+ $expires = undef;
+ } elsif (defined $hash_parent_base && $hash_parent_base !~ m/^[0-9a-fA-F]{40}$/) {
+ $expires = undef;
+ }
- # open patch output
- open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
- '-p', ($format eq 'html' ? "--full-index" : ()),
- $hash_parent_base, $hash_base,
- "--", (defined $file_parent ? $file_parent : ()), $file_name
- or die_error(undef, "Open git-diff-tree failed");
+ # if hash parameter is missing, read it from the commit.
+ if (defined $hash_base && defined $file_name && !defined $hash) {
+ $hash = git_get_hash_by_path($hash_base, $file_name);
}
- # old/legacy style URI
- if (!%diffinfo && # if new style URI failed
- defined $hash && defined $hash_parent) {
- # fake git-diff-tree raw output
- $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
- $diffinfo{'from_id'} = $hash_parent;
- $diffinfo{'to_id'} = $hash;
- if (defined $file_name) {
- if (defined $file_parent) {
- $diffinfo{'status'} = '2';
- $diffinfo{'from_file'} = $file_parent;
- $diffinfo{'to_file'} = $file_name;
- } else { # assume not renamed
- $diffinfo{'status'} = '1';
- $diffinfo{'from_file'} = $file_name;
- $diffinfo{'to_file'} = $file_name;
- }
- } else { # no filename given
- $diffinfo{'status'} = '2';
- $diffinfo{'from_file'} = $hash_parent;
- $diffinfo{'to_file'} = $hash;
- }
+ if (defined $hash_parent_base && defined $file_parent && !defined $hash_parent) {
+ $hash_parent = git_get_hash_by_path($hash_parent_base, $file_parent);
+ }
+
+ if (!defined $hash || ! defined $hash_parent) {
+ die_error('404 Not Found', "Missing one of the blob diff parameters");
+ }
- # non-textual hash id's can be cached
- if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
- $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
- $expires = '+1d';
- }
- # open patch output
- open $fd, "-|", git_cmd(), "diff", @diff_opts,
- '-p', ($format eq 'html' ? "--full-index" : ()),
- $hash_parent, $hash, "--"
- or die_error(undef, "Open git-diff failed");
- } else {
- die_error('404 Not Found', "Missing one of the blob diff parameters")
- unless %diffinfo;
+ # fake git-diff-tree raw output
+ $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
+ $diffinfo{'from_id'} = $hash_parent;
+ $diffinfo{'to_id'} = $hash;
+ if (defined $file_name) {
+ $diffinfo{'status'} = '2';
+ $diffinfo{'from_file'} = $file_parent;
+ $diffinfo{'to_file'} = $file_name;
+ } else { # no filename given
+ $diffinfo{'status'} = '2';
+ $diffinfo{'from_file'} = $hash_parent;
+ $diffinfo{'to_file'} = $hash;
}
+ # open patch output
+ open $fd, "-|", git_cmd(), "diff", @diff_opts,
+ $hash_parent, $hash, "--"
+ or die_error(undef, "Open git-diff failed");
+
# header
if ($format eq 'html') {
my $formats_nav =
@@ -4028,11 +3973,12 @@ sub git_blobdiff {
}
} elsif ($format eq 'plain') {
+ my $patch_file_name = $file_name || $hash;
print $cgi->header(
-type => 'text/plain',
-charset => 'utf-8',
-expires => $expires,
- -content_disposition => 'inline; filename="' . "$file_name" . '.patch"');
+ -content_disposition => 'inline; filename="' . "$patch_file_name" . '.patch"');
print "X-Git-Url: " . $cgi->self_url() . "\n\n";
--
1.5.1.1.85.gf1888
next prev parent reply other threads:[~2007-04-16 20:18 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <437446e84f3aea71f74fea7ea66db4c1c326fb6b.1176659094.git.mkoegler@auto.tuwien.ac.at>
2007-04-15 20:46 ` [PATCH 1/7] gitweb: show "no difference" message for empty diff Martin Koegler
2007-04-18 13:52 ` Jakub Narebski
[not found] ` <201e30b3f69b40aec4f52ca16a22206f7db1c17d.1176659094.git.mkoegler@auto.tuwien.ac.at>
2007-04-15 20:46 ` [PATCH 3/7] gitweb: support filename prefix in git_patchset_body/git_difftree_body Martin Koegler
2007-04-27 10:55 ` Jakub Narebski
2007-04-28 8:22 ` Martin Koegler
[not found] ` <083c27614411a8fd7edafef8f5cba91625c88453.1176659095.git.mkoegler@auto.tuwien.ac.at>
2007-04-15 20:46 ` [PATCH 6/7] gitweb: pass root directory as empty file parameter Martin Koegler
[not found] ` <aba7141dc09643b4d6233f1bfb15677163991a27.1176659095.git.mkoegler@auto.tuwien.ac.at>
2007-04-15 20:46 ` [PATCH 7/7] gitweb: Adapt gitweb.js to new git_treeview calling convention Martin Koegler
[not found] ` <a209e0308fc80ef0623baef8dca49e61b7bafaab.1176659094.git.mkoegler@auto.tuwien.ac.at>
2007-04-15 20:46 ` [PATCH 2/7] gitweb: Support comparing blobs with different names Martin Koegler
2007-04-20 10:34 ` Jakub Narebski
2007-04-20 11:24 ` Junio C Hamano
2007-04-20 20:49 ` Jakub Narebski
2007-04-21 12:23 ` [PATCH 0/4] git-diff: use mode for tree:name syntax (was: Re: [PATCH 2/7] gitweb: Support comparing blobs with different names) Martin Koegler
2007-04-16 20:18 ` Martin Koegler [this message]
2007-04-29 21:35 ` [PATCH 2/7] gitweb: Support comparing blobs with different names Jakub Narebski
2007-04-30 5:27 ` Martin Koegler
[not found] ` <85de402216e82cc0f220df9d27370a33538a232a.1176659094.git.mkoegler@auto.tuwien.ac.at>
2007-04-15 20:46 ` [PATCH 4/7] gitweb: Add treediff view Martin Koegler
2007-04-16 20:20 ` Martin Koegler
[not found] ` <481946c2e3cff09ed4a623b1b20b9889666aedb0.1176659095.git.mkoegler@auto.tuwien.ac.at>
2007-04-15 20:46 ` [PATCH 5/7] gitweb: Prototyp for selecting diffs in JavaScript Martin Koegler
2007-05-18 8:49 ` Petr Baudis
2007-05-19 7:57 ` Martin Koegler
2007-05-19 8:27 ` Petr Baudis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070416201813.GA2592@auto.tuwien.ac.at \
--to=mkoegler@auto.tuwien.ac.at \
--cc=git@vger.kernel.org \
--cc=jnareb@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).