]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiQuery.pm
lei q: -I/--include overrides --no-(external|local|remote)
[public-inbox.git] / lib / PublicInbox / LeiQuery.pm
index b57d1cc56aa70327dfccd19ab828a9642e3dfc73..532668aebf4a71d4480bbc222b3bc906a7eeb046 100644 (file)
@@ -51,7 +51,10 @@ sub lei_q {
        # we'll allow "--only $LOCATION --local"
        my $sto = $self->_lei_store(1);
        my $lse = $sto->search;
-       $sto->write_prepare($self) if $opt->{'import-remote'} //= 1;
+       if (($opt->{'import-remote'} //= 1) |
+                       (($opt->{'import-before'} //= \1) ? 1 : 0)) {
+               $sto->write_prepare($self);
+       }
        if ($opt->{'local'} //= scalar(@only) ? 0 : 1) {
                $lxs->prepare_external($lse);
        }
@@ -61,9 +64,12 @@ sub lei_q {
                        $lxs->prepare_external($_) for @loc;
                }
        } else {
+               my (@ilocals, @iremotes);
                for my $loc (@{$opt->{include} // []}) {
                        my @loc = $self->get_externals($loc) or return;
                        $lxs->prepare_external($_) for @loc;
+                       @ilocals = @{$lxs->{locals} // []};
+                       @iremotes = @{$lxs->{remotes} // []};
                }
                # --external is enabled by default, but allow --no-external
                if ($opt->{external} //= 1) {
@@ -75,9 +81,9 @@ sub lei_q {
                        my $ne = $self->externals_each(\&prep_ext, $lxs, \%x);
                        $opt->{remote} //= !($lxs->locals - $opt->{'local'});
                        if ($opt->{'local'}) {
-                               delete($lxs->{remotes}) if !$opt->{remote};
+                               $lxs->{remotes} = \@iremotes if !$opt->{remote};
                        } else {
-                               delete($lxs->{locals});
+                               $lxs->{locals} = \@ilocals;
                        }
                }
        }