about summary refs log tree commit homepage
path: root/lib/PublicInbox/ViewVCS.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-02-14 02:29:10 +0000
committerEric Wong <e@80x24.org>2019-04-04 09:13:57 +0000
commit4123a89e08e145405fa781be7f4590c4d13f4138 (patch)
tree9d15b135918111308c611c9006c91d6c10fb3288 /lib/PublicInbox/ViewVCS.pm
parentc9890ef809425a3607c2f1108eb19c30aa0f077b (diff)
downloadpublic-inbox-4123a89e08e145405fa781be7f4590c4d13f4138.tar.gz
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.
Diffstat (limited to 'lib/PublicInbox/ViewVCS.pm')
-rw-r--r--lib/PublicInbox/ViewVCS.pm28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm
index ae721034..b41adc44 100644
--- a/lib/PublicInbox/ViewVCS.pm
+++ b/lib/PublicInbox/ViewVCS.pm
@@ -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) {