X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FWwwCoderepo.pm;h=2fba0cd0be4571152b1e1f4fe49c068f2a22b499;hb=eea4b03f08b40647b7cf6016838d18ae26d98a08;hp=3c9292226b964857b6c9a12337c057f598fd2614;hpb=a30dd4aa9455f4166c6bc18e043fccd645b4231c;p=public-inbox.git diff --git a/lib/PublicInbox/WwwCoderepo.pm b/lib/PublicInbox/WwwCoderepo.pm index 3c929222..2fba0cd0 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; @@ -41,16 +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 - } - while (my ($nick, $repo) = each %$code_repos) { - $self->{"\0$nick"} = $repo; } } @@ -78,15 +74,12 @@ 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 < -about heads tags - -\$ git log --pretty=format:'%h %s (%cs)%d' +
\$ git log --pretty=format:'%h %s (%cs)%d'$tip_html
 EOM
 	for (@r) {
 		my $d; # decorations
@@ -105,8 +98,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), '

';
 	}
@@ -183,16 +178,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'}) {
@@ -211,30 +215,31 @@ sub srv { # endpoint called by PublicInbox::WWW
 	my $path_info = $ctx->{env}->{PATH_INFO};
 	my $git;
 	# handle clone requests
+	my $cr = $self->{pi_cfg}->{-code_repos};
 	if ($path_info =~ m!\A/(.+?)/($PublicInbox::GitHTTPBackend::ANY)\z!x) {
-		$git = $self->{"\0$1"} and return
+		$git = $cr->{$1} and return
 			PublicInbox::GitHTTPBackend::serve($ctx->{env},$git,$2);
 	}
 	$path_info =~ m!\A/(.+?)/\z! and
-		($ctx->{git} = $self->{"\0$1"}) and return summary($self, $ctx);
+		($ctx->{git} = $cr->{$1}) and return summary($self, $ctx);
 	$path_info =~ m!\A/(.+?)/([a-f0-9]+)/s/\z! and
-			($ctx->{git} = $self->{"\0$1"}) and
+			($ctx->{git} = $cr->{$1}) and
 		return PublicInbox::ViewVCS::show($ctx, $2);
 
 	# snapshots:
 	if ($path_info =~ m!\A/(.+?)/snapshot/([^/]+)\z! and
-			($ctx->{git} = $self->{"\0$1"})) {
+			($ctx->{git} = $cr->{$1})) {
 		$ctx->{wcr} = $self;
 		return PublicInbox::RepoSnapshot::srv($ctx, $2) // r(404);
 	}
 
 	if ($path_info =~ m!\A/(.+?)/atom/(.*)\z! and
-			($ctx->{git} = $self->{"\0$1"})) {
+			($ctx->{git} = $cr->{$1})) {
 		return PublicInbox::RepoAtom::srv_atom($ctx, $2) // r(404);
 	}
 
 	# enforce trailing slash:
-	if ($path_info =~ m!\A/(.+?)\z! and ($git = $self->{"\0$1"})) {
+	if ($path_info =~ m!\A/(.+?)\z! and ($git = $cr->{$1})) {
 		my $qs = $ctx->{env}->{QUERY_STRING};
 		my $url = $git->base_url($ctx->{env});
 		$url .= "?$qs" if $qs ne '';