From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id E90721F629 for ; Tue, 14 Feb 2023 13:17:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1676380660; bh=qk3CmZVrMNBimsgZ7B+eFICMnKjiorp0965GmeOf21Q=; h=From:To:Subject:Date:In-Reply-To:References:From; b=2sT34jiJ3+hdNE2oMYBk1gMMX4iz2S2O9qfIkw9wk7sOoctxhnnWOxVQWvxY79pHh zDnsfTPiQvglmRs/VfqlOKwZKk4wc7p1Q0ax3zKKOUMBTpMtRZ3Osymrhl4ObEorli 7I+TYFNOFcwLnbGeGnOBK6cjwpKmuH4vjx5LcwKM= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2/2] www_coderepo: handle unborn/dead branches in summary Date: Tue, 14 Feb 2023 13:17:39 +0000 Message-Id: <20230214131739.2978030-3-e@80x24.org> In-Reply-To: <20230214131739.2978030-1-e@80x24.org> References: <20230214131739.2978030-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We need to account for `git log' showing nothing for invalid branches and continue to render properly. We'll also quiet down `git log' stderr to avoid cluttering stderr, too. --- lib/PublicInbox/WwwCoderepo.pm | 14 +++++++------- t/solver_git.t | 18 ++++++++---------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/lib/PublicInbox/WwwCoderepo.pm b/lib/PublicInbox/WwwCoderepo.pm index 8a490b6c..629fad09 100644 --- a/lib/PublicInbox/WwwCoderepo.pm +++ b/lib/PublicInbox/WwwCoderepo.pm @@ -123,17 +123,16 @@ sub _refs_tags_link { sub summary_finish { my ($ctx) = @_; my $wcb = delete($ctx->{env}->{'qspawn.wcb'}) or return; # already done - my @x = split(/\n\n/sm, delete($ctx->{-each_refs})); + my @x = split(/\n\n/sm, delete($ctx->{-each_refs}), 3); PublicInbox::WwwStream::html_init($ctx); my $zfh = $ctx->zfh; # git log - my @r = split(/\n/s, pop(@x) // ''); + my @r = split(/\n/s, pop(@x)); my $last = scalar(@r) > $ctx->{wcr}->{summary_log} ? pop(@r) : undef; my $tip_html = ''; - if (defined(my $tip = $ctx->{qp}->{h})) { - $tip_html .= ' '.ascii_html($tip).' --'; - } + my $tip = $ctx->{qp}->{h}; + $tip_html .= ' '.ascii_html($tip).' --' if defined $tip; print $zfh <\$ git log --pretty=format:'%h %s (%cs)%d'$tip_html EOM @@ -146,7 +145,7 @@ EOM " (", $cs, ")\n"; print $zfh "\t(", ascii_html($d), ")\n" if $d; } - print $zfh "# no commits, yet\n" if !@r; + print $zfh '# no commits in `', ($tip//'HEAD'),"', yet\n\n" if !@r; print $zfh "...\n" if $last; # README @@ -218,7 +217,8 @@ sub summary { qq(git log -$nl --pretty=format:'%d %H %h %cs %s' "\$@" --)); push @cmd, '--', $tip if defined($tip); my $qsp = PublicInbox::Qspawn->new(\@cmd, - { GIT_DIR => $ctx->{git}->{git_dir} }); + { GIT_DIR => $ctx->{git}->{git_dir} }, + { quiet => 1, 2 => $self->{log_fh} }); $qsp->{qsp_err} = \($ctx->{-qsp_err} = ''); $tip //= 'HEAD'; my @try = ("$tip:README", "$tip:README.md"); # TODO: configurable diff --git a/t/solver_git.t b/t/solver_git.t index 79672398..c65d9785 100644 --- a/t/solver_git.t +++ b/t/solver_git.t @@ -330,18 +330,16 @@ EOF defined($ENV{PLACK_TEST_EXTERNALSERVER_URI}) or open STDERR, '>&', $olderr or xbail "open: $!"; is($res->code, 200, 'coderepo summary (binfoo)'); - if (ok(-s "$tmpdir/stderr.log")) { - open my $fh, '<', "$tmpdir/stderr.log" or xbail $!; - my $s = do { local $/; <$fh> }; - open $fh, '>', "$tmpdir/stderr.log" or xbail $!; - ok($s =~ s/^fatal: your current branch.*?\n//sm, - 'got current branch warning'); - ok($s =~ s/^.*? exit status=[1-9]+\n\z//sm, - 'got exit status warning'); - is($s, '', 'no unexpected warnings on empty coderepo'); - } + ok(!-s "$tmpdir/stderr.log"); $res = $cb->(GET('/public-inbox/')); is($res->code, 200, 'coderepo summary (public-inbox)'); + + my $tip = 'invalid-'.int(rand(0xdeadbeef)); + $res = $cb->(GET('/public-inbox/?h='.$tip)); + is($res->code, 200, 'coderepo summary on dead branch'); + like($res->content, qr/no commits in `\Q$tip\E', yet/, + 'lack of commits noted'); + $res = $cb->(GET('/public-inbox')); is($res->code, 301, 'redirected');