From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 06/18] viewvcs: add patch download link for single-parent commits
Date: Mon, 29 Aug 2022 09:26:35 +0000 [thread overview]
Message-ID: <20220829092647.1512215-7-e@80x24.org> (raw)
In-Reply-To: <20220829092647.1512215-1-e@80x24.org>
The email signature field will echo the format-patch arguments
used so it can be used as hint for users learning to more of
the git CLI.
---
lib/PublicInbox/ViewVCS.pm | 43 ++++++++++++++++++++++++++++++++++----
1 file changed, 39 insertions(+), 4 deletions(-)
diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm
index 8fb0844d..84358d0e 100644
--- a/lib/PublicInbox/ViewVCS.pm
+++ b/lib/PublicInbox/ViewVCS.pm
@@ -23,6 +23,7 @@ use PublicInbox::Linkify;
use PublicInbox::Tmpfile;
use PublicInbox::ViewDiff qw(flush_diff);
use PublicInbox::View;
+use PublicInbox::Eml;
use Text::Wrap qw(wrap);
use PublicInbox::Hval qw(ascii_html to_filename);
my $hl = eval {
@@ -33,7 +34,7 @@ my $hl = eval {
my %QP_MAP = ( A => 'oid_a', a => 'path_a', b => 'path_b' );
our $MAX_SIZE = 1024 * 1024; # TODO: configurable
my $BIN_DETECT = 8000; # same as git
-my $SHOW_FMT = '--pretty=format:'.join('%n', '%P', '%p', '%H', '%T', '%s',
+my $SHOW_FMT = '--pretty=format:'.join('%n', '%P', '%p', '%H', '%T', '%s', '%f',
'%an <%ae> %ai', '%cn <%ce> %ci', '%b%x00');
sub html_page ($$;@) {
@@ -127,8 +128,8 @@ sub show_commit_start { # ->psgi_qx callback
chop(my $buf = do { local $/ = "\0"; <$fh> });
chomp $buf;
my ($P, $p);
- ($P, $p, @$ctx{qw(cmt_H cmt_T cmt_s cmt_au cmt_co cmt_b)})
- = split(/\n/, $buf, 8);
+ ($P, $p, @$ctx{qw(cmt_H cmt_T cmt_s cmt_f cmt_au cmt_co cmt_b)})
+ = split(/\n/, $buf, 9);
return cmt_finalize($ctx) if !$P;
@{$ctx->{-cmt_P}} = split(/ /, $P);
@{$ctx->{-cmt_p}} = split(/ /, $p); # abbreviated
@@ -164,7 +165,8 @@ sub cmt_finalize {
my ($P, $p, $pt) = delete @$ctx{qw(-cmt_P -cmt_p -cmt_pt)};
$_ = qq(<a href="$upfx$_/s/">).shift(@$p).'</a> '.shift(@$pt) for @$P;
if (@$P == 1) {
- $x = qq(\n parent $P->[0]);
+ $x = qq{ (<a
+href="$ctx->{cmt_f}.patch">patch</a>)\n parent $P->[0]};
} elsif (@$P > 1) {
$x = qq(\n parents $P->[0]\n);
shift @$P;
@@ -230,8 +232,41 @@ EOM
delete($ctx->{env}->{'qspawn.wcb'})->([200, $res_hdr, [$x]]);
}
+sub stream_patch_parse_hdr { # {parse_hdr} for Qspawn
+ my ($r, $bref, $ctx) = @_;
+ if (!defined $r) { # sysread error
+ html_page($ctx, 500, dbg_log($ctx));
+ } elsif (index($$bref, "\n\n") >= 0) {
+ my $eml = bless { hdr => $bref }, 'PublicInbox::Eml';
+ my $fn = to_filename($eml->header('Subject') // '');
+ $fn = substr($fn // 'PATCH-no-subject', 6); # drop "PATCH-"
+ return [ 200, [ 'Content-Type', 'text/plain; charset=UTF-8',
+ 'Content-Disposition',
+ qq(inline; filename=$fn.patch) ] ];
+ } elsif ($r == 0) {
+ my $log = dbg_log($ctx);
+ warn "premature EOF on $ctx->{patch_oid} $log";
+ return html_page($ctx, 500, $log);
+ } else {
+ undef; # bref keeps growing until "\n\n"
+ }
+}
+
+sub show_patch ($$) {
+ my ($ctx, $res) = @_;
+ my ($git, $oid) = @$res;
+ my @cmd = ('git', "--git-dir=$git->{git_dir}",
+ qw(format-patch -1 --stdout -C),
+ "--signature=git format-patch -1 --stdout -C $oid", $oid);
+ my $qsp = PublicInbox::Qspawn->new(\@cmd);
+ $ctx->{env}->{'qspawn.wcb'} = delete $ctx->{-wcb};
+ $ctx->{patch_oid} = $oid;
+ $qsp->psgi_return($ctx->{env}, undef, \&stream_patch_parse_hdr, $ctx);
+}
+
sub show_commit ($$) {
my ($ctx, $res) = @_;
+ return show_patch($ctx, $res) if ($ctx->{fn} // '') =~ /\.patch\z/;
my ($git, $oid) = @$res;
# patch-id needs two passes, and we use the initial show to ensure
# a patch embedded inside the commit message body doesn't get fed
next prev parent reply other threads:[~2022-08-29 9:26 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-29 9:26 [PATCH 00/18] WWW: patch, tree, git glossary Eric Wong
2022-08-29 9:26 ` [PATCH 01/18] solver: create tmpdir lazily Eric Wong
2022-08-29 9:26 ` [PATCH 02/18] viewvcs: share File::Temp::Dir with solver Eric Wong
2022-08-29 9:26 ` [PATCH 03/18] viewvcs: delay stringification of solver debug log Eric Wong
2022-08-29 9:26 ` [PATCH 04/18] www: allow html_oneshot to take an array arg Eric Wong
2022-08-29 9:26 ` [PATCH 05/18] viewvcs: use array for highlighted blob display Eric Wong
2022-08-29 9:26 ` Eric Wong [this message]
2022-08-29 9:26 ` [PATCH 07/18] viewvcs: author date links to contemporary messages Eric Wong
2022-08-29 9:26 ` [PATCH 08/18] view: speed up /$INBOX/ landing page by 0.5-1.0% Eric Wong
2022-08-29 9:26 ` [PATCH 09/18] treewide: ditch inbox->recent method Eric Wong
2022-08-29 9:26 ` [PATCH 10/18] view: /$INBOX/: show "messages from $old to $new" Eric Wong
2022-08-29 9:26 ` [PATCH 11/18] view: cleanups and reuse for {obuf} preparation Eric Wong
2022-08-29 9:26 ` [PATCH 12/18] www: atom: fix "changed" href to nowhere Eric Wong
2022-08-29 9:26 ` [PATCH 13/18] www: provide text/help/#search anchor Eric Wong
2022-08-29 9:26 ` [PATCH 14/18] solver: early make hints detection more robust Eric Wong
2022-08-29 9:26 ` [PATCH 15/18] viewvcs: add tree view Eric Wong
2022-08-29 9:26 ` [PATCH 16/18] viewvcs: reduce hash assignments for commit info Eric Wong
2022-08-29 9:26 ` [PATCH 17/18] viewvcs: add glossary for commit Eric Wong
2022-08-29 9:57 ` [19/18 PATCH] viewvcs: fixup commit glossary stuff Eric Wong
2022-08-29 9:26 ` [PATCH 18/18] viewvcs: show "blob $OID" rather than "$OID blob" 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: https://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=20220829092647.1512215-7-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.
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).