Skip to content

Commit 2eb6752

Browse files
committed
send-email: update the mechanism to set default configuration values
The program has a good mechanism to specify the fallback default values for boolean configuration variables after two invocations of read_config() for "sendmail.$ident.$var" and "sendemail.$var" have not found any configuration. Imitate it so that we can set the default values for non-boolean variables as well. Signed-off-by: Junio C Hamano <[email protected]>
1 parent e67a228 commit 2eb6752

File tree

1 file changed

+33
-23
lines changed

1 file changed

+33
-23
lines changed

git-send-email.perl

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -250,28 +250,28 @@ sub do_edit {
250250
);
251251

252252
my %config_settings = (
253-
"smtpserver" => \$smtp_server,
254-
"smtpserverport" => \$smtp_server_port,
255-
"smtpserveroption" => \@smtp_server_options,
256-
"smtpuser" => \$smtp_authuser,
257-
"smtppass" => \$smtp_authpass,
258-
"smtpdomain" => \$smtp_domain,
259-
"smtpauth" => \$smtp_auth,
260-
"smtpbatchsize" => \$batch_size,
261-
"smtprelogindelay" => \$relogin_delay,
262-
"to" => \@initial_to,
263-
"tocmd" => \$to_cmd,
264-
"cc" => \@initial_cc,
265-
"cccmd" => \$cc_cmd,
266-
"aliasfiletype" => \$aliasfiletype,
267-
"bcc" => \@bcclist,
268-
"suppresscc" => \@suppress_cc,
269-
"envelopesender" => \$envelope_sender,
270-
"confirm" => \$confirm,
271-
"from" => \$sender,
272-
"assume8bitencoding" => \$auto_8bit_encoding,
273-
"composeencoding" => \$compose_encoding,
274-
"transferencoding" => \$target_xfer_encoding,
253+
"smtpserver" => [\$smtp_server],
254+
"smtpserverport" => [\$smtp_server_port],
255+
"smtpserveroption" => [\@smtp_server_options],
256+
"smtpuser" => [\$smtp_authuser],
257+
"smtppass" => [\$smtp_authpass],
258+
"smtpdomain" => [\$smtp_domain],
259+
"smtpauth" => [\$smtp_auth],
260+
"smtpbatchsize" => [\$batch_size],
261+
"smtprelogindelay" => [\$relogin_delay],
262+
"to" => [\@initial_to],
263+
"tocmd" => [\$to_cmd],
264+
"cc" => [\@initial_cc],
265+
"cccmd" => [\$cc_cmd],
266+
"aliasfiletype" => [\$aliasfiletype],
267+
"bcc" => [\@bcclist],
268+
"suppresscc" => [\@suppress_cc],
269+
"envelopesender" => [\$envelope_sender],
270+
"confirm" => [\$confirm],
271+
"from" => [\$sender],
272+
"assume8bitencoding" => [\$auto_8bit_encoding],
273+
"composeencoding" => [\$compose_encoding],
274+
"transferencoding" => [\$target_xfer_encoding],
275275
);
276276

277277
my %config_path_settings = (
@@ -411,7 +411,7 @@ sub read_config {
411411
}
412412

413413
foreach my $setting (keys %config_settings) {
414-
my $target = $config_settings{$setting};
414+
my $target = $config_settings{$setting}->[0];
415415
next if $setting eq "to" and defined $no_to;
416416
next if $setting eq "cc" and defined $no_cc;
417417
next if $setting eq "bcc" and defined $no_bcc;
@@ -446,6 +446,16 @@ sub read_config {
446446
${$setting->[0]} = $setting->[1] unless (defined (${$setting->[0]}));
447447
}
448448

449+
# fall back to builtin defaults
450+
while (my ($name, $setting) = each %config_settings) {
451+
next unless @$setting == 2;
452+
453+
my ($target, $default) = @$setting;
454+
if (ref($target) eq "SCALAR") {
455+
$$target = $default unless defined $$target;
456+
} # elsif ... for other types later.
457+
}
458+
449459
# 'default' encryption is none -- this only prevents a warning
450460
$smtp_encryption = '' unless (defined $smtp_encryption);
451461

0 commit comments

Comments
 (0)