X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FWwwCoderepo.pm;h=f9c150c0604a6f6c1b8146b503c9715b5b16c85a;hb=16f317f32bd5306d852b7d079b20cd0e4f2b4ff9;hp=2184e89d14572e0012bd9a2b0490c7b4cf2a6e52;hpb=cb4f3af963674ccdb0d540656bd2c58f9e130cf9;p=public-inbox.git diff --git a/lib/PublicInbox/WwwCoderepo.pm b/lib/PublicInbox/WwwCoderepo.pm index 2184e89d..f9c150c0 100644 --- a/lib/PublicInbox/WwwCoderepo.pm +++ b/lib/PublicInbox/WwwCoderepo.pm @@ -15,7 +15,10 @@ 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; +use PublicInbox::RepoTree; my $EACH_REF = "git for-each-ref --sort=-creatordate --format='%(HEAD)%00". join('%00', map { "%($_)" } @@ -27,16 +30,24 @@ sub prepare_coderepos { my $pi_cfg = $self->{pi_cfg}; # TODO: support gitweb and other repository viewers? - defined($pi_cfg->{'publicinbox.cgitrc'}) and - $pi_cfg->parse_cgitrc(undef, 0); + $pi_cfg->parse_cgitrc(undef, 0); my $code_repos = $pi_cfg->{-code_repos}; for my $k (grep(/\Acoderepo\.(?:.+)\.dir\z/, keys %$pi_cfg)) { $k = substr($k, length('coderepo.'), -length('.dir')); $code_repos->{$k} //= $pi_cfg->fill_code_repo($k); } - while (my ($nick, $repo) = each %$code_repos) { - $self->{"\0$nick"} = $repo; + + # associate inboxes and extindices with coderepos for search: + for my $k (grep(/\Apublicinbox\.(?:.+)\.coderepo\z/, keys %$pi_cfg)) { + $k = substr($k, length('publicinbox.'), -length('.coderepo')); + my $ibx = $pi_cfg->lookup_name($k) // next; + $pi_cfg->repo_objs($ibx); + } + 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); } } @@ -64,15 +75,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
@@ -91,8 +99,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), '

';
 	}
@@ -169,16 +179,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'}) {
@@ -197,25 +216,36 @@ 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);
-	$path_info =~ m!\A/(.+?)/([a-f0-9]+)/s/\z! and
-			($ctx->{git} = $self->{"\0$1"}) and
-		return PublicInbox::ViewVCS::show($ctx, $2);
+		($ctx->{git} = $cr->{$1}) and return summary($self, $ctx);
+	$path_info =~ m!\A/(.+?)/([a-f0-9]+)/s/([^/]+)?\z! and
+			($ctx->{git} = $cr->{$1}) and
+		return PublicInbox::ViewVCS::show($ctx, $2, $3);
+
+	if ($path_info =~ m!\A/(.+?)/tree/(.*)\z! and
+			($ctx->{git} = $cr->{$1})) {
+		return PublicInbox::RepoTree::srv_tree($ctx, $2) // r(404);
+	}
 
 	# 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} = $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 '';