From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/3] git: simplify local_nick, avoid "foo.git.git"
Date: Sat, 23 Oct 2021 20:19:37 +0000 [thread overview]
Message-ID: <20211023201939.27183-2-e@80x24.org> (raw)
In-Reply-To: <20211023201939.27183-1-e@80x24.org>
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';
next prev parent reply other threads:[~2021-10-23 20:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-23 20:19 [PATCH 0/3] www: coderepo-related cleanups + fixes Eric Wong
2021-10-23 20:19 ` Eric Wong [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211023201939.27183-2-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).