[PATCH 2 of 4] debugdirstate: add option to drop or add files to dirstate

Yuya Nishihara yuya at tcha.org
Fri Nov 13 13:57:23 UTC 2015


On Wed, 11 Nov 2015 22:17:56 -0800, cdelahousse at fb.com wrote:
> # HG changeset patch
> # User Christian Delahousse <cdelahousse at fb.com>
> # Date 1446522845 28800
> #      Mon Nov 02 19:54:05 2015 -0800
> # Node ID cb5481344592d2a38f1a6724324542a3d2708ec0
> # Parent  88237bdf95f715685488ba0260a27d6dd5dd5bb2
> 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,42 @@
>      finally:
>          wlock.release()
>  
> +def _moddirstate(repo, filestolookup=None, filestodrop=None):
> +    '''Manually add or drop a file to the dirstate'''
> +    wlock = repo.wlock()
> +    lock = repo.lock()
> +    try:
> +        tr = repo.transaction('dirstate')
> +        if filestolookup:
> +            for file in filestolookup:
> +                repo.dirstate.normallookup(file)
> +        else:
> +            for file in filestodrop:
> +                repo.dirstate.drop(file)
> +        repo.dirstate.write(tr)
> +        tr.close()
> +    finally:
> +        lock.release()
> +        wlock.release()

Not sure if we need a transaction (and repo.lock) just to modify dirstate.

> +
>  @command('debugdirstate|debugstate',
>      [('', 'nodates', None, _('do not display the saved mtime')),
> -    ('', 'datesort', None, _('sort by saved mtime'))],
> +    ('', 'datesort', None, _('sort by saved mtime')),
> +    ('', 'drop', [], _('drop file from dirstate'), _('FILE')),
> +    ('', 'normal-lookup', [], _('add file to dirstate'), _('FILE'))],
>      _('[OPTION]...'))
>  def debugstate(ui, repo, **opts):
> -    """show the contents of the current dirstate"""
> +    """show or modify the contents of the current dirstate"""
> +
> +    drop = opts.get('drop')
> +    nl = opts.get('normal_lookup')
> +
> +    if nl and drop:
> +        error.Abort('drop and normal-lookup are mutually exclusive')
> +
> +    if nl or drop:
> +        _moddirstate(repo, nl, drop)

As --normal-lookup and --drop are designed exclusive, we'd probably want to
do "hg debugdirstate --normal file1 file2 ...", i.e. bool **opts and *pats.

I want to call it --add (or --add-normal), but that would be a matter of taste.

Regards,



More information about the Mercurial-devel mailing list