From: Jeff King Date: Thu, 23 Jul 2009 11:09:29 +0000 (-0400) Subject: send-email: detect cycles in alias expansion X-Git-Tag: v1.6.4-rc3~9^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=302e04ea4d0c0414cedd716de882fa3dbe3480eb;p=git.git 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 Signed-off-by: Junio C Hamano --- diff --git a/git-send-email.perl b/git-send-email.perl index cccbf4517..f299c2dba 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -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);