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 <jaysoffian@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jay Soffian committed
Feb 23, 2009 at 13:51 UTC
afe756c936334a5a374a8e0e8ee70a7f319dd71b
1 file changed
+11
-9
git-send-email.perl
+11
-9
@@ -156,10 +156,7 @@ if ($@) {
156
# Behavior modification variables
157
my ($quiet, $dry_run) = (0, 0);
158
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;
160
161
# Handle interactive edition of files.
162
my $multiedit;
@@ -222,11 +219,13 @@ sub signal_handler {
219
system "stty echo";
220
221
# 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
+ }
229
}
230
231
exit;
@@ -505,6 +504,9 @@ sub get_patch_subject($) {
504
if ($compose) {
505
# Note that this does not need to be secure, but we will make a small
506
# 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];
510
open(C,">",$compose_filename)
511
or die "Failed to open for writing $compose_filename: $!";
512