[PATCH 2 of 5 V2] debugdirstate: add option to drop or add files to dirstate
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Wed Nov 18 10:34:41 UTC 2015
On 11/18/2015 02:24 AM, Pierre-Yves David wrote:
>
>
> On 11/17/2015 05:18 PM, Laurent Charignon wrote:
>>
>>> On Nov 17, 2015, at 2:54 PM, cdelahousse at fb.com wrote:
>>>
>>> # HG changeset patch
>>> # User Christian Delahousse <cdelahousse at fb.com>
>>> # Date 1447728959 28800
>>> # Mon Nov 16 18:55:59 2015 -0800
>>> # Node ID 7e9f321545b481302597ecdc90e34b62b0b8e54c
>>> # Parent 6d207a588cef3e66d71dce337b0d2b14d921c600
>>> debugdirstate: add option to drop or add files to dirstate
>>>
>>> Debugging the dirstate helps if you have options to add files for
>>> normal lookup
>>> or drop them form the dirstate. This patch adds flags to the
>>> debugdirstate
>>> command to do just that.
>>>
>>> diff --git a/mercurial/commands.py b/mercurial/commands.py
>>> --- a/mercurial/commands.py
>>> +++ b/mercurial/commands.py
>>> @@ -3158,12 +3158,37 @@
>>> finally:
>>> wlock.release()
>>>
>>> +def _moddirstate(repo, *pats, **opts):
>>> + '''Manually add or drop a file to the dirstate'''
>>
>> Why 'manually' here?
>> Do you mean that this is called when calling debugdirstate to manually
>> add or drop of file from the dirstate?
>>
>>> + wlock = repo.wlock()
>>> + try:
>>> + for file in pats:
>>> + if opts.get('normal_lookup'):
>>> + repo.dirstate.normallookup(file)
>>> + else:
>>> + repo.dirstate.drop(file)
>>> + repo.dirstate.write()
>>> + finally:
>>> + wlock.release()
>>> +
>>> @command('debugdirstate|debugstate',
>>> [('', 'nodates', None, _('do not display the saved mtime')),
>>> - ('', 'datesort', None, _('sort by saved mtime'))],
>>> + ('', 'datesort', None, _('sort by saved mtime')),
>>> + ('', 'drop', None, _('drop file from dirstate'), _('FILE')),
>>> + ('', 'normal-lookup', None, _('add file to dirstate'), _('FILE'))],
>>> _('[OPTION]...'))
>>> -def debugstate(ui, repo, **opts):
>>> - """show the contents of the current dirstate"""
>>> +def debugstate(ui, repo, *pats, **opts):
>>> + """show or modify the contents of the current dirstate"""
>>> +
>>> + drop = opts.get('drop')
>>> + nl = opts.get('normal_lookup')
>>> +
>>> + if not nl is None and not drop is None:
>>
>> From looking at the codebase it seems like we prefer using "is not":
>>
>> "if nl is not None and drop is not None:"
>
> Compile to the same bytecode by python. X is not Y is the preferred form.
>
> http://legacy.python.org/dev/peps/pep-0008/#programming-recommendations
Also for this version, you could use "None not in (nl, drop)"
--
Pierre-Yves David
More information about the Mercurial-devel
mailing list