[PATCH 2 of 2] addremove: add --full/-f to force rematching of all removed files (status ! or R)
Patrick Mézard
pmezard at gmail.com
Sun Apr 6 11:55:02 CDT 2008
Peter Arrenbrecht a écrit :
> # HG changeset patch
> # User Peter Arrenbrecht <peter.arrenbrecht at gmail.com>
> # Date 1207165043 -7200
> # Node ID b007e781b89191603950acfb228fe0d4de97d382
> # Parent e43616661358fa319579c0d9db6d50d6a1d69d18
> addremove: add --full/-f to force rematching of all removed files (status ! or R)
--full is really ambiguous, could be understood as --all. What about --redo, --replay, --again or something like that ?
> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py
> +++ b/mercurial/cmdutil.py
> @@ -267,31 +267,51 @@
> if bestname:
> yield bestname, a, bestscore
>
> -def addremove(repo, pats=[], opts={}, dry_run=None, similarity=None):
> +def addremove(repo, pats=[], opts={}, dry_run=None, similarity=None, full=None):
> if dry_run is None:
> dry_run = opts.get('dry_run')
> if similarity is None:
> similarity = float(opts.get('similarity') or 0)
> - add, remove = [], []
> + if full is None:
> + full = opts.get('full')
> + newfiles, deletedfiles = [], []
> + sources, targets = [], []
> mapping = {}
> + detectingrenames = (similarity > 0)
> for src, abs, rel, exact in walk(repo, pats, opts):
> target = repo.wjoin(abs)
> - if src == 'f' and abs not in repo.dirstate:
> - add.append(abs)
> - mapping[abs] = rel, exact
> - if repo.ui.verbose or not exact:
> - repo.ui.status(_('adding %s\n') % ((pats and rel) or abs))
> - if repo.dirstate[abs] != 'r' and (not util.lexists(target)
> - or (os.path.isdir(target) and not os.path.islink(target))):
> - remove.append(abs)
> - mapping[abs] = rel, exact
> - if repo.ui.verbose or not exact:
> - repo.ui.status(_('removing %s\n') % ((pats and rel) or abs))
> + if src == 'f':
> + isrecorded = abs in repo.dirstate
> + issource = False
> + if not isrecorded:
> + newfiles.append(abs)
> + if repo.ui.verbose or not exact:
> + repo.ui.status(_('adding %s\n') % ((pats and rel) or abs))
> + issource = detectingrenames
> + elif detectingrenames and full:
> + issource = repo.dirstate[abs] == 'a'
> + if issource:
> + targets.append(abs)
> + mapping[abs] = rel, exact
I really prefer the version without boolean variables:
isrecorded = abs in repo.dirstate
if not isrecorded:
newfiles.append(abs)
if repo.ui.verbose or not exact:
repo.ui.status(_('adding %s\n') % ((pats and rel) or abs))
if detectingrenames:
if not isrecorded or (full and repo.dirstate[abs] == 'a'):
targets.append(abs)
mapping[abs] = rel, exact
Less work for my lazy brain.
Do you think the next "if" can be changed into and "elif" ? We would stat the working directory a bit less. The "src == 'f'" and the existence tests look exclusive to me.
> + if (not util.lexists(target) or
> + (os.path.isdir(target) and not os.path.islink(target))):
> + isrecorded = repo.dirstate[abs] == 'r'
> + istarget = False
> + if not isrecorded:
> + deletedfiles.append(abs)
> + if repo.ui.verbose or not exact:
> + repo.ui.status(_('removing %s\n') % ((pats and rel) or abs))
> + istarget = detectingrenames
> + elif full:
> + istarget = detectingrenames
> + if istarget:
> + sources.append(abs)
> + mapping[abs] = rel, exact
Same remark here:
isrecorded = repo.dirstate[abs] == 'r'
if not isrecorded:
deletedfiles.append(abs)
if repo.ui.verbose or not exact:
repo.ui.status(_('removing %s\n') % ((pats and rel) or abs))
if detectingrenames:
if not isrecorded or full:
sources.append(abs)
mapping[abs] = rel, exact
--
Patrick Mézard
More information about the Mercurial-devel
mailing list