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] public-inbox-init: fix multi-address setup
Date: Sat,  4 Oct 2014 03:06:53 +0000	[thread overview]
Message-ID: <1412392014-6459-1-git-send-email-e@80x24.org> (raw)

We must support multi-address mailing lists, so we do not
clobber existing addresses.  However, we need to ensure
idempotency and ensure existing addresses are not reset.

Furthermore, we were not parsing the existing config correctly
due to a leaking $/.
---
 public-inbox-init | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/public-inbox-init b/public-inbox-init
index 5fc9d3e..2d24402 100644
--- a/public-inbox-init
+++ b/public-inbox-init
@@ -18,6 +18,7 @@ my $git_dir = shift @ARGV or usage();
 my $http_url = shift @ARGV or usage();
 my (@address) = @ARGV;
 @address or usage();
+my %seen;
 
 my $pi_config = PublicInbox::Config->default_file;
 my $dir = dirname($pi_config);
@@ -25,8 +26,11 @@ mkpath($dir); # will croak on fatal errors
 my ($fh, $filename) = tempfile('pi-init-XXXXXXXX', DIR => $dir);
 if (-e $pi_config) {
 	open(my $oh, '<', $pi_config) or die "unable to read $pi_config: $!\n";
-	local $/;
-	my $old = <$oh>;
+	my $old;
+	{
+		local $/;
+		$old = <$oh>;
+	}
 	print $fh $old or die "failed to write: $!\n";
 	close $oh or die "failed to close $pi_config: $!\n";
 
@@ -36,12 +40,16 @@ if (-e $pi_config) {
 	my $conflict;
 	foreach my $addr (@address) {
 		my $found = $cfg->lookup($addr);
-		if ($found && ($found->{listname} ne $name)) {
-			print STDERR
-				"`$addr' already defined for ",
-				"`$found->{listname}',\n",
-				"does not match intend `$name'\n";
-			$conflict = 1;
+		if ($found) {
+			if ($found->{listname} ne $name) {
+				print STDERR
+					"`$addr' already defined for ",
+					"`$found->{listname}',\n",
+					"does not match intend `$name'\n";
+				$conflict = 1;
+			} else {
+				$seen{lc($addr)} = 1;
+			}
 		}
 	}
 
@@ -54,7 +62,8 @@ my @x = (qw/git config/, "--file=$filename");
 $git_dir = expand_filename($git_dir);
 x(qw(git init -q --bare), $git_dir);
 foreach my $addr (@address) {
-	x(@x, "$pfx.address", $addr);
+	next if $seen{lc($addr)};
+	x(@x, "--add", "$pfx.address", $addr);
 }
 x(@x, "$pfx.url", $http_url);
 x(@x, "$pfx.mainrepo", $git_dir);
-- 
EW


                 reply	other threads:[~2014-10-04  3:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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: https://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=1412392014-6459-1-git-send-email-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).