]> Sergey Matveev's repositories - public-inbox.git/commitdiff
viewvcs: preliminary support for showing non-blobs
authorEric Wong <e@80x24.org>
Thu, 14 Feb 2019 02:29:10 +0000 (02:29 +0000)
committerEric Wong <e@80x24.org>
Thu, 4 Apr 2019 09:13:57 +0000 (09:13 +0000)
Eventually, we'll have special displays for various git objects
(commit, tree, tag).  But for now, we'll just use git-show
to spew whatever comes from git.

lib/PublicInbox/SolverGit.pm
lib/PublicInbox/ViewVCS.pm

index 463a9b6906ba069f87a049ea7f4fc40a51334153..cd0f94a10c831b2caa8325f8b14bc1f05a2cc3a5 100644 (file)
@@ -62,14 +62,15 @@ sub ERR ($$) {
        die $err;
 }
 
-# look for existing blobs already in git repos
+# look for existing objects already in git repos
 sub solve_existing ($$) {
        my ($self, $want) = @_;
        my $oid_b = $want->{oid_b};
+       my $have_hints = scalar keys %$want > 1;
        my @ambiguous; # Array of [ git, $oids]
        foreach my $git (@{$self->{gits}}) {
                my ($oid_full, $type, $size) = $git->check($oid_b);
-               if (defined($type) && $type eq 'blob') {
+               if (defined($type) && (!$have_hints || $type eq 'blob')) {
                        return [ $git, $oid_full, $type, int($size) ];
                }
 
@@ -480,10 +481,11 @@ sub resolve_patch ($$) {
                die "Loop detected solving $cur_want\n";
        }
        if (my $existing = solve_existing($self, $want)) {
+               my ($found_git, undef, $type, undef) = @$existing;
                dbg($self, "found $cur_want in " .
-                       join("\n", $existing->[0]->pub_urls));
+                       join("\n", $found_git->pub_urls));
 
-               if ($cur_want eq $self->{oid_want}) { # all done!
+               if ($cur_want eq $self->{oid_want} || $type ne 'blob') {
                        eval { delete($self->{user_cb})->($existing) };
                        die "E: $@" if $@;
                        return;
@@ -540,6 +542,7 @@ sub new {
 }
 
 # recreate $oid_want using $hints
+# hints keys: path_a, path_b, oid_a
 # Calls {user_cb} with: [ ::Git object, oid_full, type, size, di (diff_info) ]
 # with found object, or undef if nothing was found
 # Calls {user_cb} with a string error on fatal errors
index ae721034b8bf07532ffc89095852eb30916afaba..b41adc44b4418abedca31e93d1cfa9b2e6b73ef5 100644 (file)
@@ -71,6 +71,33 @@ sub stream_large_blob ($$$$) {
        });
 }
 
+sub show_other ($$$$) {
+       my ($ctx, $res, $logref, $fn) = @_;
+       my ($git, $oid, $type, $size) = @$res;
+       if ($size > $max_size) {
+               $$logref = "$oid is too big to show\n" . $$logref;
+               return html_page($ctx, 200, $logref);
+       }
+       my $cmd = ['git', "--git-dir=$git->{git_dir}",
+               qw(show --encoding=UTF-8 --no-color --no-abbrev), $oid ];
+       my $qsp = PublicInbox::Qspawn->new($cmd);
+       my $env = $ctx->{env};
+       $qsp->psgi_qx($env, undef, sub {
+               my ($bref) = @_;
+               if (my $err = $qsp->{err}) {
+                       utf8::decode($$err);
+                       $$logref .= "git show error: $err";
+                       return html_page($ctx, 500, $logref);
+               }
+               my $l = PublicInbox::Linkify->new;
+               utf8::decode($$bref);
+               $l->linkify_1($$bref);
+               $$bref = '<pre>'. $l->linkify_2(ascii_html($$bref));
+               $$bref .= '</pre><hr>' . $$logref;
+               html_page($ctx, 200, $bref);
+       });
+}
+
 sub solve_result {
        my ($ctx, $res, $log, $hints, $fn) = @_;
 
@@ -90,6 +117,7 @@ sub solve_result {
        $ref eq 'ARRAY' or return html_page($ctx, 500, \$log);
 
        my ($git, $oid, $type, $size, $di) = @$res;
+       return show_other($ctx, $res, \$log, $fn) if $type ne 'blob';
        my $path = to_filename($di->{path_b} || $hints->{path_b} || 'blob');
        my $raw_link = "(<a\nhref=$path>raw</a>)";
        if ($size > $max_size) {