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

login
register
mail settings
Submitter Mads Kiilerich
Date Nov. 2, 2016, 3:25 p.m.
Message ID <4b06a40809d781e9aba5.1478100327@madski>
Download mbox | patch
Permalink /patch/17285/
State Accepted
Headers show

Comments

Mads Kiilerich - Nov. 2, 2016, 3:25 p.m.
# HG changeset patch
# User Mads Kiilerich <mads@kiilerich.com>
# Date 1426800170 -3600
#      Thu Mar 19 22:22:50 2015 +0100
# Node ID 4b06a40809d781e9aba54718ec2fe1a232d81956
# Parent  90300200bc1fcaedcc6ab109574d08b01ece2853
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.
Pierre-Yves David - Nov. 3, 2016, 3:53 p.m.
On 11/02/2016 04:25 PM, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <mads@kiilerich.com>
> # Date 1426800170 -3600
> #      Thu Mar 19 22:22:50 2015 +0100
> # Node ID 4b06a40809d781e9aba54718ec2fe1a232d81956
> # Parent  90300200bc1fcaedcc6ab109574d08b01ece2853
> context: make sure __str__ works, also when there is no _changectx

These two are pushed, thanks.

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -709,7 +709,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))