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

login
register
mail settings
Submitter Sean Farley
Date Aug. 7, 2013, 6:13 p.m.
Message ID <8e7a1ca270327a1e3e42.1375899182@laptop.local>
Download mbox | patch
Permalink /patch/2019/
State Superseded
Commit 308be0e24eee04e4147ec2ac9b5abf5d9b1a5a2b
Delegated to: Augie Fackler
Headers show

Comments

Sean Farley - Aug. 7, 2013, 6:13 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 8e7a1ca270327a1e3e42e421d7bb897b84d752b7
# Parent  006e3b2905974dff47890fb2a9f1e1e88bf83228
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."""