summaryrefslogtreecommitdiff
path: root/git-send-email.perl
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2009-07-23 07:09:29 -0400
committerJunio C Hamano <gitster@pobox.com>2009-07-24 09:32:46 -0700
commit302e04ea4d0c0414cedd716de882fa3dbe3480eb (patch)
tree8f1c26b30262666bba33b6e57ae3f2a1a90cb3c5 /git-send-email.perl
parent735c674416b87505400fcf738fd3a38b52f0eccb (diff)
downloadgit-302e04ea4d0c0414cedd716de882fa3dbe3480eb.tar.gz
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>
Diffstat (limited to 'git-send-email.perl')
-rwxr-xr-xgit-send-email.perl18
1 files changed, 11 insertions, 7 deletions
diff --git a/git-send-email.perl b/git-send-email.perl
index cccbf4517a..f299c2dba2 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);