From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 93B731F61A for ; Tue, 23 Aug 2022 08:32:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1661243524; bh=JP2YUhgM25lVV72uJSfu0mK5sL3hXuwsGpO1XAM2qzU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=RBc7cOwIrfV80WhfP7F6cnZ7UTJ39mpkUjuy6rgPyhxYk//MtcOZ7cVgXXQs6Me7n TCn4DRrxYzExz9i50U2WzEXJBuimWLTwPvhL2nHxHP3scHVcgFARznPDRofLm+iYJG ECA+Fyd+HVR5XKKtulVrjp9ahXJvMYcuv6pWR4YM= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 4/8] viewvcs: show commit titles for parent commits Date: Tue, 23 Aug 2022 08:31:59 +0000 Message-Id: <20220823083203.1128993-5-e@80x24.org> In-Reply-To: <20220823083203.1128993-1-e@80x24.org> References: <20220823083203.1128993-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: It's hard to know which commit I'm following a link to without having the title of the commit handy. --- lib/PublicInbox/ViewVCS.pm | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm index a73fbf0f..2c447909 100644 --- a/lib/PublicInbox/ViewVCS.pm +++ b/lib/PublicInbox/ViewVCS.pm @@ -32,7 +32,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', '%H', '%T', '%P', '%s', +my $SHOW_FMT = '--pretty=format:'.join('%n', '%H', '%T', '%P', '%p', '%s', '%an <%ae>%x09%ai', '%cn <%ce>%x09%ci', '%b%x00'); sub html_page ($$$) { @@ -93,6 +93,17 @@ sub show_other_result ($$) { html_page($ctx, 200, $bref); } +sub cmt_title { # git->cat_async callback + my ($bref, $oid, $type, $size, $pt) = @_; + utf8::decode($$bref); + if ($$bref =~ /\r?\n\r?\n([^\r\n]+)\r?\n?/) { + push @$pt, $1; + ascii_html($pt->[-1]); + } else { + push @$pt, ''; # need a placeholder if blank commit + } +} + sub show_commit_result ($$) { my ($bref, $ctx) = @_; my ($qsp_err, $logref, $tmp) = @$ctx{qw(-qsp_err -logref -tmp)}; @@ -106,7 +117,7 @@ sub show_commit_result ($$) { my $l = $ctx->{-linkify} = PublicInbox::Linkify->new; open my $fh, '<:utf8', "$tmp/h" or die "open $tmp/h: $!"; chop(my $buf = do { local $/ = "\0"; <$fh> }); - my ($H, $T, $P, $s, $au, $co, $bdy) = split(/\n/, $buf, 7); + my ($H, $T, $P, $p, $s, $au, $co, $bdy) = split(/\n/, $buf, 8); chomp $bdy; # try to keep author and committer dates lined up my $x = length($au) - length($co); @@ -120,13 +131,19 @@ sub show_commit_result ($$) { $_ = ascii_html($_) for ($au, $co); $_ = $l->to_html($_) for ($s, $bdy); $ctx->{-title_html} = $s; - my @p = split(/ /, $P); - if (@p == 1) { - $P = qq(\n parent $P); - } elsif (@p > 1) { - $P = qq(\n parents $p[0]\n); - shift @p; - $P .= qq( $_\n) for @p; + my @P = split(/ /, $P); + my @p = split(/ /, $p); # abbreviated + my @pt; + my $git = delete $ctx->{code_git}; + $git->cat_async($_, \&cmt_title, \@pt) for @P; + $git->cat_async_wait; + $_ = qq().shift(@p).' '.shift(@pt) for @P; + if (@P == 1) { + $P = qq(\n parent $P[0]); + } elsif (@P > 1) { + $P = qq(\n parents $P[0]\n); + shift @P; + $P .= qq( $_\n) for @P; chop $P; } else { # root commit $P = ' (root commit)'; @@ -206,6 +223,7 @@ sub show_commit ($$$$) { $ctx->{-logref} = $logref; $ctx->{-tmp} = $tmp; $ctx->{env}->{'qspawn.wcb'} = delete $ctx->{-wcb}; + $ctx->{code_git} = $git; $qsp->psgi_qx($ctx->{env}, undef, \&show_commit_result, $ctx); }