From patchwork Wed May 8 10:56:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 10934943 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 09A811515 for ; Wed, 8 May 2019 10:56:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDAF72856D for ; Wed, 8 May 2019 10:56:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E22B828803; Wed, 8 May 2019 10:56:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A1122856D for ; Wed, 8 May 2019 10:56:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727182AbfEHK4N (ORCPT ); Wed, 8 May 2019 06:56:13 -0400 Received: from pb-smtp1.pobox.com ([64.147.108.70]:63066 "EHLO pb-smtp1.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726931AbfEHK4M (ORCPT ); Wed, 8 May 2019 06:56:12 -0400 Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 8378A1516A8; Wed, 8 May 2019 06:56:10 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=r0R44+xQkgtdv8AIoc4x3ZGVA Zo=; b=TmGmIhCLF1kttN23+tVmOqoNeopNAw2S2HR5wMUCudWmFD+MVUcOCVKwz 72+Y7iPqbmdphRGBptdkVXq032fMSBh0kzKPGufEG94UohEGG/sXep4ao0VNTtR5 sK1sFpbV7MnHfhcrn3XZ8PrgwxsNhURS8RT2ZMCCZrbhY4+mqg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; q=dns; s=sasl; b=joubww0T2cgfg3Dbx3C Q41W5PkOh9YhGCNyxIxMoXQWRDB+67Cj2lWRNuDOhHL4+JRJ7PkIFydDq+9l+Lru ccns8iTg94d9ZJn4v6JjJzSQzfjsshkRRaSvyh2kVNBoeshTJtWW9jmdAnhRsw7w 0sN/lfvpLnbTG3hLYiUFBBOM= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 7B8901516A7; Wed, 8 May 2019 06:56:10 -0400 (EDT) Received: from pobox.com (unknown [34.76.255.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id E724C1516A6; Wed, 8 May 2019 06:56:09 -0400 (EDT) From: Junio C Hamano To: git@vger.kernel.org Cc: Heinrich Schuchardt , Brian M Carlson , Jonathan Nieder Subject: [PATCH v2 1/2] send-email: update the mechanism to set default configuration values Date: Wed, 8 May 2019 19:56:06 +0900 Message-Id: <20190508105607.178244-2-gitster@pobox.com> X-Mailer: git-send-email 2.21.0-777-g83232e3864 In-Reply-To: References: MIME-Version: 1.0 X-Pobox-Relay-ID: E34A6E82-717F-11E9-B136-46F8B7964D18-77302942!pb-smtp1.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- git-send-email.perl | 56 ++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index f4c07908d2..98bc295c6e 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -250,28 +250,28 @@ sub do_edit { ); my %config_settings = ( - "smtpserver" => \$smtp_server, - "smtpserverport" => \$smtp_server_port, - "smtpserveroption" => \@smtp_server_options, - "smtpuser" => \$smtp_authuser, - "smtppass" => \$smtp_authpass, - "smtpdomain" => \$smtp_domain, - "smtpauth" => \$smtp_auth, - "smtpbatchsize" => \$batch_size, - "smtprelogindelay" => \$relogin_delay, - "to" => \@initial_to, - "tocmd" => \$to_cmd, - "cc" => \@initial_cc, - "cccmd" => \$cc_cmd, - "aliasfiletype" => \$aliasfiletype, - "bcc" => \@bcclist, - "suppresscc" => \@suppress_cc, - "envelopesender" => \$envelope_sender, - "confirm" => \$confirm, - "from" => \$sender, - "assume8bitencoding" => \$auto_8bit_encoding, - "composeencoding" => \$compose_encoding, - "transferencoding" => \$target_xfer_encoding, + "smtpserver" => [\$smtp_server], + "smtpserverport" => [\$smtp_server_port], + "smtpserveroption" => [\@smtp_server_options], + "smtpuser" => [\$smtp_authuser], + "smtppass" => [\$smtp_authpass], + "smtpdomain" => [\$smtp_domain], + "smtpauth" => [\$smtp_auth], + "smtpbatchsize" => [\$batch_size], + "smtprelogindelay" => [\$relogin_delay], + "to" => [\@initial_to], + "tocmd" => [\$to_cmd], + "cc" => [\@initial_cc], + "cccmd" => [\$cc_cmd], + "aliasfiletype" => [\$aliasfiletype], + "bcc" => [\@bcclist], + "suppresscc" => [\@suppress_cc], + "envelopesender" => [\$envelope_sender], + "confirm" => [\$confirm], + "from" => [\$sender], + "assume8bitencoding" => [\$auto_8bit_encoding], + "composeencoding" => [\$compose_encoding], + "transferencoding" => [\$target_xfer_encoding], ); my %config_path_settings = ( @@ -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; @@ -446,6 +446,16 @@ sub read_config { ${$setting->[0]} = $setting->[1] unless (defined (${$setting->[0]})); } +# fall back to builtin defaults +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 $smtp_encryption = '' unless (defined $smtp_encryption);