unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/2] treewide: avoid "delete local" construct on hashes
Date: Tue, 23 Feb 2021 03:38:21 +0600	[thread overview]
Message-ID: <20210222213822.18794-2-e@80x24.org> (raw)
In-Reply-To: <20210222213822.18794-1-e@80x24.org>

Apparently this feature is only in Perl 5.12+, and we're
still on Perl 5.10.
---
 lib/PublicInbox/ExtSearchIdx.pm | 3 ++-
 lib/PublicInbox/Import.pm       | 4 ++--
 lib/PublicInbox/LEI.pm          | 6 ++----
 lib/PublicInbox/Spawn.pm        | 5 ++---
 lib/PublicInbox/TestCommon.pm   | 9 +++++----
 t/spawn.t                       | 6 ++++++
 6 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/lib/PublicInbox/ExtSearchIdx.pm b/lib/PublicInbox/ExtSearchIdx.pm
index a4b3bbd5..d0c9c2f7 100644
--- a/lib/PublicInbox/ExtSearchIdx.pm
+++ b/lib/PublicInbox/ExtSearchIdx.pm
@@ -1011,8 +1011,9 @@ sub _watch_commit { # PublicInbox::DS::add_timer callback
 	delete $self->{-commit_timer};
 	eidxq_process($self, $self->{-watch_sync});
 	eidxq_release($self);
-	delete local $self->{-watch_sync}->{-regen_fmt};
+	my $fmt = delete $self->{-watch_sync}->{-regen_fmt};
 	reindex_checkpoint($self, $self->{-watch_sync});
+	$self->{-watch_sync}->{-regen_fmt} = $fmt;
 
 	# call event_step => done unless commit_timer is armed
 	PublicInbox::DS::requeue($self);
diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm
index e803ee74..b8fa5c21 100644
--- a/lib/PublicInbox/Import.pm
+++ b/lib/PublicInbox/Import.pm
@@ -21,8 +21,8 @@ use POSIX qw(strftime);
 
 sub default_branch () {
 	state $default_branch = do {
-		delete local $ENV{GIT_CONFIG};
-		my $r = popen_rd([qw(git config --global init.defaultBranch)]);
+		my $r = popen_rd([qw(git config --global init.defaultBranch)],
+				 { GIT_CONFIG => undef });
 		chomp(my $h = <$r> // '');
 		close $r;
 		$h eq '' ? 'refs/heads/master' : $h;
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 415a425d..31dbd01f 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -629,13 +629,11 @@ sub lei_mark {
 
 sub _config {
 	my ($self, @argv) = @_;
-	my $env = $self->{env};
-	delete local $env->{GIT_CONFIG};
-	delete local $ENV{GIT_CONFIG};
+	my %env = (%{$self->{env}}, GIT_CONFIG => undef);
 	my $cfg = _lei_cfg($self, 1);
 	my $cmd = [ qw(git config -f), $cfg->{'-f'}, @argv ];
 	my %rdr = map { $_ => $self->{$_} } (0..2);
-	waitpid(spawn($cmd, $env, \%rdr), 0);
+	waitpid(spawn($cmd, \%env, \%rdr), 0);
 }
 
 sub lei_config {
diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm
index 00e6829e..fe7aa0a8 100644
--- a/lib/PublicInbox/Spawn.pm
+++ b/lib/PublicInbox/Spawn.pm
@@ -358,10 +358,9 @@ sub spawn ($;$$) {
 	my $f = which($cmd->[0]) // die "$cmd->[0]: command not found\n";
 	my @env;
 	$opts ||= {};
-
-	my %env = $env ? (%ENV, %$env) : %ENV;
+	my %env = (%ENV, $env ? %$env : ());
 	while (my ($k, $v) = each %env) {
-		push @env, "$k=$v";
+		push @env, "$k=$v" if defined($v);
 	}
 	my $redir = [];
 	for my $child_fd (0..2) {
diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index ca05fa21..fc32b57f 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -483,10 +483,11 @@ SKIP: {
 	require_git(2.6, 1) or skip('git 2.6+ required for lei test', 2);
 	require_mods(qw(json DBD::SQLite Search::Xapian), 2);
 	require PublicInbox::Config;
-	delete local $ENV{XDG_DATA_HOME};
-	delete local $ENV{XDG_CONFIG_HOME};
-	local $ENV{GIT_COMMITTER_EMAIL} = 'lei@example.com';
-	local $ENV{GIT_COMMITTER_NAME} = 'lei user';
+	local %ENV = %ENV;
+	delete $ENV{XDG_DATA_HOME};
+	delete $ENV{XDG_CONFIG_HOME};
+	$ENV{GIT_COMMITTER_EMAIL} = 'lei@example.com';
+	$ENV{GIT_COMMITTER_NAME} = 'lei user';
 	my (undef, $fn, $lineno) = caller(0);
 	my $t = "$fn:$lineno";
 	require PublicInbox::Spawn;
diff --git a/t/spawn.t b/t/spawn.t
index a17b72d9..6168c1f6 100644
--- a/t/spawn.t
+++ b/t/spawn.t
@@ -121,6 +121,12 @@ EOF
 	isnt($?, 0, '$? set properly: '.$?);
 }
 
+{
+	local $ENV{GIT_CONFIG} = '/path/to/this/better/not/exist';
+	my $fh = popen_rd([qw(env)], { GIT_CONFIG => undef });
+	ok(!grep(/^GIT_CONFIG=/, <$fh>), 'GIT_CONFIG clobbered');
+}
+
 { # ->CLOSE vs ->DESTROY waitpid caller distinction
 	my @c;
 	my $fh = popen_rd(['true'], undef, { cb => sub { @c = caller } });

  reply	other threads:[~2021-02-22 21:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-22 21:38 [PATCH 0/2] fix Perl 5.10.1 compatibility Eric Wong
2021-02-22 21:38 ` Eric Wong [this message]
2021-02-22 21:38 ` [PATCH 2/2] lei: avoid needless env passing to subcommands 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: 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=20210222213822.18794-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.
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).