From c6038169a77854c26536f1c95176cbeb237e9e11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 30 Sep 2010 13:42:54 +0000 Subject: send-email: use lexical filehandle for opendir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ævar Arnfjörð Bjarmason Reviewed-by: Jeff King > Signed-off-by: Junio C Hamano diff --git a/git-send-email.perl b/git-send-email.perl index 8cc4161..2f18d83 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -512,12 +512,12 @@ while (defined(my $f = shift @ARGV)) { push @rev_list_opts, "--", @ARGV; @ARGV = (); } elsif (-d $f and !check_file_rev_conflict($f)) { - opendir(DH,$f) + opendir my $dh, $f or die "Failed to opendir $f: $!"; push @files, grep { -f $_ } map { catfile($f, $_) } - sort readdir(DH); - closedir(DH); + sort readdir $dh; + closedir $dh; } elsif ((-f $f or -p $f) and !check_file_rev_conflict($f)) { push @files, $f; } else { -- cgit v0.10.2-6-g49f6 From fe0f944f3bbe4adac815808654b16837a05905fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 30 Sep 2010 13:42:55 +0000 Subject: send-email: use lexical filehandles for $compose MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ævar Arnfjörð Bjarmason Reviewed-by: Jeff King > Signed-off-by: Junio C Hamano diff --git a/git-send-email.perl b/git-send-email.perl index 2f18d83..634835c 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -567,7 +567,7 @@ if ($compose) { $compose_filename = ($repo ? tempfile(".gitsendemail.msg.XXXXXX", DIR => $repo->repo_path()) : tempfile(".gitsendemail.msg.XXXXXX", DIR => "."))[1]; - open(C,">",$compose_filename) + open my $c, ">", $compose_filename or die "Failed to open for writing $compose_filename: $!"; @@ -575,7 +575,7 @@ if ($compose) { my $tpl_subject = $initial_subject || ''; my $tpl_reply_to = $initial_reply_to || ''; - print C <",$compose_filename . ".final") + open my $c2, ">", $compose_filename . ".final" or die "Failed to open $compose_filename.final : " . $!; - open(C,"<",$compose_filename) + open $c, "<", $compose_filename or die "Failed to open $compose_filename : " . $!; my $need_8bit_cte = file_has_nonascii($compose_filename); my $in_body = 0; my $summary_empty = 1; - while() { + while(<$c>) { next if m/^GIT:/; if ($in_body) { $summary_empty = 0 unless (/^\n$/); } elsif (/^\n$/) { $in_body = 1; if ($need_8bit_cte) { - print C2 "MIME-Version: 1.0\n", + print $c2 "MIME-Version: 1.0\n", "Content-Type: text/plain; ", "charset=UTF-8\n", "Content-Transfer-Encoding: 8bit\n"; @@ -639,10 +639,10 @@ EOT print "To/Cc/Bcc fields are not interpreted yet, they have been ignored\n"; next; } - print C2 $_; + print $c2 $_; } - close(C); - close(C2); + close $c; + close $c2; if ($summary_empty) { print "Summary email is empty, skipping it\n"; -- cgit v0.10.2-6-g49f6 From f9237e61576c9bd1ba6a00276a9a849a4b5354fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 30 Sep 2010 13:42:56 +0000 Subject: send-email: use lexical filehandles during sending MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ævar Arnfjörð Bjarmason Reviewed-by: Jeff King > Signed-off-by: Junio C Hamano diff --git a/git-send-email.perl b/git-send-email.perl index 634835c..488d894 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -1144,7 +1144,7 @@ $subject = $initial_subject; $message_num = 0; foreach my $t (@files) { - open(F,"<",$t) or die "can't open file $t"; + open my $fh, "<", $t or die "can't open file $t"; my $author = undef; my $author_encoding; @@ -1157,7 +1157,7 @@ foreach my $t (@files) { $message = ""; $message_num++; # First unfold multiline header fields - while() { + while(<$fh>) { last if /^\s*$/; if (/^\s+\S/ and @header) { chomp($header[$#header]); @@ -1233,7 +1233,7 @@ foreach my $t (@files) { } } # Now parse the message body - while() { + while(<$fh>) { $message .= $_; if (/^(Signed-off-by|Cc): (.*)$/i) { chomp; @@ -1250,12 +1250,12 @@ foreach my $t (@files) { $c, $_) unless $quiet; } } - close F; + close $fh; if (defined $cc_cmd && !$suppress_cc{'cccmd'}) { - open(F, "$cc_cmd \Q$t\E |") + open my $fh, "$cc_cmd \Q$t\E |" or die "(cc-cmd) Could not execute '$cc_cmd'"; - while() { + while(<$fh>) { my $c = $_; $c =~ s/^\s*//g; $c =~ s/\n$//g; @@ -1264,7 +1264,7 @@ foreach my $t (@files) { printf("(cc-cmd) Adding cc: %s from: '%s'\n", $c, $cc_cmd) unless $quiet; } - close F + close $fh or die "(cc-cmd) failed to close pipe to '$cc_cmd'"; } -- cgit v0.10.2-6-g49f6 From acf071b0923d9939b8f37ece18d2424f8e627b4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 30 Sep 2010 13:42:57 +0000 Subject: send-email: get_patch_subject doesn't need a prototype MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ævar Arnfjörð Bjarmason Reviewed-by: Jeff King > Signed-off-by: Junio C Hamano diff --git a/git-send-email.perl b/git-send-email.perl index 488d894..b50c963 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -549,7 +549,7 @@ if (@files) { usage(); } -sub get_patch_subject($) { +sub get_patch_subject { my $fn = shift; open (my $fh, '<', $fn); while (my $line = <$fh>) { -- cgit v0.10.2-6-g49f6 From 1d50bfd9c7ae6a0bc7d60b34162c56c670db540d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 30 Sep 2010 13:42:58 +0000 Subject: send-email: file_declares_8bit_cte doesn't need a prototype MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ævar Arnfjörð Bjarmason Reviewed-by: Jeff King > Signed-off-by: Junio C Hamano diff --git a/git-send-email.perl b/git-send-email.perl index b50c963..f471888 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -679,7 +679,7 @@ sub ask { my %broken_encoding; -sub file_declares_8bit_cte($) { +sub file_declares_8bit_cte { my $fn = shift; open (my $fh, '<', $fn); while (my $line = <$fh>) { -- cgit v0.10.2-6-g49f6 From c438ea2a8bd25054057220498eca4caa2aca0131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 30 Sep 2010 13:42:59 +0000 Subject: send-email: unique_email_list doesn't need a prototype MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ævar Arnfjörð Bjarmason Reviewed-by: Jeff King > Signed-off-by: Junio C Hamano diff --git a/git-send-email.perl b/git-send-email.perl index f471888..90b777a 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -136,7 +136,6 @@ my $have_mail_address = eval { require Mail::Address; 1 }; my $smtp; my $auth; -sub unique_email_list(@); sub cleanup_compose_files(); # Variables we fill in automatically, or via prompting: @@ -1332,7 +1331,7 @@ sub cleanup_compose_files() { $smtp->quit if $smtp; -sub unique_email_list(@) { +sub unique_email_list { my %seen; my @emails; -- cgit v0.10.2-6-g49f6 From 4bf597ee05495b6fed37972eac722e5269a6b957 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 30 Sep 2010 13:43:00 +0000 Subject: send-email: cleanup_compose_files doesn't need a prototype MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ævar Arnfjörð Bjarmason Reviewed-by: Jeff King > Signed-off-by: Junio C Hamano diff --git a/git-send-email.perl b/git-send-email.perl index 90b777a..ce9b5eb 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -136,8 +136,6 @@ my $have_mail_address = eval { require Mail::Address; 1 }; my $smtp; my $auth; -sub cleanup_compose_files(); - # Variables we fill in automatically, or via prompting: my (@to,$no_to,@cc,$no_cc,@initial_cc,@bcclist,$no_bcc,@xh, $initial_reply_to,$initial_subject,@files, @@ -1325,7 +1323,7 @@ foreach my $t (@files) { cleanup_compose_files(); -sub cleanup_compose_files() { +sub cleanup_compose_files { unlink($compose_filename, $compose_filename . ".final") if $compose; } -- cgit v0.10.2-6-g49f6 From 0d290a46346f465a735bf50244d033e2257b0326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 30 Sep 2010 13:43:01 +0000 Subject: send-email: use \E***\Q instead of \*\*\* MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change the regex introduced in a03bc5b to use the \E...\Q escape syntax instead of using backslashes. It's more readable like this, and easier to grep for. Signed-off-by: Ævar Arnfjörð Bjarmason Reviewed-by: Jeff King > Signed-off-by: Junio C Hamano diff --git a/git-send-email.perl b/git-send-email.perl index ce9b5eb..1218bbe 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -705,7 +705,7 @@ if (!defined $auto_8bit_encoding && scalar %broken_encoding) { if (!$force) { for my $f (@files) { - if (get_patch_subject($f) =~ /\*\*\* SUBJECT HERE \*\*\*/) { + if (get_patch_subject($f) =~ /\Q*** SUBJECT HERE ***\E/) { die "Refusing to send because the patch\n\t$f\n" . "has the template subject '*** SUBJECT HERE ***'. " . "Pass --force if you really want to send.\n"; -- cgit v0.10.2-6-g49f6 From ff483897317b5379e189d6bd782270dd08c09966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 30 Sep 2010 13:43:02 +0000 Subject: send-email: sanitize_address use $foo, not "$foo" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There's no reason to explicitly stringify a variable in Perl unless it's an overloaded object and you want to call overload::StrVal, otherwise it's just creating a new scalar redundantly. Signed-off-by: Ævar Arnfjörð Bjarmason Reviewed-by: Jeff King > Signed-off-by: Junio C Hamano diff --git a/git-send-email.perl b/git-send-email.perl index 1218bbe..1bf090a 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -864,7 +864,7 @@ sub sanitize_address { my ($recipient_name, $recipient_addr) = ($recipient =~ /^(.*?)\s*(<.*)/); if (not $recipient_name) { - return "$recipient"; + return $recipient; } # if recipient_name is already quoted, do nothing -- cgit v0.10.2-6-g49f6 From d5c7d69d0fa25f1b5df50e12280a622f28319f16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 30 Sep 2010 13:43:03 +0000 Subject: send-email: sanitize_address use qq["foo"], not "\"foo\"" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Perl provides an alternate quote syntax which can make using "" inside interpolated strings easier to read. Signed-off-by: Ævar Arnfjörð Bjarmason Reviewed-by: Jeff King > Signed-off-by: Junio C Hamano diff --git a/git-send-email.perl b/git-send-email.perl index 1bf090a..c012b95 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -881,7 +881,7 @@ sub sanitize_address { # double quotes are needed if specials or CTLs are included elsif ($recipient_name =~ /[][()<>@,;:\\".\000-\037\177]/) { $recipient_name =~ s/(["\\\r])/\\$1/g; - $recipient_name = "\"$recipient_name\""; + $recipient_name = qq["$recipient_name"]; } return "$recipient_name $recipient_addr"; -- cgit v0.10.2-6-g49f6 From e9bf741b887aadd227557804d3560ebd07b1dd09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 30 Sep 2010 13:43:04 +0000 Subject: send-email: use (?:) instead of () if no match variables are needed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ævar Arnfjörð Bjarmason Reviewed-by: Jeff King > Signed-off-by: Junio C Hamano diff --git a/git-send-email.perl b/git-send-email.perl index c012b95..5a0c4a8 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -365,7 +365,7 @@ my(%suppress_cc); if (@suppress_cc) { foreach my $entry (@suppress_cc) { die "Unknown --suppress-cc field: '$entry'\n" - unless $entry =~ /^(all|cccmd|cc|author|self|sob|body|bodycc)$/; + unless $entry =~ /^(?:all|cccmd|cc|author|self|sob|body|bodycc)$/; $suppress_cc{$entry} = 1; } } -- cgit v0.10.2-6-g49f6 From 5e2c2ab1599f0a7a26b58adf1a3b9314e51bfb5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 30 Sep 2010 13:43:07 +0000 Subject: send-email: send_message die on $!, not $? MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If close fails we want to emit errno, not the return code of whatever happened to be the child process run. Signed-off-by: Ævar Arnfjörð Bjarmason Reviewed-by: Jeff King > Signed-off-by: Junio C Hamano diff --git a/git-send-email.perl b/git-send-email.perl index 5a0c4a8..1e7adc2 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -1035,7 +1035,7 @@ X-Mailer: git-send-email $gitversion exec($smtp_server, @sendmail_parameters) or die $!; } print $sm "$header\n$message"; - close $sm or die $?; + close $sm or die $!; } else { if (!defined $smtp_server) { -- cgit v0.10.2-6-g49f6 From 529dd386dda6c6e6d0dad801785d2d943756fb3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 30 Sep 2010 13:43:08 +0000 Subject: send-email: make_message_id use "require" instead of "use" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change the use of Sys::Hostname from a "use" to a "require". The former happens in an implicit BEGIN block and is thus immune from the if block it's contained in, so it's always loaded. This should speed up the invocation of git-send-email by a few milliseconds. Signed-off-by: Ævar Arnfjörð Bjarmason Reviewed-by: Jeff King > Signed-off-by: Junio C Hamano diff --git a/git-send-email.perl b/git-send-email.perl index 1e7adc2..bfc6d4b 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -819,7 +819,7 @@ sub make_message_id { last if (defined $du_part and $du_part ne ''); } if (not defined $du_part or $du_part eq '') { - use Sys::Hostname qw(); + require Sys::Hostname; $du_part = 'user@' . Sys::Hostname::hostname(); } my $message_id_template = "<%s-git-send-email-%s>"; -- cgit v0.10.2-6-g49f6 From 41ae8f1d6cf70f32328c984cdbe51d0f156cd501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 30 Sep 2010 13:43:09 +0000 Subject: send-email: use Perl idioms in while loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change `while(<$fh>) { my $c = $_' to `while(my $c = <$fh>) {', and use `chomp $c' instead of `$c =~ s/\n$//g;', the two are equivalent in this case. I've also changed the --cccmd test so that we test for the stripping of whitespace at the beginning of the lines returned from the --cccmd. I think we probably shouldn't do this, but it was there already so I haven't changed the behavior. Signed-off-by: Ævar Arnfjörð Bjarmason Reviewed-by: Jeff King > Signed-off-by: Junio C Hamano diff --git a/git-send-email.perl b/git-send-email.perl index bfc6d4b..036e4b4 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -1252,10 +1252,9 @@ foreach my $t (@files) { if (defined $cc_cmd && !$suppress_cc{'cccmd'}) { open my $fh, "$cc_cmd \Q$t\E |" or die "(cc-cmd) Could not execute '$cc_cmd'"; - while(<$fh>) { - my $c = $_; + while(my $c = <$fh>) { + chomp $c; $c =~ s/^\s*//g; - $c =~ s/\n$//g; next if ($c eq $sender and $suppress_from); push @cc, $c; printf("(cc-cmd) Adding cc: %s from: '%s'\n", diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 6f67da4..99a16d5 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -204,7 +204,7 @@ test_expect_success $PREREQ 'Prompting works' ' test_expect_success $PREREQ 'cccmd works' ' clean_fake_sendmail && cp $patches cccmd.patch && - echo cccmd--cccmd@example.com >>cccmd.patch && + echo "cccmd-- cccmd@example.com" >>cccmd.patch && { echo "#!$SHELL_PATH" echo sed -n -e s/^cccmd--//p \"\$1\" -- cgit v0.10.2-6-g49f6 From 49f73852c80ee681c179ee2eb76b1a792d7b1b22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 30 Sep 2010 13:43:05 +0000 Subject: send-email: is_rfc2047_quoted use qr// regexes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano diff --git a/git-send-email.perl b/git-send-email.perl index 036e4b4..1890409 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -852,8 +852,8 @@ sub quote_rfc2047 { sub is_rfc2047_quoted { my $s = shift; - my $token = '[^][()<>@,;:"\/?.= \000-\037\177-\377]+'; - my $encoded_text = '[!->@-~]+'; + my $token = qr/[^][()<>@,;:"\/?.= \000-\037\177-\377]+/; + my $encoded_text = qr/[!->@-~]+/; length($s) <= 75 && $s =~ m/^(?:"[[:ascii:]]*"|=\?$token\?$token\?$encoded_text\?=)$/o; } -- cgit v0.10.2-6-g49f6 From 35b6ab955d2288e1c2671bde67298ed3abe32781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 30 Sep 2010 19:03:31 +0000 Subject: send-email: extract_valid_address use qr// regexes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano diff --git a/git-send-email.perl b/git-send-email.perl index 1890409..db17aae 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -777,8 +777,8 @@ our ($message_id, %mail, $subject, $reply_to, $references, $message, sub extract_valid_address { my $address = shift; - my $local_part_regexp = '[^<>"\s@]+'; - my $domain_regexp = '[^.<>"\s@]+(?:\.[^.<>"\s@]+)+'; + my $local_part_regexp = qr/[^<>"\s@]+/; + my $domain_regexp = qr/[^.<>"\s@]+(?:\.[^.<>"\s@]+)+/; # check for a local address: return $address if ($address =~ /^($local_part_regexp)$/); -- cgit v0.10.2-6-g49f6