Patchwork [02,of,35,V2] context: return a copied context if changeid is already a context

login
register
mail settings
Submitter Sean Farley
Date Aug. 7, 2013, 11:51 p.m.
Message ID <21cc2a97203367398850.1375919476@laptop.local>
Download mbox | patch
Permalink /patch/2055/
State Accepted
Headers show

Comments

Sean Farley - Aug. 7, 2013, 11:51 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1375822228 18000
#      Tue Aug 06 15:50:28 2013 -0500
# Node ID 21cc2a972033673988500bb126c24e77f2ed37e1
# Parent  339f5b17a04f405040de893becb51b7270b8613d
context: return a copied context if changeid is already a context

This implements a copy constructor so that we can pass a context-derived object
in future refactorings.

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -22,11 +22,20 @@ 
     workingctx: a context that represents the working directory and can
                 be committed,
     memctx: a context that represents changes in-memory and can also
             be committed."""
     def __new__(cls, repo, changeid='', *args, **kwargs):
-        return super(context, cls).__new__(cls)
+        if isinstance(changeid, context):
+            return changeid
+
+        o = super(context, cls).__new__(cls)
+
+        o._repo = repo
+        o._rev = nullrev
+        o._node = nullid
+
+        return o
 
 class changectx(context):
     """A changecontext object makes access to data related to a particular
     changeset convenient. It represents a read-only context already presnt in
     the repo."""