Patchwork [6,of,9,V2] subrepo: store the ui object in the base class

login
register
mail settings
Submitter Matt Harbison
Date Nov. 30, 2014, 5:52 a.m.
Message ID <63861162c13d1764fceb.1417326754@Envy>
Download mbox | patch
Permalink /patch/6901/
State Superseded
Commit fcbc66b5da6ad820ca980737025bfeb35a479fc8
Headers show

Comments

Matt Harbison - Nov. 30, 2014, 5:52 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1417036418 18000
#      Wed Nov 26 16:13:38 2014 -0500
# Node ID 63861162c13d1764fcebb3f30e4f173378d83e4b
# Parent  31e3071ecdb39568755995b21e4961a7e77cee49
subrepo: store the ui object in the base class

This will be used in the next patch to print a warning from the base class.  It
seems better than having to explicitly pass it to a new method, since a lot of
existing methods also require it.
Martin von Zweigbergk - Dec. 2, 2014, 11:31 p.m.
On Sat Nov 29 2014 at 9:53:42 PM Matt Harbison <matt_harbison@yahoo.com>
wrote:

> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1417036418 18000
> #      Wed Nov 26 16:13:38 2014 -0500
> # Node ID 63861162c13d1764fcebb3f30e4f173378d83e4b
> # Parent  31e3071ecdb39568755995b21e4961a7e77cee49
> subrepo: store the ui object in the base class
>
> This will be used in the next patch to print a warning from the base
> class.  It
> seems better than having to explicitly pass it to a new method, since a
> lot of
> existing methods also require it.
>
> diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
> --- a/mercurial/subrepo.py
> +++ b/mercurial/subrepo.py
> @@ -372,6 +372,9 @@
>
>  class abstractsubrepo(object):
>
> +    def __init__(self, ui):
> +        self._ui = ui
> +
>      def storeclean(self, path):
>          """
>          returns true if the repository has not changed since it was last
> @@ -508,6 +511,7 @@
>
>  class hgsubrepo(abstractsubrepo):
>      def __init__(self, ctx, path, state):
> +        abstractsubrepo.__init__(self, ctx._repo.ui)
>

It seems like "super(hgsubrepo, self).__init__(self, ctx._repo.ui)" is
better since it doesn't repeat the superclass, but I'm new to Python, so I
may easily be wrong.
Matt Harbison - Dec. 3, 2014, 3:20 a.m.
Martin von Zweigbergk wrote:
>
>
> On Sat Nov 29 2014 at 9:53:42 PM Matt Harbison <matt_harbison@yahoo.com
> <mailto:matt_harbison@yahoo.com>> wrote:
>
>     # HG changeset patch
>     # User Matt Harbison <matt_harbison@yahoo.com>
>     # Date 1417036418 18000
>     #      Wed Nov 26 16:13:38 2014 -0500
>     # Node ID 63861162c13d1764fcebb3f30e4f17__3378d83e4b
>     # Parent  31e3071ecdb39568755995b21e4961__a7e77cee49
>     subrepo: store the ui object in the base class
>
>     This will be used in the next patch to print a warning from the base
>     class.  It
>     seems better than having to explicitly pass it to a new method,
>     since a lot of
>     existing methods also require it.
>
>     diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
>     --- a/mercurial/subrepo.py
>     +++ b/mercurial/subrepo.py
>     @@ -372,6 +372,9 @@
>
>       class abstractsubrepo(object):
>
>     +    def __init__(self, ui):
>     +        self._ui = ui
>     +
>           def storeclean(self, path):
>     """
>               returns true if the repository has not changed since it
>     was last
>     @@ -508,6 +511,7 @@
>
>       class hgsubrepo(abstractsubrepo):
>           def __init__(self, ctx, path, state):
>     +        abstractsubrepo.__init__(self, ctx._repo.ui)
>
>
> It seems like "super(hgsubrepo, self).__init__(self, ctx._repo.ui)" is
> better since it doesn't repeat the superclass, but I'm new to Python, so
> I may easily be wrong.

I don't know much python myself, so I'm not sure if there's any 
difference.  I see examples of it both ways in the code.  But now that 
you mention it, I think I vaguely remember reading somewhere on the wiki 
that your form is preferred, so I'll change it.

It's getting late, so I'll probably tackle this series tomorrow night if 
you want to try to slip in some of the tweaks you mentioned earlier.

--Matt

Patch

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -372,6 +372,9 @@ 
 
 class abstractsubrepo(object):
 
+    def __init__(self, ui):
+        self._ui = ui
+
     def storeclean(self, path):
         """
         returns true if the repository has not changed since it was last
@@ -508,6 +511,7 @@ 
 
 class hgsubrepo(abstractsubrepo):
     def __init__(self, ctx, path, state):
+        abstractsubrepo.__init__(self, ctx._repo.ui)
         self._path = path
         self._state = state
         r = ctx._repo
@@ -878,6 +882,7 @@ 
 
 class svnsubrepo(abstractsubrepo):
     def __init__(self, ctx, path, state):
+        abstractsubrepo.__init__(self, ctx._repo.ui)
         self._path = path
         self._state = state
         self._ctx = ctx
@@ -1108,6 +1113,7 @@ 
 
 class gitsubrepo(abstractsubrepo):
     def __init__(self, ctx, path, state):
+        abstractsubrepo.__init__(self, ctx._repo.ui)
         self._state = state
         self._ctx = ctx
         self._path = path