Patchwork [2,of,5,V2] debugdirstate: add option to drop or add files to dirstate

login
register
mail settings
Submitter Christian Delahousse
Date Nov. 17, 2015, 10:54 p.m.
Message ID <7e9f321545b481302597.1447800857@dev4253.prn1.facebook.com>
Download mbox | patch
Permalink /patch/11444/
State Changes Requested
Headers show

Comments

Christian Delahousse - Nov. 17, 2015, 10:54 p.m.
# HG changeset patch
# User Christian Delahousse <cdelahousse@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.
Laurent Charignon - Nov. 18, 2015, 1:18 a.m.
> On Nov 17, 2015, at 2:54 PM, cdelahousse@fb.com wrote:
> 
> # HG changeset patch
> # User Christian Delahousse <cdelahousse@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:"


> +        raise error.Abort('drop and normal-lookup are mutually exclusive')
> +
> +    if nl or drop:
> +        _moddirstate(repo, *pats, **opts)
> +        return
> 
>     nodates = opts.get('nodates')
>     datesort = opts.get('datesort')
> diff --git a/tests/test-completion.t b/tests/test-completion.t
> --- a/tests/test-completion.t
> +++ b/tests/test-completion.t
> @@ -243,7 +243,7 @@
>   debugdag: tags, branches, dots, spaces
>   debugdata: changelog, manifest, dir
>   debugdate: extended
> -  debugdirstate: nodates, datesort
> +  debugdirstate: nodates, datesort, drop, normal-lookup
>   debugdiscovery: old, nonheads, ssh, remotecmd, insecure
>   debugextensions: template
>   debugfileset: rev
> diff --git a/tests/test-help.t b/tests/test-help.t
> --- a/tests/test-help.t
> +++ b/tests/test-help.t
> @@ -800,7 +800,7 @@
>    debugdata     dump the contents of a data file revision
>    debugdate     parse and display a date
>    debugdirstate
> -                 show the contents of the current dirstate
> +                 show or modify the contents of the current dirstate
>    debugdiscovery
>                  runs the changeset discovery protocol in isolation
>    debugextensions
> diff --git a/tests/test-rebuildstate.t b/tests/test-rebuildstate.t
> --- a/tests/test-rebuildstate.t
> +++ b/tests/test-rebuildstate.t
> @@ -20,6 +20,19 @@
>   n 644         -1 set                 bar
>   n 644         -1 set                 foo
> 
> +  $ hg debugstate --normal-lookup file1 file2
> +  $ hg debugstate --drop bar
> +  $ hg debugstate --drop
> +  $ hg debugstate --nodates
> +  n   0         -1 unset               file1
> +  n   0         -1 unset               file2
> +  n 644         -1 set                 foo
> +  $ hg debugstate --normal-lookup file1 --drop file2
> +  abort: drop and normal-lookup are mutually exclusive
> +  [255]
> +
> +  $ hg debugrebuildstate
> +
> status
> 
>   $ hg st -A
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel
Pierre-Yves David - Nov. 18, 2015, 10:24 a.m.
On 11/17/2015 05:18 PM, Laurent Charignon wrote:
>
>> On Nov 17, 2015, at 2:54 PM, cdelahousse@fb.com wrote:
>>
>> # HG changeset patch
>> # User Christian Delahousse <cdelahousse@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
Pierre-Yves David - Nov. 18, 2015, 10:34 a.m.
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@fb.com wrote:
>>>
>>> # HG changeset patch
>>> # User Christian Delahousse <cdelahousse@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)"
Yuya Nishihara - Nov. 18, 2015, 1:14 p.m.
On Wed, 18 Nov 2015 02:34:41 -0800, Pierre-Yves David wrote:
> 
> 
> 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@fb.com wrote:
> >>>
> >>> # HG changeset patch
> >>> # User Christian Delahousse <cdelahousse@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)"

Aren't they boolean options? I think "bool_val is None" is too strict.

Patch

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'''
+    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:
+        raise error.Abort('drop and normal-lookup are mutually exclusive')
+
+    if nl or drop:
+        _moddirstate(repo, *pats, **opts)
+        return
 
     nodates = opts.get('nodates')
     datesort = opts.get('datesort')
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -243,7 +243,7 @@ 
   debugdag: tags, branches, dots, spaces
   debugdata: changelog, manifest, dir
   debugdate: extended
-  debugdirstate: nodates, datesort
+  debugdirstate: nodates, datesort, drop, normal-lookup
   debugdiscovery: old, nonheads, ssh, remotecmd, insecure
   debugextensions: template
   debugfileset: rev
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -800,7 +800,7 @@ 
    debugdata     dump the contents of a data file revision
    debugdate     parse and display a date
    debugdirstate
-                 show the contents of the current dirstate
+                 show or modify the contents of the current dirstate
    debugdiscovery
                  runs the changeset discovery protocol in isolation
    debugextensions
diff --git a/tests/test-rebuildstate.t b/tests/test-rebuildstate.t
--- a/tests/test-rebuildstate.t
+++ b/tests/test-rebuildstate.t
@@ -20,6 +20,19 @@ 
   n 644         -1 set                 bar
   n 644         -1 set                 foo
 
+  $ hg debugstate --normal-lookup file1 file2
+  $ hg debugstate --drop bar
+  $ hg debugstate --drop
+  $ hg debugstate --nodates
+  n   0         -1 unset               file1
+  n   0         -1 unset               file2
+  n 644         -1 set                 foo
+  $ hg debugstate --normal-lookup file1 --drop file2
+  abort: drop and normal-lookup are mutually exclusive
+  [255]
+
+  $ hg debugrebuildstate
+
 status
 
   $ hg st -A