[PATCH 1 of 2 standalone-strip] mq: extract strip as a standalone extension (issue3824)

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu Sep 26 17:56:55 CDT 2013


On 09/27/2013 12:50 AM, Martin Geisler wrote:
> Pierre-Yves David<pierre-yves.david at ens-lyon.org>  writes:
>
>> On 09/26/2013 11:48 PM, Martin Geisler wrote:
>>> pierre-yves.david at ens-lyon.org writes:
>>>
>>>> +# force load strip extension formely included in mq and import some utility
>>>> +try:
>>>> +    stripext = extensions.find('strip')
>>>> +except KeyError:
>>>> +    # note: load is lazy so we could avoid the try-except.
>>>> +    # but I (marmoute) prefers this explicite code.
>>>> +    class dummyui(object):
>>>> +        def debug(self, msg):
>>>> +            pass
>>>> +    stripext = extensions.load(dummyui(), 'strip', '')
>>>> +
>>>> +strip = stripext.strip
>>>> +checksubstate = stripext.checksubstate
>>>> +checklocalchanges = stripext.checklocalchanges
>>> I guess you don't simply do 'from hgext import strip as stripext'
>> I prefer to use the Mercurial code dedicated to load extension when I
>> have to load extension. In particular because I actually NEED to have
>> to properly loaded by mercurial so the strip command is registred and
>> extension callback are called.
> Good point. As far as I can see, though, uisetup and extsetup wont be
> called when you use extensions.load -- it is extensions.loadall that
> calls those functions.

No, extensions load insert it in the _order list so that loadall call 
those function.

loadall is run
    load(mq)
      load(strip)
    Extension hook run for everything.


> If that is true, then perhaps you can use extensions.loadall still: it
> loads the extensions based on the configuration, so you could set
> ui.config('extensions', 'strip') and then call loadall. It should only
> load and initialize the new extensions, i.e., strip.

No, I will not run loadall in the middle of loadall. I'm certain the 
code breaks if I do that.

>
>>>    since you want to avoid loading the extension twice in case the
>>> user already enabled 'strip'?
>> Mercurial already have its own way to prevent that (because extension
>> can be enable in multiple hgrc file and you do not want them to be
>> loaded multiple time in that case) So there is no issue in that
>> direction.
> I think you misunderstood me. I was talking about the hgext.strip module
> being loaded twice: once when you do
>
>    from hgext import strip
>
> and once when you run
>
>    extensions.load(ui, 'strip', None)

The nice part is that you do not run `from hgext import strip` the same 
as you do not run `from hgext import random-extension` because that's 
not the way they meant to be used.

> I had the impression that extensions.load would mangle the module name
> so that the module would end up twice in sys.modules. That was wrong,
> the module name is only changed if you supply a path. So calling
>
>    extensions.load(ui, 'strip', None)
>
> should give the same result as importing it the normal way, except that
> extensions.load will also store a reference in it's _extensions dict.

We are discussing the generic implementation of extensions here. There 
is nothing wrong down there and that's far out of scope.

-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list