Junio C Hamano <[email protected]> writes:
> So, here is a two-patch series that tries to do so, primarily done
> to gauge if there still is the level of interest needed to make it
> worth for us to pursue this topic. Here is the first one; I'll send
> the second one that takes advantage of this change separately (but
> it should be trivial to imagine what that step would involve).
>
> -- >8 --
> Subject: [PATCH 1/2] 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]>
> ---
> git-send-email.perl | 51 ++++++++++++++++++++++++++-------------------
> 1 file changed, 29 insertions(+), 22 deletions(-)
This one was embarrassingly buggy, and needs the following squashed
in.
Sorry about that.
git-send-email.perl | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/git-send-email.perl b/git-send-email.perl
index ca7faff094..831947c7ed 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -411,7 +411,7 @@ sub read_config {
}
foreach my $setting (keys %config_settings) {
- my $target = $config_settings{$setting};
+ my $target = $config_settings{$setting}->[0];
next if $setting eq "to" and defined $no_to;
next if $setting eq "cc" and defined $no_cc;
next if $setting eq "bcc" and defined $no_bcc;
@@ -447,10 +447,13 @@ sub read_config {
}
# fall back to builtin defaults
-for my $setting (values %config_settings) {
- if (@$setting == 2 && !defined (${$setting->[0]})) {
- ${$setting->[0]} = $setting->[1];
- }
+while (my ($name, $setting) = each %config_settings) {
+ next unless @$setting == 2;
+
+ my ($target, $default) = @$setting;
+ if (ref($target) eq "SCALAR") {
+ $$target = $default unless defined $target;
+ } # elsif ... for other types later.
}
# 'default' encryption is none -- this only prevents a warning