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: [PATCH 01/16] 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 --- git-send-email.perl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 8cc416115..2f18d8307 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -512,12 +512,12 @@ ($) 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 { 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: [PATCH 02/16] 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 --- git-send-email.perl | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 2f18d8307..634835c83 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -567,7 +567,7 @@ ($) $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 @@ ($) 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 @@ ($) 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"; 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: [PATCH 03/16] 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 --- git-send-email.perl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 634835c83..488d8947d 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -1144,7 +1144,7 @@ sub send_message { $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 @@ sub send_message { $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 @@ sub send_message { } } # Now parse the message body - while() { + while(<$fh>) { $message .= $_; if (/^(Signed-off-by|Cc): (.*)$/i) { chomp; @@ -1250,12 +1250,12 @@ sub send_message { $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 @@ sub send_message { 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'"; } 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: [PATCH 04/16] 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 --- git-send-email.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-send-email.perl b/git-send-email.perl index 488d8947d..b50c96379 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -549,7 +549,7 @@ ($) usage(); } -sub get_patch_subject($) { +sub get_patch_subject { my $fn = shift; open (my $fh, '<', $fn); while (my $line = <$fh>) { 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: [PATCH 05/16] 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 --- git-send-email.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-send-email.perl b/git-send-email.perl index b50c96379..f47188888 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>) { 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: [PATCH 06/16] 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 --- git-send-email.perl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index f47188888..90b777a9f 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -136,7 +136,6 @@ sub format_2822_time { my $smtp; my $auth; -sub unique_email_list(@); sub cleanup_compose_files(); # Variables we fill in automatically, or via prompting: @@ -1332,7 +1331,7 @@ () $smtp->quit if $smtp; -sub unique_email_list(@) { +sub unique_email_list { my %seen; my @emails; 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: [PATCH 07/16] 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 --- git-send-email.perl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 90b777a9f..ce9b5ebd4 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -136,8 +136,6 @@ sub format_2822_time { 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 @@ sub send_message { cleanup_compose_files(); -sub cleanup_compose_files() { +sub cleanup_compose_files { unlink($compose_filename, $compose_filename . ".final") if $compose; } 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: [PATCH 08/16] 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 --- git-send-email.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-send-email.perl b/git-send-email.perl index ce9b5ebd4..1218bbe72 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -705,7 +705,7 @@ sub file_declares_8bit_cte { 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"; 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: [PATCH 09/16] 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 --- git-send-email.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-send-email.perl b/git-send-email.perl index 1218bbe72..1bf090a88 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 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: [PATCH 10/16] 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 --- git-send-email.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-send-email.perl b/git-send-email.perl index 1bf090a88..c012b9556 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"; 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: [PATCH 11/16] 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 --- git-send-email.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-send-email.perl b/git-send-email.perl index c012b9556..5a0c4a8ae 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -365,7 +365,7 @@ sub read_config { 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; } } 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: [PATCH 12/16] 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 --- git-send-email.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-send-email.perl b/git-send-email.perl index 5a0c4a8ae..1e7adc209 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -1035,7 +1035,7 @@ sub send_message { 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) { 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: [PATCH 13/16] 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 --- git-send-email.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-send-email.perl b/git-send-email.perl index 1e7adc209..bfc6d4b45 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>"; 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: [PATCH 14/16] 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 --- git-send-email.perl | 5 ++--- t/t9001-send-email.sh | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index bfc6d4b45..036e4b425 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -1252,10 +1252,9 @@ sub send_message { 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 6f67da4e7..99a16d575 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\" 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: [PATCH 15/16] 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 --- git-send-email.perl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 036e4b425..189040923 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; } 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: [PATCH 16/16] 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 --- git-send-email.perl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 189040923..db17aae02 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -777,8 +777,8 @@ sub expand_one_alias { 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)$/);