# HG changeset patch # User Matt Mackall # Date 1246422353 18000 # Node ID 627399330c7d2a660cf2b109c6dba7290a30ac3c # Parent 85b81cac9613b6e31745d840aa31d8852080adbc addremove: build lists of already added and removed files too (issue1696) diff -r 85b81cac9613 -r 627399330c7d mercurial/cmdutil.py --- a/mercurial/cmdutil.py Tue Jun 30 16:11:42 2009 -0500 +++ b/mercurial/cmdutil.py Tue Jun 30 23:25:53 2009 -0500 @@ -298,7 +298,8 @@ dry_run = opts.get('dry_run') if similarity is None: similarity = float(opts.get('similarity') or 0) - unknown, deleted = [], [] + # we'd use status here, except handling of symlinks and ignore is tricky + added, unknown, deleted, removed = [], [], [], [] audit_path = util.path_auditor(repo.root) m = match(repo, pats, opts) for abs in repo.walk(m): @@ -314,16 +315,22 @@ unknown.append(abs) 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 good or not util.lexists(target) + elif repo.dirstate[abs] != 'r' and (not good or not util.lexists(target) or (os.path.isdir(target) and not os.path.islink(target))): deleted.append(abs) if repo.ui.verbose or not exact: repo.ui.status(_('removing %s\n') % ((pats and rel) or abs)) + # for finding renames + elif repo.dirstate[abs] == 'r': + removed.append(abs) + elif repo.dirstate[abs] == 'a': + added.append(abs) if not dry_run: repo.remove(deleted) repo.add(unknown) if similarity > 0: - for old, new, score in findrenames(repo, unknown, deleted, similarity): + for old, new, score in findrenames(repo, added + unknown, + removed + deleted, similarity): if repo.ui.verbose or not m.exact(old) or not m.exact(new): repo.ui.status(_('recording removal of %s as rename to %s ' '(%d%% similar)\n') % diff -r 85b81cac9613 -r 627399330c7d tests/test-addremove --- a/tests/test-addremove Tue Jun 30 16:11:42 2009 -0500 +++ b/tests/test-addremove Tue Jun 30 23:25:53 2009 -0500 @@ -22,5 +22,6 @@ mv a b rm c echo d > d +hg addremove -n -s 50 # issue 1696 hg addremove -s 50 hg commit -mb diff -r 85b81cac9613 -r 627399330c7d tests/test-addremove.out --- a/tests/test-addremove.out Tue Jun 30 16:11:42 2009 -0500 +++ b/tests/test-addremove.out Tue Jun 30 23:25:53 2009 -0500 @@ -15,3 +15,8 @@ removing c adding d recording removal of a as rename to b (100% similar) +removing a +adding b +removing c +adding d +recording removal of a as rename to b (100% similar)