user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH 0/4] www: more coderepo tweaks
@ 2023-01-10 11:49 Eric Wong
  2023-01-10 11:49 ` [PATCH 1/4] www_coderepo: handle "?h=$tip" in summary view Eric Wong
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Eric Wong @ 2023-01-10 11:49 UTC (permalink / raw)
  To: meta

Still trying to figure out how present a search UI for
multiple mailboxes, or just use /all/ or single inbox
mappings...  UI/UX is frustrating :<

patch 2/4 took me a while to decide between `b=/' and `b='.

Eric Wong (4):
  www_coderepo: handle "?h=$tip" in summary view
  www_coderepo: show tree root as "(root)"
  viewvcs: update comment about show_other_result
  config: use inbox names to map inboxes <-> coderepos

 lib/PublicInbox/Config.pm      |  4 +---
 lib/PublicInbox/ViewVCS.pm     | 41 ++++++++++++++++++++--------------
 lib/PublicInbox/WwwCoderepo.pm | 28 +++++++++++++++++------
 3 files changed, 46 insertions(+), 27 deletions(-)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] www_coderepo: handle "?h=$tip" in summary view
  2023-01-10 11:49 [PATCH 0/4] www: more coderepo tweaks Eric Wong
@ 2023-01-10 11:49 ` Eric Wong
  2023-01-10 11:49 ` [PATCH 2/4] www_coderepo: show tree root as "(root)" Eric Wong
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2023-01-10 11:49 UTC (permalink / raw)
  To: meta

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 <<EOM;
 <pre>
 <a
@@ -83,7 +88,7 @@ href='#heads'>heads</a> <a
 href='#tags'>tags</a>
 
 <a
-id=log>\$</a> git log --pretty=format:'%h %s (%cs)%d'
+id=log>\$</a> 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<a id=readme>\$</a> " .
-			"git cat-file blob <a href=./$oid/s/>",
+			qq(git cat-file blob <a href="./$oid/s/?b=) .
+			ascii_html(uri_escape_path($path)) . q(">).
 			ascii_html($ref_path), "</a>\n",
 			$l->to_html($$bref), '</pre><hr><pre>';
 	}
@@ -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'}) {

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] www_coderepo: show tree root as "(root)"
  2023-01-10 11:49 [PATCH 0/4] www: more coderepo tweaks Eric Wong
  2023-01-10 11:49 ` [PATCH 1/4] www_coderepo: handle "?h=$tip" in summary view Eric Wong
@ 2023-01-10 11:49 ` Eric Wong
  2023-01-10 11:49 ` [PATCH 3/4] viewvcs: update comment about show_other_result Eric Wong
  2023-01-10 11:49 ` [PATCH 4/4] config: use inbox names to map inboxes <-> coderepos Eric Wong
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2023-01-10 11:49 UTC (permalink / raw)
  To: meta

We'll use the `b=' parameter as a hint.  I originally considered
`b=/', but a singular slash `/' isn't used in git for paths.
$refname:$path resolution where $path is an empty string,
`git cat-file -t $refname:' resolves to the tree, so it seems
special-casing the empty string is fine in the web UI, too.
---
 lib/PublicInbox/ViewVCS.pm | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm
index 99ee2c11..d8f6742f 100644
--- a/lib/PublicInbox/ViewVCS.pm
+++ b/lib/PublicInbox/ViewVCS.pm
@@ -212,7 +212,7 @@ href="$f.patch">patch</a>)\n   <a href=#parent>parent</a> $P->[0]};
 	my $zfh = $ctx->zfh;
 	print $zfh <<EOM;
 <pre>   <a href=#commit>commit</a> $H$x
-     <a href=#tree>tree</a> <a href="$upfx$T/s/">$T</a>
+     <a href=#tree>tree</a> <a href="$upfx$T/s/?b=">$T</a>
    author $au
 committer $co
 
@@ -362,9 +362,13 @@ sub show_tree_result ($$) {
 	my $pfx = $qp->{b};
 	$$bref = "<pre><a href=#tree>tree</a> $ctx->{tree_oid}";
 	if (defined $pfx) {
-		my $x = ascii_html($pfx);
-		$pfx .= '/';
-		$$bref .= qq(  <a href=#path>path</a>: $x</a>\n);
+		if ($pfx eq '') {
+			$$bref .= "  (root)\n";
+		} else {
+			my $x = ascii_html($pfx);
+			$pfx .= '/';
+			$$bref .= qq(  <a href=#path>path</a>: $x</a>\n);
+		}
 	} else {
 		$pfx = '';
 		$$bref .= qq[  (<a href=#path>path</a> unknown)\n];

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] viewvcs: update comment about show_other_result
  2023-01-10 11:49 [PATCH 0/4] www: more coderepo tweaks Eric Wong
  2023-01-10 11:49 ` [PATCH 1/4] www_coderepo: handle "?h=$tip" in summary view Eric Wong
  2023-01-10 11:49 ` [PATCH 2/4] www_coderepo: show tree root as "(root)" Eric Wong
@ 2023-01-10 11:49 ` Eric Wong
  2023-01-10 11:49 ` [PATCH 4/4] config: use inbox names to map inboxes <-> coderepos Eric Wong
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2023-01-10 11:49 UTC (permalink / raw)
  To: meta

In case git has other object types in the future...
---
 lib/PublicInbox/ViewVCS.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm
index d8f6742f..9a559687 100644
--- a/lib/PublicInbox/ViewVCS.pm
+++ b/lib/PublicInbox/ViewVCS.pm
@@ -104,7 +104,7 @@ sub stream_large_blob ($$) {
 	$qsp->psgi_return($env, undef, \&stream_blob_parse_hdr, $ctx);
 }
 
-sub show_other_result ($$) { # tag
+sub show_other_result ($$) { # future-proofing
 	my ($bref, $ctx) = @_;
 	if (my $qsp_err = delete $ctx->{-qsp_err}) {
 		return html_page($ctx, 500, dbg_log($ctx) .

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] config: use inbox names to map inboxes <-> coderepos
  2023-01-10 11:49 [PATCH 0/4] www: more coderepo tweaks Eric Wong
                   ` (2 preceding siblings ...)
  2023-01-10 11:49 ` [PATCH 3/4] viewvcs: update comment about show_other_result Eric Wong
@ 2023-01-10 11:49 ` Eric Wong
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2023-01-10 11:49 UTC (permalink / raw)
  To: meta

We can avoid having to deal with weakening references and then
later creating strong references in WwwCoderepo.
---
 lib/PublicInbox/Config.pm      |  4 +---
 lib/PublicInbox/ViewVCS.pm     | 27 +++++++++++++++------------
 lib/PublicInbox/WwwCoderepo.pm |  2 --
 3 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index c48ab2bd..cdf06d85 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -404,10 +404,8 @@ sub repo_objs {
 			push @repo_objs, $repo if $repo;
 		}
 		if (scalar @repo_objs) {
-			require Scalar::Util;
 			for (@repo_objs) {
-				push @{$_->{-ibxs}}, $ibxish;
-				Scalar::Util::weaken($_->{-ibxs}->[-1]);
+				push @{$_->{ibx_names}}, $ibxish->{name};
 			}
 			$ibxish->{-repo_objs} = \@repo_objs;
 		} else {
diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm
index 9a559687..6b641b32 100644
--- a/lib/PublicInbox/ViewVCS.pm
+++ b/lib/PublicInbox/ViewVCS.pm
@@ -155,21 +155,24 @@ sub show_commit_start { # ->psgi_qx callback
 
 sub ibx_url_for {
 	my ($ctx) = @_;
-	$ctx->{ibx} and return; # just fall back to $upfx
-	$ctx->{git} or return; # /$CODEREPO/$OID/s/ to (eidx|ibx)
+	$ctx->{ibx} and return; # fall back to $upfx
+	$ctx->{git} or return;
 	if (my $ALL = $ctx->{www}->{pi_cfg}->ALL) {
-		$ALL->base_url // $ALL->base_url($ctx->{env});
-	} elsif (my $ibxs = $ctx->{git}->{-ibxs}) {
-		for my $ibx (@$ibxs) {
-			if ($ibx->isrch) {
-				return defined($ibx->{url}) ?
-					prurl($ctx->{env}, $ibx->{url}) :
-					"../../../$ibx->{name}/";
-			}
+		return $ALL->base_url // $ALL->base_url($ctx->{env});
+	} elsif (my $ibx_names = $ctx->{git}->{ibx_names}) {
+		my $by_name = $ctx->{www}->{pi_cfg}->{-by_name};
+		for my $name (@$ibx_names) {
+			my $ibx = $by_name->{$name} // do {
+				warn "inbox `$name' no longer exists\n";
+				next;
+			};
+			$ibx->isrch // next;
+			return defined($ibx->{url}) ?
+				prurl($ctx->{env}, $ibx->{url}) :
+				"../../../$name/";
 		}
-	} else {
-		undef;
 	}
+	undef;
 }
 
 sub cmt_finalize {
diff --git a/lib/PublicInbox/WwwCoderepo.pm b/lib/PublicInbox/WwwCoderepo.pm
index 53126e19..e89a6456 100644
--- a/lib/PublicInbox/WwwCoderepo.pm
+++ b/lib/PublicInbox/WwwCoderepo.pm
@@ -42,13 +42,11 @@ sub prepare_coderepos {
 		$k = substr($k, length('publicinbox.'), -length('.coderepo'));
 		my $ibx = $pi_cfg->lookup_name($k) // next;
 		$pi_cfg->repo_objs($ibx);
-		push @{$self->{-strong}}, $ibx; # strengthen {-ibxs} weakref
 	}
 	for my $k (grep(/\Aextindex\.(?:.+)\.coderepo\z/, keys %$pi_cfg)) {
 		$k = substr($k, length('extindex.'), -length('.coderepo'));
 		my $eidx = $pi_cfg->lookup_ei($k) // next;
 		$pi_cfg->repo_objs($eidx);
-		push @{$self->{-strong}}, $eidx; # strengthen {-ibxs} weakref
 	}
 }
 

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-01-10 11:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-10 11:49 [PATCH 0/4] www: more coderepo tweaks Eric Wong
2023-01-10 11:49 ` [PATCH 1/4] www_coderepo: handle "?h=$tip" in summary view Eric Wong
2023-01-10 11:49 ` [PATCH 2/4] www_coderepo: show tree root as "(root)" Eric Wong
2023-01-10 11:49 ` [PATCH 3/4] viewvcs: update comment about show_other_result Eric Wong
2023-01-10 11:49 ` [PATCH 4/4] config: use inbox names to map inboxes <-> coderepos Eric Wong

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).