]> Sergey Matveev's repositories - public-inbox.git/commitdiff
git: simplify local_nick, avoid "foo.git.git"
authorEric Wong <e@80x24.org>
Sat, 23 Oct 2021 20:19:37 +0000 (20:19 +0000)
committerEric Wong <e@80x24.org>
Sat, 23 Oct 2021 21:53:55 +0000 (21:53 +0000)
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
t/git.t

index e634ca55fd1f75879d6f8dc15126c7444e21cb80..374a3b4dd71d9849aea7a1c7dee2e8d2e2d8d1f6 100644 (file)
@@ -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 fa541f41179fad34a033309ed25e51570cfd0f78..08b4a9182f60832794292d1aed572fa1741323a3 100644 (file)
--- 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';