[PATCH 2 of 3 various] context: make sure __str__ works, also when there is no _changectx

Mads Kiilerich mads at kiilerich.com
Mon Apr 13 15:26:00 CDT 2015


# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1426800170 -3600
#      Thu Mar 19 22:22:50 2015 +0100
# Node ID 31a330fcad90837e0c0d858db69e67a7f74ec997
# Parent  dec70e4b55cad0d4f1ef1ed0468e2710cb4d49db
context: make sure __str__ works, also when there is no _changectx

Before, it could crash when trying to print the wrong kind of object at the
wrong time.

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -652,7 +652,10 @@ class basefilectx(object):
             return False
 
     def __str__(self):
-        return "%s@%s" % (self.path(), self._changectx)
+        try:
+            return "%s@%s" % (self.path(), self._changectx)
+        except error.LookupError:
+            return "%s@???" % self.path()
 
     def __repr__(self):
         return "<%s %s>" % (type(self).__name__, str(self))


More information about the Mercurial-devel mailing list