send-email: copy "config_regxp" into git-send-email.perl

The config_regexp() function was added in dd84e528a3 (git-send-email: die if sendmail.* config is set, 2020-07-23) for use in git-send-email, and it's the only in-tree user of it. However, the consensus is that Git.pm is a public interface, so even though it's a recently added function we can't change it. So let's copy over a minimal version of it to git-send-email.perl itself. In a subsequent commit it'll be changed further for our own use. 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 28, 2021 at 11:23 UTC 2b110e9ba255120a2d78a5d2cccc842519e341f1
1 file changed +19 -1
git-send-email.perl
+19 -1
@@ -390,6 +390,24 @@ sub read_config {
390 }
391 }
392
393 +sub config_regexp {
394 + my ($regex) = @_;
395 + my @ret;
396 + eval {
397 + @ret = Git::command(
398 + 'config',
399 + '--name-only',
400 + '--get-regexp',
401 + $regex,
402 + );
403 + 1;
404 + } or do {
405 + # If we have no keys we're OK, otherwise re-throw
406 + die $@ if $@->value != 1;
407 + };
408 + return @ret;
409 +}
410 +
411 # sendemail.identity yields to --identity. We must parse this
412 # special-case first before the rest of the config is read.
413 $identity = Git::config(@repo, "sendemail.identity");
@@ -488,7 +506,7 @@ unless ($rc) {
506 usage();
507 }
508
491 -if ($forbid_sendmail_variables && (scalar Git::config_regexp("^sendmail[.]")) != 0) {
509 +if ($forbid_sendmail_variables && (scalar config_regexp("^sendmail[.]")) != 0) {
510 die __("fatal: found configuration options for 'sendmail'\n" .
511 "git-send-email is configured with the sendemail.* options - note the 'e'.\n" .
512 "Set sendemail.forbidSendmailVariables to false to disable this check.\n");