* [PATCH] gitweb: Support comparing blobs with different names
@ 2007-04-23 20:55 Martin Koegler
0 siblings, 0 replies; 2+ messages in thread
From: Martin Koegler @ 2007-04-23 20:55 UTC (permalink / raw)
To: Jakub Narebski; +Cc: git, Martin Koegler
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>
---
Updated gitweb blobdiff patch to take advantage of my git-diff patch series.
gitweb/gitweb.perl | 148 +++++++++++++++++++---------------------------------
1 files changed, 53 insertions(+), 95 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index cbd8d03..4b42f62 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3902,109 +3902,66 @@ 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");
- }
-
- 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'};
+ my $expires = '+1d';
+ my $from, $to;
- $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;
+ }
+
+ # 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);
+ }
- # 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 (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");
}
- # 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 $hase_base && defined $file_name) {
+ $to = $hash_base . ':' . $file_name;
+ } else {
+ $to = $hash;
+ }
- # 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';
- }
+ if (defined $hase_parent_base && defined $file_parent) {
+ $from = $hash_parent_base . ':' . $file_parent;
+ } else {
+ $from = $hash_parent;
+ }
- # 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, '--raw', '-p', '--full-index',
+ $from, $to, "--"
+ or die_error(undef, "Open git-diff failed");
+
# header
if ($format eq 'html') {
my $formats_nav =
@@ -4028,11 +3985,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.199.g1a18-dirty
^ permalink raw reply related [flat|nested] 2+ messages in thread* [PATCH] gitweb: show no difference message
@ 2007-03-25 20:34 Martin Koegler
2007-03-25 20:34 ` [PATCH] gitweb: Support comparing blobs with different names Martin Koegler
0 siblings, 1 reply; 2+ messages in thread
From: Martin Koegler @ 2007-03-25 20:34 UTC (permalink / raw)
To: Jakub Narebski; +Cc: git, Martin Koegler
Currently, gitweb shows only header and footer, if no differences are
found. This patch adds a "No differences are found" message for the html
output.
Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>
---
gitweb/gitweb.perl | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 5214050..fbadab4 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2376,6 +2376,7 @@ sub git_patchset_body {
my $patch_idx = 0;
my $patch_line;
+ my $empty = 0;
my $diffinfo;
my (%from, %to);
@@ -2396,6 +2397,7 @@ sub git_patchset_body {
# git diff header
#assert($patch_line =~ m/^diff /) if DEBUG;
#assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
+ $empty++;
push @diff_header, $patch_line;
# extended diff header
@@ -2559,6 +2561,8 @@ sub git_patchset_body {
print "</div>\n"; # class="patch"
}
+ print "<div class=\"diff header\">No differences found</div>\n" if (!$empty);
+
print "</div>\n"; # class="patchset"
}
--
1.5.1.rc1.51.gb08b-dirty
^ permalink raw reply related [flat|nested] 2+ messages in thread* [PATCH] gitweb: Support comparing blobs with different names
2007-03-25 20:34 [PATCH] gitweb: show no difference message Martin Koegler
@ 2007-03-25 20:34 ` Martin Koegler
0 siblings, 0 replies; 2+ messages in thread
From: Martin Koegler @ 2007-03-25 20:34 UTC (permalink / raw)
To: Jakub Narebski; +Cc: git, Martin Koegler
Currently, blobdiff can only compare blobs with diffenrent file
names, if no hb/hpb parameters are present.
This patch adds support for comparing two blobs specified by hb/f
and hpb/fp.
Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>
---
gitweb/gitweb.perl | 27 ++++++++++++++++++++++++++-
1 files changed, 26 insertions(+), 1 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index fbadab4..e3c2918 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3882,9 +3882,34 @@ sub git_blobdiff {
my %diffinfo;
my $expires;
+ if (defined $hash_base && defined $hash_parent_base &&
+ defined $file_name && defined $file_parent) {
+
+ $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
+ $diffinfo{'from_file'} = $file_parent;
+ $diffinfo{'to_file'} = $file_name;
+ $diffinfo{'status'} = '2';
+
+ if (defined $hash) {
+ $diffinfo{'to_id'} = $hash;
+ } else {
+ $diffinfo{'to_id'} = git_get_hash_by_path($hash_base, $file_name);
+ }
+ if (defined $hash_parent) {
+ $diffinfo{'from_id'} = $hash_parent;
+ } else {
+ $diffinfo{'from_id'} = git_get_hash_by_path($hash_parent_base, $file_parent);
+ }
+
+ # open patch output
+ open $fd, "-|", git_cmd(), "diff", '-p', @diff_opts,
+ $hash_parent_base.":".$file_parent, $hash_base.":".$file_name, "--"
+ or die_error(undef, "Open git-diff failed");
+ }
+
# preparing $fd and %diffinfo for git_patchset_body
# new style URI
- if (defined $hash_base && defined $hash_parent_base) {
+ if (defined $hash_base && defined $hash_parent_base && !%diffinfo) {
if (defined $file_name) {
# read raw output
open $fd, "-|", git_cmd(), "diff-tree", '-r', @diff_opts,
--
1.5.1.rc1.51.gb08b-dirty
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-04-23 20:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-23 20:55 [PATCH] gitweb: Support comparing blobs with different names Martin Koegler
-- strict thread matches above, loose matches on Subject: below --
2007-03-25 20:34 [PATCH] gitweb: show no difference message Martin Koegler
2007-03-25 20:34 ` [PATCH] gitweb: Support comparing blobs with different names Martin Koegler
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).