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

login
register
mail settings
Submitter Matt Harbison
Date June 29, 2015, 5:13 p.m.
Message ID <46033c2b55b71c40b323.1435598036@MATT7H-PC.attotech.com>
Download mbox | patch
Permalink /patch/9816/
State Accepted
Headers show

Comments

Matt Harbison - June 29, 2015, 5:13 p.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1435531198 14400
#      Sun Jun 28 18:39:58 2015 -0400
# Node ID 46033c2b55b71c40b32315f16f5524b0295e64dc
# Parent  6fb8a76fa2afa847734c15ef7b2e22a94505c591
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.
Matt Mackall - June 29, 2015, 10:52 p.m.
On Mon, 2015-06-29 at 13:13 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1435531198 14400
> #      Sun Jun 28 18:39:58 2015 -0400
> # Node ID 46033c2b55b71c40b32315f16f5524b0295e64dc
> # Parent  6fb8a76fa2afa847734c15ef7b2e22a94505c591
> identify: avoid a crash when given '-r wdir()'

Queued for default, thanks.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4064,7 +4064,9 @@  def identify(ui, repo, source=None, rev=
             if bm:
                 output.append(bm)
     else:
-        if not rev:
+        ctx = scmutil.revsingle(repo, rev, None)
+
+        if ctx.rev() is None:
             ctx = repo[None]
             parents = ctx.parents()
             changed = ""
@@ -4079,7 +4081,6 @@  def identify(ui, repo, source=None, rev=
                 output.append("%s%s" %
                   ('+'.join([str(p.rev()) for p in parents]), changed))
         else:
-            ctx = scmutil.revsingle(repo, rev)
             if default or id:
                 output = [hexfunc(ctx.node())]
             if num:
diff --git a/tests/test-tags.t b/tests/test-tags.t
--- a/tests/test-tags.t
+++ b/tests/test-tags.t
@@ -47,6 +47,8 @@  Setup:
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg identify
   acb14030fe0a tip
+  $ hg identify -r 'wdir()'
+  acb14030fe0a tip
   $ cacheexists
   tag cache exists
 No fnodes cache because .hgtags file doesn't exist
@@ -174,6 +176,8 @@  Create a branch:
   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
   $ hg id
   acb14030fe0a+ first
+  $ hg id -r 'wdir()'
+  acb14030fe0a+ first
   $ hg -v id
   acb14030fe0a+ first
   $ hg status