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

Matt Harbison mharbison72 at gmail.com
Sun Jun 28 20:40:09 CDT 2015


# 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]
             parents = ctx.parents()
@@ -4083,7 +4089,6 @@
                 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 @@
   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 @@
   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


More information about the Mercurial-devel mailing list