[PATCH 2 of 3] context: override workingctx.hex() to avoid a crash

Matt Harbison mharbison72 at gmail.com
Sun Jun 14 23:28:58 CDT 2015


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1434333857 14400
#      Sun Jun 14 22:04:17 2015 -0400
# Node ID f5f5e4ae488d9cae8111e9a212f647ed1430a019
# Parent  9c738d2588313bb624465495a8923b293c45b999
context: override workingctx.hex() to avoid a crash

Since node is None for workingctx, it can't use the base class implementation of
'hex(self.node())'.

It doesn't appear that there are any current callers of this, but there will be
when archive supports 'wdir()'.  Since 'hg id' prints "p1.node() + '+'" for a
dirty working copy, this does too.  That of course means that it isn't possible
to call 'bin(ctx.hex())', but that seems circuitous.  Having the '+' seems like
a useful distinction when building the .hg_archival.txt file.

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -1334,6 +1334,12 @@
     def __contains__(self, key):
         return self._repo.dirstate[key] not in "?r"
 
+    def hex(self):
+        hex = self.p1().hex()
+        if self.dirty():
+            hex += '+'
+        return hex
+
     @propertycache
     def _parents(self):
         p = self._repo.dirstate.parents()


More information about the Mercurial-devel mailing list