Skip to content

Commit 1ff5a41

Browse files
committed
Merge branch 'cs/perl-config-path-send-email'
* cs/perl-config-path-send-email: use new Git::config_path() for aliasesfile Add Git::config_path()
2 parents afc71aa + cec5dae commit 1ff5a41

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

git-send-email.perl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ sub do_edit {
225225
"cccmd" => \$cc_cmd,
226226
"aliasfiletype" => \$aliasfiletype,
227227
"bcc" => \@bcclist,
228-
"aliasesfile" => \@alias_files,
229228
"suppresscc" => \@suppress_cc,
230229
"envelopesender" => \$envelope_sender,
231230
"multiedit" => \$multiedit,
@@ -234,6 +233,10 @@ sub do_edit {
234233
"assume8bitencoding" => \$auto_8bit_encoding,
235234
);
236235

236+
my %config_path_settings = (
237+
"aliasesfile" => \@alias_files,
238+
);
239+
237240
# Help users prepare for 1.7.0
238241
sub chain_reply_to {
239242
if (defined $chain_reply_to &&
@@ -333,6 +336,11 @@ sub read_config {
333336
$$target = Git::config_bool(@repo, "$prefix.$setting") unless (defined $$target);
334337
}
335338

339+
foreach my $setting (keys %config_path_settings) {
340+
my $target = $config_path_settings{$setting}->[0];
341+
$$target = Git::config_path(@repo, "$prefix.$setting") unless (defined $$target);
342+
}
343+
336344
foreach my $setting (keys %config_settings) {
337345
my $target = $config_settings{$setting};
338346
next if $setting eq "to" and defined $no_to;

perl/Git.pm

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,38 @@ sub config_bool {
627627
};
628628
}
629629

630+
631+
=item config_path ( VARIABLE )
632+
633+
Retrieve the path configuration C<VARIABLE>. The return value
634+
is an expanded path or C<undef> if it's not defined.
635+
636+
This currently wraps command('config') so it is not so fast.
637+
638+
=cut
639+
640+
sub config_path {
641+
my ($self, $var) = _maybe_self(@_);
642+
643+
try {
644+
my @cmd = ('config', '--path');
645+
unshift @cmd, $self if $self;
646+
if (wantarray) {
647+
return command(@cmd, '--get-all', $var);
648+
} else {
649+
return command_oneline(@cmd, '--get', $var);
650+
}
651+
} catch Git::Error::Command with {
652+
my $E = shift;
653+
if ($E->value() == 1) {
654+
# Key not found.
655+
return undef;
656+
} else {
657+
throw $E;
658+
}
659+
};
660+
}
661+
630662
=item config_int ( VARIABLE )
631663
632664
Retrieve the integer configuration C<VARIABLE>. The return value

0 commit comments

Comments
 (0)