Skip to content

Commit

Permalink
send-email: detect cycles in alias expansion
Browse files Browse the repository at this point in the history
With the previous code, an alias cycle like:

  $ echo 'alias a b' >aliases
  $ echo 'alias b a' >aliases
  $ git config sendemail.aliasesfile aliases
  $ git config sendemail.aliasfiletype mutt

would put send-email into an infinite loop. This patch
detects the situation and complains to the user.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jul 24, 2009
1 parent 735c674 commit 302e04e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions git-send-email.perl
Original file line number Diff line number Diff line change
Expand Up @@ -655,13 +655,17 @@ sub ask {
}

sub expand_aliases {
my @cur = @_;
my @last;
do {
@last = @cur;
@cur = map { $aliases{$_} ? @{$aliases{$_}} : $_ } @last;
} while (join(',',@cur) ne join(',',@last));
return @cur;
return map { expand_one_alias($_) } @_;
}

my %EXPANDED_ALIASES;
sub expand_one_alias {
my $alias = shift;
if ($EXPANDED_ALIASES{$alias}) {
die "fatal: alias '$alias' expands to itself\n";
}
local $EXPANDED_ALIASES{$alias} = 1;
return $aliases{$alias} ? expand_aliases(@{$aliases{$alias}}) : $alias;
}

@to = expand_aliases(@to);
Expand Down

0 comments on commit 302e04e

Please sign in to comment.