Skip to content

Commit

Permalink
send-email: Don't require to be called in a repository
Browse files Browse the repository at this point in the history
We might not have some configuration variables available, but if the
user doesn't care about that, neither should we. Still use the
repository if it is available, though.

Signed-off-by: Frank Lichtenheld <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
flichtenheld authored and gitster committed Mar 15, 2008
1 parent 4461792 commit ad79c02
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions git-send-email.perl
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ sub format_2822_time {
# Example reply to:
#$initial_reply_to = ''; #<[email protected]>';

my $repo = Git->repository();
my $repo = eval { Git->repository() };
my @repo = $repo ? ($repo) : ();
my $term = eval {
$ENV{"GIT_SEND_EMAIL_NOTTY"}
? new Term::ReadLine 'git-send-email', \*STDIN, \*STDOUT
Expand Down Expand Up @@ -271,25 +272,25 @@ sub read_config {

foreach my $setting (keys %config_bool_settings) {
my $target = $config_bool_settings{$setting}->[0];
$$target = $repo->config_bool("$prefix.$setting") unless (defined $$target);
$$target = Git::config_bool(@repo, "$prefix.$setting") unless (defined $$target);
}

foreach my $setting (keys %config_settings) {
my $target = $config_settings{$setting};
if (ref($target) eq "ARRAY") {
unless (@$target) {
my @values = $repo->config("$prefix.$setting");
my @values = Git::config(@repo, "$prefix.$setting");
@$target = @values if (@values && defined $values[0]);
}
}
else {
$$target = $repo->config("$prefix.$setting") unless (defined $$target);
$$target = Git::config(@repo, "$prefix.$setting") unless (defined $$target);
}
}
}

# read configuration from [sendemail "$identity"], fall back on [sendemail]
$identity = $repo->config("sendemail.identity") unless (defined $identity);
$identity = Git::config(@repo, "sendemail.identity") unless (defined $identity);
read_config("sendemail.$identity") if (defined $identity);
read_config("sendemail");

Expand Down Expand Up @@ -327,8 +328,9 @@ sub read_config {
}
}

my ($repoauthor) = $repo->ident_person('author');
my ($repocommitter) = $repo->ident_person('committer');
my ($repoauthor, $repocommitter);
($repoauthor) = Git::ident_person(@repo, 'author');
($repocommitter) = Git::ident_person(@repo, 'committer');

# Verify the user input

Expand Down Expand Up @@ -415,7 +417,7 @@ sub read_config {

my $prompting = 0;
if (!defined $sender) {
$sender = $repoauthor || $repocommitter;
$sender = $repoauthor || $repocommitter || '';

while (1) {
$_ = $term->readline("Who should the emails appear to be from? [$sender] ");
Expand Down Expand Up @@ -509,7 +511,7 @@ sub expand_aliases {
EOT
close(C);

my $editor = $ENV{GIT_EDITOR} || $repo->config("core.editor") || $ENV{VISUAL} || $ENV{EDITOR} || "vi";
my $editor = $ENV{GIT_EDITOR} || Git::config(@repo, "core.editor") || $ENV{VISUAL} || $ENV{EDITOR} || "vi";
system('sh', '-c', '$0 $@', $editor, $compose_filename);

open(C2,">",$compose_filename . ".final")
Expand Down

0 comments on commit ad79c02

Please sign in to comment.