user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/2] use PublicInbox::Config::each_inbox where appropriate
Date: Tue,  1 Jan 2019 10:18:46 +0000	[thread overview]
Message-ID: <20190101101847.22805-2-e@80x24.org> (raw)
In-Reply-To: <20190101101847.22805-1-e@80x24.org>

No need to reach into PublicInbox::Config internals and iterate
through the hashref by hand
---
 lib/PublicInbox/WatchMaildir.pm | 19 ++++++++-----------
 script/public-inbox-index       | 14 ++++++--------
 2 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm
index 13dea16..b558cda 100644
--- a/lib/PublicInbox/WatchMaildir.pm
+++ b/lib/PublicInbox/WatchMaildir.pm
@@ -45,30 +45,27 @@ sub new {
 	my $spamcheck = PublicInbox::Spamcheck::get($config, $k, $default);
 	$spamcheck = _spamcheck_cb($spamcheck) if $spamcheck;
 
-	# need to make all inboxes writable for spam removal:
-	$config->each_inbox(sub { PublicInbox::InboxWritable->new($_[0]) });
+	$config->each_inbox(sub {
+		# need to make all inboxes writable for spam removal:
+		my $ibx = $_[0] = PublicInbox::InboxWritable->new($_[0]);
 
-	foreach $k (keys %$config) {
-		$k =~ /\Apublicinbox\.([^\.]+)\.watch\z/ or next;
-		my $name = $1;
-		my $watch = $config->{$k};
+		my $watch = $ibx->{watch} or return;
 		if ($watch =~ s/\Amaildir://) {
 			$watch =~ s!/+\z!!;
-			my $inbox = $config->lookup_name($name);
-			if (my $wm = $inbox->{watchheader}) {
+			if (my $wm = $ibx->{watchheader}) {
 				my ($k, $v) = split(/:/, $wm, 2);
-				$inbox->{-watchheader} = [ $k, qr/\Q$v\E/ ];
+				$ibx->{-watchheader} = [ $k, qr/\Q$v\E/ ];
 			}
 			my $new = "$watch/new";
 			my $cur = "$watch/cur";
 			push @mdir, $new, $cur;
 			die "$new already in use\n" if $mdmap{$new};
 			die "$cur already in use\n" if $mdmap{$cur};
-			$mdmap{$new} = $mdmap{$cur} = $inbox;
+			$mdmap{$new} = $mdmap{$cur} = $ibx;
 		} else {
 			warn "watch unsupported: $k=$watch\n";
 		}
-	}
+	});
 	return unless @mdir;
 
 	my $mdre = join('|', map { quotemeta($_) } @mdir);
diff --git a/script/public-inbox-index b/script/public-inbox-index
index e487e3f..73ad9bc 100755
--- a/script/public-inbox-index
+++ b/script/public-inbox-index
@@ -73,16 +73,14 @@ if (@ARGV) {
 sub usage { print STDERR "Usage: $usage\n"; exit 1 }
 usage() unless @dirs;
 
-foreach my $k (keys %$config) {
-	$k =~ /\Apublicinbox\.([^\.]+)\.mainrepo\z/ or next;
-	my $name = $1;
-	my $v = $config->{$k};
+$config->each_inbox(sub {
+	my ($ibx) = @_;
+
 	for my $i (0..$#dirs) {
-		next if $dirs[$i] ne $v;
-		my $ibx = $config->lookup_name($name);
-		$dirs[$i] = $ibx if $ibx;
+		next if $dirs[$i] ne $ibx->{mainrepo};
+		$dirs[$i] = $ibx;
 	}
-}
+});
 
 foreach my $dir (@dirs) {
 	if (!ref($dir) && -f "$dir/inbox.lock") { # v2
-- 
EW


  reply	other threads:[~2019-01-01 10:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-01 10:18 [PATCH 0/2] config-related cleanups Eric Wong
2019-01-01 10:18 ` Eric Wong [this message]
2019-01-01 10:18 ` [PATCH 2/2] config: relax name inbox name restrictions Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190101101847.22805-2-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).