[PATCH] identify: avoid a crash when given '-r wdir()'

Matt Harbison mharbison72 at gmail.com
Mon Jun 29 11:40:24 CDT 2015


On Mon, 29 Jun 2015 09:39:58 -0400, Yuya Nishihara <yuya at tcha.org> wrote:

> On Sun, 28 Jun 2015 21:40:09 -0400, Matt Harbison wrote:
>> # HG changeset patch
>> # User Matt Harbison <matt_harbison at yahoo.com>
>> # Date 1435531198 14400
>> #      Sun Jun 28 18:39:58 2015 -0400
>> # Node ID 6f1a661262ebb3281f707642447887deaafafc38
>> # Parent  601770f5da477240954670d51f5ea11caa40dc20
>> identify: avoid a crash when given '-r wdir()'
>>
>> The crash was 'NoneType is not subscriptable' in hexfunc(ctx.node()),  
>> because
>> the node for wdir() is None.  This can be avoided simply by detecting  
>> 'wdir()'
>> and taking the existing path for no given revision.
>>
>> diff --git a/mercurial/commands.py b/mercurial/commands.py
>> --- a/mercurial/commands.py
>> +++ b/mercurial/commands.py
>> @@ -4064,6 +4064,12 @@
>>              if bm:
>>                  output.append(bm)
>>      else:
>> +        if rev:
>> +            # If wdir() is given, translate back to None
>> +            ctx = scmutil.revsingle(repo, rev)
>> +            if ctx.rev() is None:
>> +                rev = None
>> +
>>          if not rev:
>>              ctx = repo[None]
>
> Perhaps we can simply do
>
>   ctx = scmutil.revsingle(repo, rev, None)
>   if ctx.rev() is None:
>       ...
>   else:
>       ...

Definitely cleaner this way, and avoids the trap I fell into where rev=0  
took the wdir path when I was unconditionally overwriting rev with  
ctx.rev().  I'll send a V2.


More information about the Mercurial-devel mailing list