Skip to content

Commit afe756c

Browse files
jaysoffiangitster
authored andcommitted
send-email: don't create temporary compose file until it is needed
Commit eed6ca7 caused a minor regression when it switched to using tempfile() to generate the temporary compose file. Since tempfile() creates the file at the time it generates the filename, zero-length temporary files are being left behind unless --compose is used (in which case the file is cleaned up). This patch fixes the regression by not calling tempfile() to generate the compose filename unless --compose is in use. Signed-off-by: Jay Soffian <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3531e27 commit afe756c

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

git-send-email.perl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,7 @@ sub format_2822_time {
156156
# Behavior modification variables
157157
my ($quiet, $dry_run) = (0, 0);
158158
my $format_patch;
159-
my $compose_filename = ($repo ?
160-
tempfile(".gitsendemail.msg.XXXXXX", DIR => $repo->repo_path()) :
161-
tempfile(".gitsendemail.msg.XXXXXX", DIR => "."))[1];
162-
159+
my $compose_filename;
163160

164161
# Handle interactive edition of files.
165162
my $multiedit;
@@ -222,11 +219,13 @@ sub signal_handler {
222219
system "stty echo";
223220

224221
# tmp files from --compose
225-
if (-e $compose_filename) {
226-
print "'$compose_filename' contains an intermediate version of the email you were composing.\n";
227-
}
228-
if (-e ($compose_filename . ".final")) {
229-
print "'$compose_filename.final' contains the composed email.\n"
222+
if (defined $compose_filename) {
223+
if (-e $compose_filename) {
224+
print "'$compose_filename' contains an intermediate version of the email you were composing.\n";
225+
}
226+
if (-e ($compose_filename . ".final")) {
227+
print "'$compose_filename.final' contains the composed email.\n"
228+
}
230229
}
231230

232231
exit;
@@ -505,6 +504,9 @@ ($)
505504
if ($compose) {
506505
# Note that this does not need to be secure, but we will make a small
507506
# effort to have it be unique
507+
$compose_filename = ($repo ?
508+
tempfile(".gitsendemail.msg.XXXXXX", DIR => $repo->repo_path()) :
509+
tempfile(".gitsendemail.msg.XXXXXX", DIR => "."))[1];
508510
open(C,">",$compose_filename)
509511
or die "Failed to open for writing $compose_filename: $!";
510512

0 commit comments

Comments
 (0)