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.1 required=3.0 tests=ALL_TRUSTED,AWL,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 6C7071F59D for ; Tue, 10 Jan 2023 11:49:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1673351361; bh=w7w+l1PbrbTAzY6VOjn+59OGayOv9EaAwuyWdmNxRHk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=IraoXw6yKWtQlkS88rt40ak21XE5RoF9AgO8hcoUGpSybcLQn66K3OVHvdk5/dtBo FKXgZNiLTS1kn1BAU89OFb5uRKHgJeSkYy7R4/sCocoywHGOisJ9x0qU5rloPBxsB5 WK2pjdk+eZwT7l3OF+UuDDuScJOE88TW5t4mLr9E= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/4] www_coderepo: handle "?h=$tip" in summary view Date: Tue, 10 Jan 2023 11:49:18 +0000 Message-Id: <20230110114921.2668377-2-e@80x24.org> In-Reply-To: <20230110114921.2668377-1-e@80x24.org> References: <20230110114921.2668377-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This makes sense at least as far as the README and `git log' output goes. We'll also add the `b=' query parameter to the $OID/s/ href for the README blob. --- lib/PublicInbox/WwwCoderepo.pm | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/PublicInbox/WwwCoderepo.pm b/lib/PublicInbox/WwwCoderepo.pm index 7f8b3459..53126e19 100644 --- a/lib/PublicInbox/WwwCoderepo.pm +++ b/lib/PublicInbox/WwwCoderepo.pm @@ -15,6 +15,7 @@ use PublicInbox::Git; use PublicInbox::GitAsyncCat; use PublicInbox::WwwStream; use PublicInbox::Hval qw(ascii_html); +use PublicInbox::ViewDiff qw(uri_escape_path); use PublicInbox::RepoSnapshot; use PublicInbox::RepoAtom; @@ -75,6 +76,10 @@ sub summary_finish { # git log my @r = split(/\n/s, pop(@x) // ''); my $last = pop(@r) if scalar(@r) > $ctx->{wcr}->{summary_log}; + my $tip_html = ''; + if (defined(my $tip = $ctx->{qp}->{h})) { + $tip_html .= ' '.ascii_html($tip).' --'; + } print $zfh < heads tags \$ git log --pretty=format:'%h %s (%cs)%d' +id=log>\$ git log --pretty=format:'%h %s (%cs)%d'$tip_html EOM for (@r) { my $d; # decorations @@ -102,8 +107,10 @@ EOM if ($bref) { my $l = PublicInbox::Linkify->new; $$bref =~ s/\s*\z//sm; + my (undef, $path) = split(/:/, $ref_path, 2); # HEAD:README print $zfh "\n\$ " . - "git cat-file blob ", + qq(git cat-file blob ). ascii_html($ref_path), "\n", $l->to_html($$bref), '
';
 	}
@@ -180,16 +187,25 @@ sub set_readme { # git->cat_async callback
 sub summary {
 	my ($self, $ctx) = @_;
 	$ctx->{wcr} = $self;
+	my $tip = $ctx->{qp}->{h}; # same as cgit
+	if (defined $tip && $tip eq '') {
+		delete $ctx->{qp}->{h};
+		undef($tip);
+	}
 	my $nb = $self->{summary_branches} + 1;
 	my $nt = $self->{summary_tags} + 1;
 	my $nl = $self->{summary_log} + 1;
-	my $qsp = PublicInbox::Qspawn->new([qw(/bin/sh -c),
+
+	my @cmd = (qw(/bin/sh -c),
 		"$EACH_REF --count=$nb refs/heads; echo && " .
 		"$EACH_REF --count=$nt refs/tags; echo && " .
-		"git log -$nl --pretty=format:'%d %H %h %cs %s' --" ],
+		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} });
 	$qsp->{qsp_err} = \($ctx->{-qsp_err} = '');
-	my @try = qw(HEAD:README HEAD:README.md); # TODO: configurable
+	$tip //= 'HEAD';
+	my @try = ("$tip:README", "$tip:README.md"); # TODO: configurable
 	$ctx->{-nr_readme_tries} = [ @try ];
 	$ctx->{git}->cat_async($_, \&set_readme, $ctx) for @try;
 	if ($ctx->{env}->{'pi-httpd.async'}) {