Re: infinite loop in git-send-email with alias files
- From
Jeff King <peff@peff.net>
- Date
- Jul 23, 2009, 13:54 UTC
- Message-ID
- <20090723135408.GA22317@coredump.intra.peff.net>
- In-Reply-To
- <4A6857FF.5070401@viscovery.net>
On Thu, Jul 23, 2009 at 02:30:55PM +0200, Johannes Sixt wrote:
Show 15 quoted lines
> Jeff King schrieb:
> > +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;
>
> What does 'local' make local here? Only the assignment of the slot
> $EXPANDED_ALIASES{$alias}? Or the whole %EXPANDED_ALIASES? If the latter,
> does this copy the existing %EXPANDED_ALIASES before the assignment is
> made; otherwise, how can this work if only ever a single slot of
> %EXPANDED_ALIASES is filled in?It localizes just that slot. But remember that 'local' is about _dynamic_ scoping, not _lexical_ scoping. So that slot is now set for the duration of the expand_one_alias call, and is visible to its subroutines (i.e., the recursive calls). So each level of recursion sets one more field in $EXPANDED_ALIASES, and when we leave the function, perl automatically restores it to its previous value.
-Peff