* [PATCH 1/4] cindex: simplify some internal data structures
2023-03-28 2:59 7% [PATCH 0/4] cindex updates Eric Wong
@ 2023-03-28 2:59 7% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2023-03-28 2:59 UTC (permalink / raw)
To: meta
We'll rely more on local-ized `our' globals rather than
hashref fields. The former is more resistant to typos
and can be checked at compile-time earlier via `perl -c'.
The {-internal} field is also renamed to {-cidx_internal}
in case to reduce confusion within a large code base.
---
lib/PublicInbox/CodeSearchIdx.pm | 22 +++++++++-------------
script/public-inbox-cindex | 2 +-
2 files changed, 10 insertions(+), 14 deletions(-)
diff --git a/lib/PublicInbox/CodeSearchIdx.pm b/lib/PublicInbox/CodeSearchIdx.pm
index e353f452..85e44cdc 100644
--- a/lib/PublicInbox/CodeSearchIdx.pm
+++ b/lib/PublicInbox/CodeSearchIdx.pm
@@ -289,10 +289,9 @@ sub docids_by_postlist ($$) { # consider moving to PublicInbox::Search
@ids;
}
-sub run_todo ($) {
- my ($self) = @_;
+sub run_deferred () {
my $n;
- while (defined(my $x = shift(@{$self->{todo} // []}))) {
+ while (defined(my $x = shift(@{$DEFER // []}))) {
my $cb = shift @$x;
$cb->(@$x);
++$n;
@@ -308,12 +307,12 @@ sub need_reap { # post_loop_do
sub cidx_reap ($$) {
my ($self, $jobs) = @_;
- while (run_todo($self)) {}
+ while (run_deferred()) {}
local @PublicInbox::DS::post_loop_do = (\&need_reap, $jobs);
while (need_reap(undef, $jobs)) {
PublicInbox::DS::event_loop($MY_SIG, $SIGSET);
}
- while (!$jobs && run_todo($self)) {}
+ while (!$jobs && run_deferred()) {}
}
sub cidx_await_cb { # awaitpid cb
@@ -527,7 +526,7 @@ sub index_repo { # cidx_await cb
$consumers->{$repo->{shard_n}} = undef;
commit_used_shards($self, $git, $consumers);
progress($self, "$git->{git_dir}: done");
- return run_todo($self);
+ return run_deferred();
}
die "E: store_repo $git->{git_dir}: id=$id";
}
@@ -725,7 +724,7 @@ sub prep_umask ($) {
my ($self) = @_;
my $um;
my $cur = umask;
- if ($self->{-internal}) { # respect core.sharedRepository
+ if ($self->{-cidx_internal}) { # respect core.sharedRepository
@{$self->{git_dirs}} == 1 or die 'BUG: only for GIT_DIR';
# yuck, FIXME move umask handling out of inbox-specific stuff
require PublicInbox::InboxWritable;
@@ -750,14 +749,12 @@ sub prep_umask ($) {
sub cidx_run { # main entry point
my ($self) = @_;
my $restore_umask = prep_umask($self);
- local $self->{todo} = [];
- local $DEFER = $self->{todo};
+ local $DEFER = [];
local $SIGSET = PublicInbox::DS::block_signals();
my $restore = PublicInbox::OnDestroy->new($$,
\&PublicInbox::DS::sig_setmask, $SIGSET);
local $LIVE = {};
- local $DO_QUIT;
- local $TMP_GIT;
+ local ($DO_QUIT, $TMP_GIT, $REINDEX);
local @IDX_SHARDS = cidx_init($self);
local $self->{current_info} = '';
local $MY_SIG = {
@@ -772,8 +769,7 @@ sub cidx_run { # main entry point
$m =~ s/\A(#?\s*)/$1$self->{current_info}: /;
$cb->($m, @_);
};
- load_existing($self) unless $self->{-internal};
- local $REINDEX;
+ load_existing($self) unless $self->{-cidx_internal};
if ($self->{-opt}->{reindex}) {
require PublicInbox::SharedKV;
$REINDEX = PublicInbox::SharedKV->new;
diff --git a/script/public-inbox-cindex b/script/public-inbox-cindex
index fb906bad..4c9136cf 100755
--- a/script/public-inbox-cindex
+++ b/script/public-inbox-cindex
@@ -79,7 +79,7 @@ EOM
for my $gd (@git_dirs) {
my $cd = "$gd/public-inbox-cindex";
my $cidx = PublicInbox::CodeSearchIdx->new($cd, { %$opt });
- $cidx->{-internal} = 1;
+ $cidx->{-cidx_internal} = 1;
@{$cidx->{git_dirs}} = ($gd);
$cidx->cidx_run;
}
^ permalink raw reply related [relevance 7%]
* [PATCH 0/4] cindex updates
@ 2023-03-28 2:59 7% Eric Wong
2023-03-28 2:59 7% ` [PATCH 1/4] cindex: simplify some internal data structures Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2023-03-28 2:59 UTC (permalink / raw)
To: meta
cindex --prune is less intrusive w.r.t. handling new
commits, now.
I'm embracing `local' more because this is a Perl codebase;
and I think it makes things more robust against typos.
I probably should've been doing this years ago :x
Eric Wong (4):
cindex: simplify some internal data structures
cindex: always break out of event loop on $DO_QUIT
cindex: interleave prune with indexing
cindex: leave SIGTSTP and SIGCONT unblocked
lib/PublicInbox/CodeSearchIdx.pm | 298 ++++++++++++++++++++-----------
lib/PublicInbox/DS.pm | 5 +-
lib/PublicInbox/SearchIdx.pm | 12 +-
script/public-inbox-cindex | 2 +-
4 files changed, 210 insertions(+), 107 deletions(-)
^ permalink raw reply [relevance 7%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2023-03-28 2:59 7% [PATCH 0/4] cindex updates Eric Wong
2023-03-28 2:59 7% ` [PATCH 1/4] cindex: simplify some internal data structures Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).