send-email: detect cycles in alias expansion

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>
This commit is contained in:
Jeff King 2009-07-23 07:09:29 -04:00 коммит произвёл Junio C Hamano
Родитель 735c674416
Коммит 302e04ea4d
1 изменённых файлов: 11 добавлений и 7 удалений

Просмотреть файл

@ -655,13 +655,17 @@ if (!@to) {
}
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);