]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei_store: simplify git_epoch_max, slightly
authorEric Wong <e@80x24.org>
Thu, 17 Dec 2020 00:16:18 +0000 (00:16 +0000)
committerEric Wong <e@80x24.org>
Sat, 19 Dec 2020 09:32:08 +0000 (09:32 +0000)
This follows how we detect the max epoch for v2 and shard count
in Xapian.

lib/PublicInbox/LeiStore.pm

index b5b49efbb7e7329dbd9f64e3840ed743e163a676..d3667d29ba5d4eb42bd42248f94baa46707a90aa 100644 (file)
@@ -18,6 +18,7 @@ use PublicInbox::V2Writable;
 use PublicInbox::ContentHash qw(content_hash);
 use PublicInbox::MID qw(mids);
 use PublicInbox::LeiSearch;
+use List::Util qw(max);
 
 sub new {
        my (undef, $dir, $opt) = @_;
@@ -42,15 +43,13 @@ sub git_pfx { "$_[0]->{priv_eidx}->{topdir}/local" };
 
 sub git_epoch_max  {
        my ($self) = @_;
-       my $pfx = $self->git_pfx;
-       my $max = 0;
-       return $max unless -d $pfx ;
-       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;
-               $max = $1 + 0 if $1 > $max;
+       if (opendir(my $dh, $self->git_pfx)) {
+               max(map {
+                       substr($_, 0, -4) + 0; # drop ".git" suffix
+               } grep(/\A[0-9]+\.git\z/, readdir($dh))) // 0;
+       } else {
+               $!{ENOENT} ? 0 : die("opendir ${\$self->git_pfx}: $!\n");
        }
-       $max;
 }
 
 sub importer {