]> Sergey Matveev's repositories - public-inbox.git/commitdiff
edit: pass global variables into subs
authorEric Wong <e@80x24.org>
Fri, 15 Nov 2019 09:50:32 +0000 (09:50 +0000)
committerEric Wong <e@80x24.org>
Sat, 16 Nov 2019 11:05:23 +0000 (11:05 +0000)
Avoid 'Variable "%s" will not stay shared' warnings
when the contents of this script eval'ed into a sub.

script/public-inbox-edit

index 43ce9900eff3aa06f0d15fc35937adcbc2795d1b..c98840531fd674c1716aeb0a1aed0b77746d725f 100755 (executable)
@@ -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 <<"";