Merge branch 'cs/perl-config-path-send-email'
authorJunio C Hamano <gitster@pobox.com>
Wed, 12 Oct 2011 19:34:05 +0000 (12:34 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 12 Oct 2011 19:34:05 +0000 (12:34 -0700)
* cs/perl-config-path-send-email:
use new Git::config_path() for aliasesfile
Add Git::config_path()

git-send-email.perl
perl/Git.pm
index 8ded7f5ce3556acf69a2d88e8b9aedae1d5e2da6..91607c5878953d69a8e32731023b2eb727bcc069 100755 (executable)
@@ -225,7 +225,6 @@ sub do_edit {
     "cccmd" => \$cc_cmd,
     "aliasfiletype" => \$aliasfiletype,
     "bcc" => \@bcclist,
-    "aliasesfile" => \@alias_files,
     "suppresscc" => \@suppress_cc,
     "envelopesender" => \$envelope_sender,
     "multiedit" => \$multiedit,
@@ -234,6 +233,10 @@ sub do_edit {
     "assume8bitencoding" => \$auto_8bit_encoding,
 );
 
+my %config_path_settings = (
+    "aliasesfile" => \@alias_files,
+);
+
 # Help users prepare for 1.7.0
 sub chain_reply_to {
        if (defined $chain_reply_to &&
@@ -333,6 +336,11 @@ sub read_config {
                $$target = Git::config_bool(@repo, "$prefix.$setting") unless (defined $$target);
        }
 
+       foreach my $setting (keys %config_path_settings) {
+               my $target = $config_path_settings{$setting}->[0];
+               $$target = Git::config_path(@repo, "$prefix.$setting") unless (defined $$target);
+       }
+
        foreach my $setting (keys %config_settings) {
                my $target = $config_settings{$setting};
                next if $setting eq "to" and defined $no_to;
index a86ab709c25b5e110aa2708941cea560f82c1fa8..c279bfb2446880bb18a5e6c898ef533805e78e56 100644 (file)
@@ -627,6 +627,38 @@ sub config_bool {
        };
 }
 
+
+=item config_path ( VARIABLE )
+
+Retrieve the path configuration C<VARIABLE>. The return value
+is an expanded path or C<undef> if it's not defined.
+
+This currently wraps command('config') so it is not so fast.
+
+=cut
+
+sub config_path {
+       my ($self, $var) = _maybe_self(@_);
+
+       try {
+               my @cmd = ('config', '--path');
+               unshift @cmd, $self if $self;
+               if (wantarray) {
+                       return command(@cmd, '--get-all', $var);
+               } else {
+                       return command_oneline(@cmd, '--get', $var);
+               }
+       } catch Git::Error::Command with {
+               my $E = shift;
+               if ($E->value() == 1) {
+                       # Key not found.
+                       return undef;
+               } else {
+                       throw $E;
+               }
+       };
+}
+
 =item config_int ( VARIABLE )
 
 Retrieve the integer configuration C<VARIABLE>. The return value