about summary refs log tree commit homepage
path: root/lib/PublicInbox/InboxWritable.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-12-16 23:19:04 +0000
committerEric Wong <e@80x24.org>2020-12-17 19:41:14 +0000
commitdbf250d9423ccc38377c35eef8d43e3e11723253 (patch)
tree9d29ec1355eae9bb8e46981ecd181074f4809cf8 /lib/PublicInbox/InboxWritable.pm
parent519f80bb052a446ffa604a0862a631d846f64468 (diff)
downloadpublic-inbox-dbf250d9423ccc38377c35eef8d43e3e11723253.tar.gz
Perl readdir detects list context and can return an array
suitable for the grep op.  From there, we can rely on
substr to remove the ".git" suffix and integerize the value
to save a few bytes before letting List::Util::max return
the value.

This is how we detect Xapian shards nowadays, too, and
we'll also use defined-or (//) to simplify the return
value there.

We'll also simplify InboxWritable->git_dir_latest,
remove some callers, and consider removing it entirely.
Diffstat (limited to 'lib/PublicInbox/InboxWritable.pm')
-rw-r--r--lib/PublicInbox/InboxWritable.pm17
1 files changed, 3 insertions, 14 deletions
diff --git a/lib/PublicInbox/InboxWritable.pm b/lib/PublicInbox/InboxWritable.pm
index bdfae2f8..48d2267f 100644
--- a/lib/PublicInbox/InboxWritable.pm
+++ b/lib/PublicInbox/InboxWritable.pm
@@ -303,22 +303,11 @@ sub warn_ignore_cb {
 # v2+ only
 sub git_dir_n { "$_[0]->{inboxdir}/git/$_[1].git" }
 
-# v2+ only
+# v2+ only, XXX: maybe we can just rely on ->max_git_epoch and remove
 sub git_dir_latest {
         my ($self, $max) = @_;
-        $$max = -1;
-        my $pfx = "$self->{inboxdir}/git";
-        return unless -d $pfx;
-        my $latest;
-        opendir my $dh, $pfx or die "opendir $pfx: $!\n";
-        while (defined(my $git_dir = readdir($dh))) {
-                $git_dir =~ m!\A([0-9]+)\.git\z! or next;
-                if ($1 > $$max) {
-                        $$max = $1;
-                        $latest = "$pfx/$git_dir";
-                }
-        }
-        $latest;
+        defined($$max = $self->max_git_epoch) ?
+                "$self->{inboxdir}/git/$$max.git" : undef;
 }
 
 1;