]> Sergey Matveev's repositories - public-inbox.git/commitdiff
treewide: avoid "delete local" construct on hashes
authorEric Wong <e@80x24.org>
Mon, 22 Feb 2021 21:38:21 +0000 (03:38 +0600)
committerEric Wong <e@80x24.org>
Wed, 24 Feb 2021 11:12:56 +0000 (11:12 +0000)
Apparently this feature is only in Perl 5.12+, and we're
still on Perl 5.10.

lib/PublicInbox/ExtSearchIdx.pm
lib/PublicInbox/Import.pm
lib/PublicInbox/LEI.pm
lib/PublicInbox/Spawn.pm
lib/PublicInbox/TestCommon.pm
t/spawn.t

index a4b3bbd5e57c3255920e89e21b5e95e5a3d6116d..d0c9c2f7075d65034a3259d1024c9a0b77855e24 100644 (file)
@@ -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);
index e803ee74c2b8d06c11e7361ef0f32a5d5fd1363e..b8fa5c217ed99b344019e423cd4a384e6f5bd38c 100644 (file)
@@ -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;
index fec00c020487daa696b911a144aa0f9a8fb17124..28e5365ad6b8bf75d302b8472941e50561446187 100644 (file)
@@ -641,13 +641,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 {
index 00e6829e9483918c92bccefef153c1477c084b2f..fe7aa0a8b5f6fce9a0326cced1efb2a41f84ce6b 100644 (file)
@@ -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) {
index ca05fa215664c5cd6960f4ba0982afce6ba323c5..fc32b57fe92fc7d93ed79f2e38ecf58f0f093738 100644 (file)
@@ -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;
index a17b72d97ff5926d41477647b0ffc273d16d5dc2..6168c1f6171c83919efefa91d7194a5a8b069c1b 100644 (file)
--- 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 } });