send-email: move the read_config() function above getopts
This is in preparation for a later change where we'll read the config first before parsing command-line options. As the move detection will show no lines (except one line of comment) is changed here, just moved around. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
May 9, 2019 at 13:48 UTC
c573572c52758c4368ebc410d6b801fefa6bcbdd
1 file changed
+48
-49
git-send-email.perl
+48
-49
@@ -307,6 +307,54 @@ sub signal_handler {
307
$SIG{TERM} = \&signal_handler;
308
$SIG{INT} = \&signal_handler;
309
310
+# Read our sendemail.* config
311
+sub read_config {
312
+ my ($prefix) = @_;
313
+
314
+ foreach my $setting (keys %config_bool_settings) {
315
+ my $target = $config_bool_settings{$setting}->[0];
316
+ $$target = Git::config_bool(@repo, "$prefix.$setting") unless (defined $$target);
317
+ }
318
+
319
+ foreach my $setting (keys %config_path_settings) {
320
+ my $target = $config_path_settings{$setting};
321
+ if (ref($target) eq "ARRAY") {
322
+ unless (@$target) {
323
+ my @values = Git::config_path(@repo, "$prefix.$setting");
324
+ @$target = @values if (@values && defined $values[0]);
325
+ }
326
+ }
327
+ else {
328
+ $$target = Git::config_path(@repo, "$prefix.$setting") unless (defined $$target);
329
+ }
330
+ }
331
+
332
+ foreach my $setting (keys %config_settings) {
333
+ my $target = $config_settings{$setting};
334
+ next if $setting eq "to" and defined $no_to;
335
+ next if $setting eq "cc" and defined $no_cc;
336
+ next if $setting eq "bcc" and defined $no_bcc;
337
+ if (ref($target) eq "ARRAY") {
338
+ unless (@$target) {
339
+ my @values = Git::config(@repo, "$prefix.$setting");
340
+ @$target = @values if (@values && defined $values[0]);
341
+ }
342
+ }
343
+ else {
344
+ $$target = Git::config(@repo, "$prefix.$setting") unless (defined $$target);
345
+ }
346
+ }
347
+
348
+ if (!defined $smtp_encryption) {
349
+ my $enc = Git::config(@repo, "$prefix.smtpencryption");
350
+ if (defined $enc) {
351
+ $smtp_encryption = $enc;
352
+ } elsif (Git::config_bool(@repo, "$prefix.smtpssl")) {
353
+ $smtp_encryption = 'ssl';
354
+ }
355
+ }
356
+}
357
+
358
# Begin by accumulating all the variables (defined above), that we will end up
359
# needing, first, from the command line:
360
@@ -387,55 +435,6 @@ die __("`batch-size` and `relogin` must be specified together " .
435
"(via command-line or configuration option)\n")
436
if defined $relogin_delay and not defined $batch_size;
437
390
-# Now, let's fill any that aren't set in with defaults:
391
-
392
-sub read_config {
393
- my ($prefix) = @_;
394
-
395
- foreach my $setting (keys %config_bool_settings) {
396
- my $target = $config_bool_settings{$setting}->[0];
397
- $$target = Git::config_bool(@repo, "$prefix.$setting") unless (defined $$target);
398
- }
399
-
400
- foreach my $setting (keys %config_path_settings) {
401
- my $target = $config_path_settings{$setting};
402
- if (ref($target) eq "ARRAY") {
403
- unless (@$target) {
404
- my @values = Git::config_path(@repo, "$prefix.$setting");
405
- @$target = @values if (@values && defined $values[0]);
406
- }
407
- }
408
- else {
409
- $$target = Git::config_path(@repo, "$prefix.$setting") unless (defined $$target);
410
- }
411
- }
412
-
413
- foreach my $setting (keys %config_settings) {
414
- my $target = $config_settings{$setting};
415
- next if $setting eq "to" and defined $no_to;
416
- next if $setting eq "cc" and defined $no_cc;
417
- next if $setting eq "bcc" and defined $no_bcc;
418
- if (ref($target) eq "ARRAY") {
419
- unless (@$target) {
420
- my @values = Git::config(@repo, "$prefix.$setting");
421
- @$target = @values if (@values && defined $values[0]);
422
- }
423
- }
424
- else {
425
- $$target = Git::config(@repo, "$prefix.$setting") unless (defined $$target);
426
- }
427
- }
428
-
429
- if (!defined $smtp_encryption) {
430
- my $enc = Git::config(@repo, "$prefix.smtpencryption");
431
- if (defined $enc) {
432
- $smtp_encryption = $enc;
433
- } elsif (Git::config_bool(@repo, "$prefix.smtpssl")) {
434
- $smtp_encryption = 'ssl';
435
- }
436
- }
437
-}
438
-
438
# read configuration from [sendemail "$identity"], fall back on [sendemail]
439
$identity = Git::config(@repo, "sendemail.identity") unless (defined $identity);
440
read_config("sendemail.$identity") if (defined $identity);