]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LEI.pm
lei: All Local Externals: bare git dir for alternates
[public-inbox.git] / lib / PublicInbox / LEI.pm
index 59a3338c08a69a9415190546b122d06bc14eff3f..0da26a32825755c7f3534d2c50b9c70e04fc06f0 100644 (file)
@@ -83,7 +83,7 @@ sub rel2abs ($$) {
        File::Spec->rel2abs($p, $pwd);
 }
 
-sub _store_path ($) {
+sub store_path ($) {
        my ($self) = @_;
        rel2abs($self, ($self->{env}->{XDG_DATA_HOME} //
                ($self->{env}->{HOME} // '/nonexistent').'/.local/share')
@@ -97,6 +97,22 @@ sub _config_path ($) {
                .'/lei/config');
 }
 
+sub cache_dir ($) {
+       my ($self) = @_;
+       rel2abs($self, ($self->{env}->{XDG_CACHE_HOME} //
+               ($self->{env}->{HOME} // '/nonexistent').'/.cache')
+               .'/lei');
+}
+
+sub ale {
+       my ($self) = @_;
+       $self->{ale} //= do {
+               require PublicInbox::LeiALE;
+               PublicInbox::LeiALE->new(cache_dir($self).
+                                       '/all_locals_ever.git');
+       };
+}
+
 sub index_opt {
        # TODO: drop underscore variants everywhere, they're undocumented
        qw(fsync|sync! jobs|j=i indexlevel|L=s compact
@@ -188,7 +204,7 @@ our %CMD = ( # sorted in order of importance/use:
        }, qw(config-file|system|global|file|f=s), # for conflict detection
         qw(C=s@), pass_through('git config') ],
 'init' => [ '[DIRNAME]', sub {
-       "initialize storage, default: "._store_path($_[0]);
+       "initialize storage, default: ".store_path($_[0]);
        }, qw(quiet|q C=s@) ],
 'daemon-kill' => [ '[-SIGNAL]', 'signal the lei-daemon',
        # "-C DIR" conflicts with -CHLD, here, and chdir makes no sense, here
@@ -412,9 +428,9 @@ sub check_input_format ($;$) {
                return fail($self, "--$opt_key unset for $err");
        }
        require PublicInbox::MboxLock if $files;
+       require PublicInbox::MboxReader;
        return 1 if $fmt eq 'eml';
        # XXX: should this handle {gz,bz2,xz}? that's currently in LeiToMail
-       require PublicInbox::MboxReader;
        PublicInbox::MboxReader->can($fmt) or
                return fail($self, "--$opt_key=$fmt unrecognized");
        1;
@@ -606,8 +622,10 @@ sub _lei_cfg ($;$) {
        my $f = _config_path($self);
        my @st = stat($f);
        my $cur_st = @st ? pack('dd', $st[10], $st[7]) : ''; # 10:ctime, 7:size
+       my ($sto, $sto_dir);
        if (my $cfg = $PATH2CFG{$f}) { # reuse existing object in common case
                return ($self->{cfg} = $cfg) if $cur_st eq $cfg->{-st};
+               ($sto, $sto_dir) = @$cfg{qw(-lei_store leistore.dir)};
        }
        if (!@st) {
                unless ($creat) {
@@ -625,6 +643,10 @@ sub _lei_cfg ($;$) {
        bless $cfg, 'PublicInbox::Config';
        $cfg->{-st} = $cur_st;
        $cfg->{'-f'} = $f;
+       if ($sto && File::Spec->canonpath($sto_dir) eq
+                       File::Spec->canonpath($cfg->{'leistore.dir'})) {
+               $cfg->{-lei_store} = $sto;
+       }
        $self->{cfg} = $PATH2CFG{$f} = $cfg;
 }
 
@@ -634,7 +656,7 @@ sub _lei_store ($;$) {
        $cfg->{-lei_store} //= do {
                require PublicInbox::LeiStore;
                my $dir = $cfg->{'leistore.dir'};
-               $dir //= $creat ? _store_path($self) : return;
+               $dir //= $creat ? store_path($self) : return;
                PublicInbox::LeiStore->new($dir, { creat => $creat });
        };
 }
@@ -683,7 +705,7 @@ sub lei_init {
        my ($self, $dir) = @_;
        my $cfg = _lei_cfg($self, 1);
        my $cur = $cfg->{'leistore.dir'};
-       $dir //= _store_path($self);
+       $dir //= store_path($self);
        $dir = rel2abs($self, $dir);
        my @cur = stat($cur) if defined($cur);
        $cur = File::Spec->canonpath($cur // $dir);