From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id C0D6A1F5A2 for ; Fri, 15 Nov 2019 09:51:00 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 01/29] edit: pass global variables into subs Date: Fri, 15 Nov 2019 09:50:32 +0000 Message-Id: <20191115095100.25633-2-e@80x24.org> In-Reply-To: <20191115095100.25633-1-e@80x24.org> References: <20191115095100.25633-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Avoid 'Variable "%s" will not stay shared' warnings when the contents of this script eval'ed into a sub. --- script/public-inbox-edit | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/script/public-inbox-edit b/script/public-inbox-edit index 43ce9900..c9884053 100755 --- a/script/public-inbox-edit +++ b/script/public-inbox-edit @@ -46,9 +46,9 @@ PublicInbox::AdminEdit::check_editable(\@ibxs); my $found = {}; # cid => [ [ibx, smsg] [, [ibx, smsg] ] ] -sub find_mid ($) { - my ($mid) = @_; - foreach my $ibx (@ibxs) { +sub find_mid ($$$) { + my ($found, $mid, $ibxs) = @_; + foreach my $ibx (@$ibxs) { my $over = $ibx->over; my ($id, $prev); while (my $smsg = $over->next_by_mid($mid, \$id, \$prev)) { @@ -68,7 +68,8 @@ sub show_cmd ($$) { " GIT_DIR=$ibx->{inboxdir}/all.git \\\n git show $smsg->{blob}\n"; } -sub show_found () { +sub show_found ($) { + my ($found) = @_; foreach my $to_edit (values %$found) { foreach my $tuple (@$to_edit) { my ($ibx, $smsg) = @$tuple; @@ -79,7 +80,7 @@ sub show_found () { if (defined($mid)) { $mid = mid_clean($mid); - $found = find_mid($mid); + find_mid($found, $mid, \@ibxs); my $nr = scalar(keys %$found); die "No message found for <$mid>\n" unless $nr; if ($nr > 1) { @@ -87,7 +88,7 @@ if (defined($mid)) { Multiple messages with different content found matching <$mid>: - show_found(); + show_found($found); die "Use --force to edit all of them\n" if !$opt->{force}; warn "Will edit all of them\n"; } @@ -96,7 +97,7 @@ Multiple messages with different content found matching my $orig = do { local $/; <$fh> }; my $mime = PublicInbox::MIME->new(\$orig); my $mids = mids($mime->header_obj); - find_mid($_) for (@$mids); # populates $found + find_mid($found, $_, \@ibxs) for (@$mids); # populates $found my $cid = content_id($mime); my $to_edit = $found->{$cid}; unless ($to_edit) { @@ -106,7 +107,7 @@ Multiple messages with different content found matching $nr matches to Message-ID(s) in $file, but none matched content Partial matches below: - show_found(); + show_found($found); } elsif ($nr == 0) { $mids = join('', map { " <$_>\n" } @$mids); warn <<"";