changeset 19538:049d6b5a4a59

basectx: return a copied context if changeid is already a basectx This implements a copy constructor so that we can pass a basectx-derived object in future refactorings.
author Sean Farley <sean.michael.farley@gmail.com>
date Tue, 06 Aug 2013 15:50:28 -0500
parents 6e3e8575276d
children 79671c46bb46
files mercurial/context.py
diffstat 1 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/context.py	Sat Jul 13 19:59:21 2013 -0500
+++ b/mercurial/context.py	Tue Aug 06 15:50:28 2013 -0500
@@ -24,7 +24,16 @@
     memctx: a context that represents changes in-memory and can also
             be committed."""
     def __new__(cls, repo, changeid='', *args, **kwargs):
-        return super(basectx, cls).__new__(cls)
+        if isinstance(changeid, basectx):
+            return changeid
+
+        o = super(basectx, cls).__new__(cls)
+
+        o._repo = repo
+        o._rev = nullrev
+        o._node = nullid
+
+        return o
 
 class changectx(basectx):
     """A changecontext object makes access to data related to a particular