[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:03:41 CDT 2013


On 09/26/2013 11:48 PM, Martin Geisler wrote:
> pierre-yves.david at ens-lyon.org writes:
>
>> # HG changeset patch
>> # User Pierre-Yves David<pierre-yves.david at ens-lyon.org>
>> # Date 1380144102 -7200
>> #      Wed Sep 25 23:21:42 2013 +0200
>> # Node ID f2d6590c1873f5d9fbd903a2ea467a19de4d4c13
>> # Parent  72982741c525e1d0b06096bc7eafc780a4f2274f
>> mq: extract strip as a standalone extension (issue3824)
> This is a great idea! Thanks for making my life easier when I explain
> new users how to remove changesets.
>
>> Strip now lives in its own extension. The extension is surprisingly called `strip`.
>> The `mq` extension force the use of the strip extension when its enabled. This
>> is both necessary for backward compatibility (people expect `mq` to comes with strip) and
>> become some utility function used by `mq` are now in the strip extension.
> The commit message above is wrapped inconsistently -- maybe by hand?
>
>> diff --git a/hgext/mq.py b/hgext/mq.py
>> --- a/hgext/mq.py
>> +++ b/hgext/mq.py
>> @@ -55,17 +55,20 @@ discarded. Setting::
>>     keepchanges = True
>>
>>   make them behave as if --keep-changes were passed, and non-conflicting
>>   local changes will be tolerated and preserved. If incompatible options
>>   such as -f/--force or --exact are passed, this setting is ignored.
>> +
>> +This extension used to provide a strip commands. This command now lives
> Should be "a strip command", without the "s".
>
> [...]
>
>> +# 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.

>   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.


-- 
Pierre-Yves


More information about the Mercurial-devel mailing list