* [PATCH 0/3] www: coderepo-related cleanups + fixes
@ 2021-10-23 20:19 Eric Wong
2021-10-23 20:19 ` [PATCH 1/3] git: simplify local_nick, avoid "foo.git.git" Eric Wong
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Eric Wong @ 2021-10-23 20:19 UTC (permalink / raw)
To: meta
Eric Wong (3):
git: simplify local_nick, avoid "foo.git.git"
config: remove *_url_format support for cgit
www: respect coderepo.*.url during cgit init
lib/PublicInbox/Cgit.pm | 5 +----
lib/PublicInbox/Config.pm | 27 +++++----------------------
lib/PublicInbox/Git.pm | 9 ++-------
t/git.t | 8 +++++++-
4 files changed, 15 insertions(+), 34 deletions(-)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] git: simplify local_nick, avoid "foo.git.git"
2021-10-23 20:19 [PATCH 0/3] www: coderepo-related cleanups + fixes Eric Wong
@ 2021-10-23 20:19 ` Eric Wong
2021-10-23 20:19 ` [PATCH 2/3] config: remove *_url_format support for cgit Eric Wong
2021-10-23 20:19 ` [PATCH 3/3] www: respect coderepo.*.url during cgit init Eric Wong
2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2021-10-23 20:19 UTC (permalink / raw)
To: meta
We need to use a non-greedy regexp to avoid capturing the
".git" suffix in the pathname before blindly appending our
own.
---
lib/PublicInbox/Git.pm | 9 ++-------
t/git.t | 8 +++++++-
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index e634ca55..374a3b4d 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -442,13 +442,8 @@ sub packed_bytes {
sub DESTROY { cleanup(@_) }
sub local_nick ($) {
- my ($self) = @_;
- my $ret = '???';
# don't show full FS path, basename should be OK:
- if ($self->{git_dir} =~ m!/([^/]+)(?:/*\.git/*)?\z!) {
- $ret = "$1.git";
- }
- wantarray ? ($ret) : $ret;
+ $_[0]->{git_dir} =~ m!/([^/]+?)(?:/*\.git/*)?\z! ? "$1.git" : '???';
}
sub host_prefix_url ($$) {
@@ -465,7 +460,7 @@ sub pub_urls {
if (my $urls = $self->{cgit_url}) {
return map { host_prefix_url($env, $_) } @$urls;
}
- local_nick($self);
+ (local_nick($self));
}
sub cat_async_begin {
diff --git a/t/git.t b/t/git.t
index fa541f41..08b4a918 100644
--- a/t/git.t
+++ b/t/git.t
@@ -18,7 +18,13 @@ use PublicInbox::Git;
is($?, 0, 'fast-import succeeded');
}
{
- my $git = PublicInbox::Git->new($dir);
+ my $git = PublicInbox::Git->new("$dir/foo.git");
+ my $nick = $git->local_nick; # internal sub
+ unlike($nick, qr/\.git\.git\z/, "no doubled `.git.git' suffix");
+ like($nick, qr/\.git\z/, "one `.git' suffix");
+ $git = PublicInbox::Git->new($dir);
+ $nick = $git->local_nick; # internal sub
+ like($nick, qr/\.git\z/, "local nick always adds `.git' suffix");
my @s = $git->date_parse('1970-01-01T00:00:00Z');
is($s[0], 0, 'parsed epoch');
local $ENV{TZ} = 'UTC';
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] config: remove *_url_format support for cgit
2021-10-23 20:19 [PATCH 0/3] www: coderepo-related cleanups + fixes Eric Wong
2021-10-23 20:19 ` [PATCH 1/3] git: simplify local_nick, avoid "foo.git.git" Eric Wong
@ 2021-10-23 20:19 ` Eric Wong
2021-10-23 20:19 ` [PATCH 3/3] www: respect coderepo.*.url during cgit init Eric Wong
2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2021-10-23 20:19 UTC (permalink / raw)
To: meta
We're not using them, anywhere.
---
lib/PublicInbox/Config.pm | 20 ++------------------
1 file changed, 2 insertions(+), 18 deletions(-)
diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index d38f6586..f2e5d5f0 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -328,30 +328,14 @@ sub parse_cgitrc {
sub _fill_code_repo {
my ($self, $nick) = @_;
my $pfx = "coderepo.$nick";
-
- my $dir = $self->{"$pfx.dir"}; # aka "GIT_DIR"
- unless (defined $dir) {
+ my $dir = $self->{"$pfx.dir"} // do { # aka "GIT_DIR"
warn "$pfx.dir unset\n";
return;
- }
-
+ };
my $git = PublicInbox::Git->new($dir);
- foreach my $t (qw(blob commit tree tag)) {
- $git->{$t.'_url_format'} =
- _array($self->{lc("$pfx.${t}UrlFormat")});
- }
-
if (defined(my $cgits = $self->{"$pfx.cgiturl"})) {
$git->{cgit_url} = $cgits = _array($cgits);
$self->{"$pfx.cgiturl"} = $cgits;
-
- # cgit supports "/blob/?id=%s", but it's only a plain-text
- # display and requires an unabbreviated id=
- foreach my $t (qw(blob commit tag)) {
- $git->{$t.'_url_format'} //= map {
- "$_/$t/?id=%s"
- } @$cgits;
- }
}
$git;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] www: respect coderepo.*.url during cgit init
2021-10-23 20:19 [PATCH 0/3] www: coderepo-related cleanups + fixes Eric Wong
2021-10-23 20:19 ` [PATCH 1/3] git: simplify local_nick, avoid "foo.git.git" Eric Wong
2021-10-23 20:19 ` [PATCH 2/3] config: remove *_url_format support for cgit Eric Wong
@ 2021-10-23 20:19 ` Eric Wong
2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2021-10-23 20:19 UTC (permalink / raw)
To: meta
This is necessary for showing "found $OID in $CODEREPO_URL"
in solver-generated pages ($INBOX_URL/$OID/s/).
---
lib/PublicInbox/Cgit.pm | 5 +----
lib/PublicInbox/Config.pm | 7 +++----
2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/lib/PublicInbox/Cgit.pm b/lib/PublicInbox/Cgit.pm
index 8ad07be2..cc729aa2 100644
--- a/lib/PublicInbox/Cgit.pm
+++ b/lib/PublicInbox/Cgit.pm
@@ -63,15 +63,12 @@ sub new {
pi_cfg => $pi_cfg,
}, $class;
- # fill in -code_repos mapped to inboxes
- $pi_cfg->each_inbox($pi_cfg->can('repo_objs'));
-
# some cgit repos may not be mapped to inboxes, so ensure those exist:
my $code_repos = $pi_cfg->{-code_repos};
foreach my $k (keys %$pi_cfg) {
$k =~ /\Acoderepo\.(.+)\.dir\z/ or next;
my $dir = $pi_cfg->{$k};
- $code_repos->{$1} ||= PublicInbox::Git->new($dir);
+ $code_repos->{$1} ||= $pi_cfg->fill_code_repo($1);
}
while (my ($nick, $repo) = each %$code_repos) {
$self->{"\0$nick"} = $repo;
diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index f2e5d5f0..41117ac5 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -323,9 +323,8 @@ sub parse_cgitrc {
cgit_repo_merge($self, $repo->{dir}, $repo) if $repo;
}
-# parse a code repo
-# Only git is supported at the moment, but SVN and Hg are possibilities
-sub _fill_code_repo {
+# parse a code repo, only git is supported at the moment
+sub fill_code_repo {
my ($self, $nick) = @_;
my $pfx = "coderepo.$nick";
my $dir = $self->{"$pfx.dir"} // do { # aka "GIT_DIR"
@@ -392,7 +391,7 @@ sub repo_objs {
next;
}
my $repo = $code_repos->{$nick} //=
- _fill_code_repo($self, $nick);
+ fill_code_repo($self, $nick);
push @repo_objs, $repo if $repo;
}
if (scalar @repo_objs) {
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-10-23 20:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-23 20:19 [PATCH 0/3] www: coderepo-related cleanups + fixes Eric Wong
2021-10-23 20:19 ` [PATCH 1/3] git: simplify local_nick, avoid "foo.git.git" Eric Wong
2021-10-23 20:19 ` [PATCH 2/3] config: remove *_url_format support for cgit Eric Wong
2021-10-23 20:19 ` [PATCH 3/3] www: respect coderepo.*.url during cgit init Eric Wong
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).