about summary refs log tree commit homepage
path: root/lib/PublicInbox/Inbox.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/Inbox.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/Inbox.pm')
-rw-r--r--lib/PublicInbox/Inbox.pm18
1 files changed, 7 insertions, 11 deletions
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index bd1de0a0..8a3a0194 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -4,10 +4,10 @@
 # Represents a public-inbox (which may have multiple mailing addresses)
 package PublicInbox::Inbox;
 use strict;
-use warnings;
 use PublicInbox::Git;
 use PublicInbox::MID qw(mid2path);
 use PublicInbox::Eml;
+use List::Util qw(max);
 
 # Long-running "git-cat-file --batch" processes won't notice
 # unlinked packs, so we need to restart those processes occasionally.
@@ -155,19 +155,15 @@ sub max_git_epoch {
         my ($self) = @_;
         return if $self->version < 2;
         my $cur = $self->{-max_git_epoch};
-        my $changed = git($self)->alternates_changed;
-        if (!defined($cur) || $changed) {
+        my $changed;
+        if (!defined($cur) || ($changed = git($self)->alternates_changed)) {
                 git_cleanup($self) if $changed;
                 my $gits = "$self->{inboxdir}/git";
                 if (opendir my $dh, $gits) {
-                        my $max = -1;
-                        while (defined(my $git_dir = readdir($dh))) {
-                                $git_dir =~ m!\A([0-9]+)\.git\z! or next;
-                                $max = $1 if $1 > $max;
-                        }
-                        $cur = $self->{-max_git_epoch} = $max if $max >= 0;
-                } else {
-                        warn "opendir $gits failed: $!\n";
+                        my $max = max(map {
+                                substr($_, 0, -4) + 0; # drop ".git" suffix
+                        } grep(/\A[0-9]+\.git\z/, readdir($dh))) // return;
+                        $cur = $self->{-max_git_epoch} = $max;
                 }
         }
         $cur;