Patchwork [36,of,36] changectx: if passing a context then exit __init__ immediately

login
register
mail settings
Submitter Sean Farley
Date Aug. 7, 2013, 6:13 p.m.
Message ID <7316661a4968456c3868.1375899216@laptop.local>
Download mbox | patch
Permalink /patch/2053/
State Superseded
Commit 62378ae107df07ae25570038b9949f00d1ee50c5
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 1375825361 18000
#      Tue Aug 06 16:42:41 2013 -0500
# Node ID 7316661a4968456c3868c178cab6e32004094504
# Parent  3f12610b25b6e786c81d84734ca8433ad47ab7a3
changectx: if passing a context then exit __init__ immediately
Augie Fackler - Aug. 7, 2013, 6:32 p.m.
On Wed, Aug 07, 2013 at 01:13:36PM -0500, Sean Farley wrote:
> # HG changeset patch
> # User Sean Farley <sean.michael.farley@gmail.com>
> # Date 1375825361 18000
> #      Tue Aug 06 16:42:41 2013 -0500
> # Node ID 7316661a4968456c3868c178cab6e32004094504
> # Parent  3f12610b25b6e786c81d84734ca8433ad47ab7a3
> changectx: if passing a context then exit __init__ immediately

hm, so we'd leave an uninitialized object? I feel like this should
throw some kind of exception (TypeError? ArgumentError?) instead.

>
> diff --git a/mercurial/context.py b/mercurial/context.py
> --- a/mercurial/context.py
> +++ b/mercurial/context.py
> @@ -152,10 +152,16 @@
>      """A changecontext object makes access to data related to a particular
>      changeset convenient. It represents a read-only context already presnt in
>      the repo."""
>      def __init__(self, repo, changeid=''):
>          """changeid is a revision number, node, or tag"""
> +
> +        # allow changeid to be a context so that we can simplify creating a
> +        # copy
> +        if isinstance(changeid, context):
> +            return
> +
>          if changeid == '':
>              changeid = '.'
>          self._repo = repo
>
>          if isinstance(changeid, int):
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
Sean Farley - Aug. 7, 2013, 7:18 p.m.
raf@durin42.com writes:

> On Wed, Aug 07, 2013 at 01:13:36PM -0500, Sean Farley wrote:
>> # HG changeset patch
>> # User Sean Farley <sean.michael.farley@gmail.com>
>> # Date 1375825361 18000
>> #      Tue Aug 06 16:42:41 2013 -0500
>> # Node ID 7316661a4968456c3868c178cab6e32004094504
>> # Parent  3f12610b25b6e786c81d84734ca8433ad47ab7a3
>> changectx: if passing a context then exit __init__ immediately
>
> hm, so we'd leave an uninitialized object? I feel like this should
> throw some kind of exception (TypeError? ArgumentError?) instead.

I guess this means I need to augment this commit message. We want to
exit immediately because context.__new__ takes care of copying the
object already and we don't want to clobber it with another
initialization.
Augie Fackler - Aug. 7, 2013, 7:40 p.m.
On Wed, Aug 7, 2013 at 3:18 PM, Sean Farley
<sean.michael.farley@gmail.com> wrote:
> I guess this means I need to augment this commit message. We want to
> exit immediately because context.__new__ takes care of copying the
> object already and we don't want to clobber it with another
> initialization.


A comment in the __init__ would be better.

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -152,10 +152,16 @@ 
     """A changecontext object makes access to data related to a particular
     changeset convenient. It represents a read-only context already presnt in
     the repo."""
     def __init__(self, repo, changeid=''):
         """changeid is a revision number, node, or tag"""
+
+        # allow changeid to be a context so that we can simplify creating a
+        # copy
+        if isinstance(changeid, context):
+            return
+
         if changeid == '':
             changeid = '.'
         self._repo = repo
 
         if isinstance(changeid, int):