From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 02/13] viewvcs: preliminary support for showing non-blobs
Date: Tue, 12 Mar 2019 04:00:35 +0000 [thread overview]
Message-ID: <20190312040046.4619-3-e@80x24.org> (raw)
In-Reply-To: <20190312040046.4619-1-e@80x24.org>
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 | 11 +++++++----
lib/PublicInbox/ViewVCS.pm | 28 ++++++++++++++++++++++++++++
2 files changed, 35 insertions(+), 4 deletions(-)
diff --git a/lib/PublicInbox/SolverGit.pm b/lib/PublicInbox/SolverGit.pm
index 463a9b6..cd0f94a 100644
--- a/lib/PublicInbox/SolverGit.pm
+++ b/lib/PublicInbox/SolverGit.pm
@@ -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
diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm
index f537451..4a97b9a 100644
--- a/lib/PublicInbox/ViewVCS.pm
+++ b/lib/PublicInbox/ViewVCS.pm
@@ -67,6 +67,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) = @_;
@@ -86,6 +113,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) {
--
EW
next prev parent reply other threads:[~2019-03-12 4:00 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-12 4:00 [PATCH 00/13] support parsing cgitrc and spawning cgit Eric Wong
2019-03-12 4:00 ` [PATCH 01/13] git: add "commit_title" method Eric Wong
2019-03-12 4:00 ` Eric Wong [this message]
2019-03-12 4:00 ` [PATCH 03/13] viewvcs: match 8000-byte lookup for git Eric Wong
2019-03-12 4:00 ` [PATCH 04/13] spawn: support RLIMIT_CPU, RLIMIT_DATA and RLIMIT_CORE Eric Wong
2019-03-12 4:00 ` [PATCH 05/13] support publicinbox.cgitrc directive Eric Wong
2019-03-12 4:00 ` [PATCH 06/13] githttpbackend: move more psgi.input handling into subroutine Eric Wong
2019-03-12 4:00 ` [PATCH 07/13] githttpbackend: check for other errors and relax CRLF check Eric Wong
2019-03-12 4:00 ` [PATCH 08/13] spawn: support absolute paths Eric Wong
2019-03-12 4:00 ` [PATCH 09/13] cgit: support running cgit as a standalone CGI Eric Wong
2019-03-12 4:00 ` [PATCH 10/13] www: wire up cgit as a 404 handler if cgitrc is configured Eric Wong
2019-03-12 4:00 ` [PATCH 11/13] qspawn: wire up RLIMIT_* handling to limiters Eric Wong
2019-03-12 4:00 ` [PATCH 12/13] cgit: use a dedicated named limiter Eric Wong
2019-03-12 4:00 ` [PATCH 13/13] spawn: require soft and hard vals for RLIMIT_* params Eric Wong
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
List information: http://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190312040046.4619-3-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).