summaryrefslogtreecommitdiff
path: root/git-send-email.perl
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2021-05-28 09:23:51 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-05-28 09:38:07 (GMT)
commitc95e3a3f0b8107b5dc7eac9dfdb9e5238280c9fb (patch)
tree915442f5fa9899f43916728f0e2aabe37a8cc9b0 /git-send-email.perl
parent5a544a4e11e2a08a813215c1b9cc80cc1555c7c2 (diff)
downloadgit-c95e3a3f0b8107b5dc7eac9dfdb9e5238280c9fb.zip
git-c95e3a3f0b8107b5dc7eac9dfdb9e5238280c9fb.tar.gz
git-c95e3a3f0b8107b5dc7eac9dfdb9e5238280c9fb.tar.bz2
send-email: move trivial config handling to Perl
Optimize the startup time of git-send-email by using an amended config_regexp() function to retrieve the list of config keys and values we're interested in. For boolean keys we can handle the [true|false] case ourselves, and the "--get" case didn't need any parsing. Let's leave "--path" and other "--bool" cases to "git config". I'm not bothering with the "undef" or "" case (true and false, respectively), let's just punt on those and others and have "git config --type=bool" handle it. The "grep { defined } @values" here covers a rather subtle case. For list values such as sendemail.to it is possible as with any other config key to provide a plain "-c sendemail.to", i.e. to set the key as a boolean true. In that case the Git::config() API will return an empty string, but this new parser will correctly return "undef". However, that means we can end up with "undef" in the middle of a list. E.g. for sendemail.smtpserveroption in conjuction with sendemail.smtpserver as a path this would have produce a warning. For most of the other keys we'd behave the same despite the subtle change in the value, e.g. sendemail.to would behave the same because Mail::Address->parse() happens to return an empty list if fed "undef". For the boolean values we were already prepared to handle these variables being initialized as undef anyway. This brings the runtime of "git send-email" from ~60-~70ms to a very steady ~40ms on my test box. We now run just one "git config" invocation on startup instead of 8, the exact number will differ based on the local sendemail.* config. I happen to have 8 of those set. This brings the runtime of t9001-send-email.sh from ~13s down to ~12s for me. The change there is less impressive as many of those tests set various config values, and we're also getting to the point of diminishing returns for optimizing "git send-email" itself. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-send-email.perl')
-rwxr-xr-xgit-send-email.perl29
1 files changed, 21 insertions, 8 deletions
diff --git a/git-send-email.perl b/git-send-email.perl
index a8949c9..5791138 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -334,7 +334,11 @@ sub read_config {
my $target = $config_bool_settings{$setting};
my $key = "$prefix.$setting";
next unless exists $known_keys->{$key};
- my $v = Git::config_bool(@repo, $key);
+ my $v = (@{$known_keys->{$key}} == 1 &&
+ (defined $known_keys->{$key}->[0] &&
+ $known_keys->{$key}->[0] =~ /^(?:true|false)$/s))
+ ? $known_keys->{$key}->[0] eq 'true'
+ : Git::config_bool(@repo, $key);
next unless defined $v;
next if $configured->{$setting}++;
$$target = $v;
@@ -363,13 +367,13 @@ sub read_config {
my $key = "$prefix.$setting";
next unless exists $known_keys->{$key};
if (ref($target) eq "ARRAY") {
- my @values = Git::config(@repo, $key);
- next unless @values;
+ my @values = @{$known_keys->{$key}};
+ @values = grep { defined } @values;
next if $configured->{$setting}++;
@$target = @values;
}
else {
- my $v = Git::config(@repo, $key);
+ my $v = $known_keys->{$key}->[0];
next unless defined $v;
next if $configured->{$setting}++;
$$target = $v;
@@ -381,12 +385,19 @@ sub config_regexp {
my ($regex) = @_;
my @ret;
eval {
- @ret = Git::command(
+ my $ret = Git::command(
'config',
- '--name-only',
+ '--null',
'--get-regexp',
$regex,
);
+ @ret = map {
+ # We must always return ($k, $v) here, since
+ # empty config values will be just "key\0",
+ # not "key\nvalue\0".
+ my ($k, $v) = split /\n/, $_, 2;
+ ($k, $v);
+ } split /\0/, $ret;
1;
} or do {
# If we have no keys we're OK, otherwise re-throw
@@ -399,8 +410,10 @@ sub config_regexp {
# parses 'bool' etc.) by only doing so for config keys that exist.
my %known_config_keys;
{
- my @known_config_keys = config_regexp("^sende?mail[.]");
- @known_config_keys{@known_config_keys} = ();
+ my @kv = config_regexp("^sende?mail[.]");
+ while (my ($k, $v) = splice @kv, 0, 2) {
+ push @{$known_config_keys{$k}} => $v;
+ }
}
# sendemail.identity yields to --identity. We must parse this