Mercurial > hg
changeset 6761:cb981fc955fb
remove: work directly off status
This allows us to use a single directory walk and to trivially ignore
unknown files. The resulting code is also easier to follow.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Fri, 27 Jun 2008 14:53:30 -0500 |
parents | 4faaa0535ea7 |
children | f67d1468ac50 |
files | mercurial/commands.py tests/test-remove.out |
diffstat | 2 files changed, 26 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Fri Jun 27 13:43:29 2008 -0500 +++ b/mercurial/commands.py Fri Jun 27 14:53:30 2008 -0500 @@ -2197,46 +2197,29 @@ raise util.Abort(_('no files specified')) m = cmdutil.match(repo, pats, opts) - mardu = map(dict.fromkeys, repo.status(match=m, unknown=True))[:5] - modified, added, removed, deleted, unknown = mardu - - remove, forget = [], [] - for abs in repo.walk(m): - - reason = None - if abs in removed or abs in unknown: - continue - - # last column - elif abs in deleted: - remove.append(abs) - - # rest of the third row - elif after and not force: - reason = _('still exists (use -f to force removal)') - - # rest of the first column - elif abs in added: - if not force: - reason = _('has been marked for add (use -f to force removal)') - else: - forget.append(abs) - - # rest of the third column - elif abs in modified: - if not force: - reason = _('is modified (use -f to force removal)') - else: - remove.append(abs) - - # rest of the second column - elif not reason: - remove.append(abs) - - if reason: - ui.warn(_('not removing %s: file %s\n') % (m.rel(abs), reason)) - elif ui.verbose or not m.exact(abs): - ui.status(_('removing %s\n') % m.rel(abs)) + s = repo.status(match=m, clean=True) + modified, added, deleted, clean = s[0], s[1], s[3], s[6] + + def warn(files, reason): + for f in files: + ui.warn(_('not removing %s: file %s (use -f to force removal)\n') + % (m.rel(f), reason)) + + if force: + remove, forget = modified + deleted + clean, added + elif after: + remove, forget = deleted, [] + warn(modified + added + clean, _('still exists')) + else: + remove, forget = deleted + clean, [] + warn(modified, _('is modified')) + warn(added, _('has been marked for add')) + + files = remove + forget + files.sort() + for f in files: + if ui.verbose or not m.exact(f): + ui.status(_('removing %s\n') % m.rel(f)) repo.forget(forget) repo.remove(remove, unlink=not after)
--- a/tests/test-remove.out Fri Jun 27 13:43:29 2008 -0500 +++ b/tests/test-remove.out Fri Jun 27 14:53:30 2008 -0500 @@ -70,15 +70,15 @@ adding test/bar adding test/foo % dir, options none +removing test/bar removing test/foo -removing test/bar R test/bar R test/foo ./foo 2 files updated, 0 files merged, 0 files removed, 0 files unresolved % dir, options -f +removing test/bar removing test/foo -removing test/bar R test/bar R test/foo ./foo @@ -91,8 +91,8 @@ ./test/foo 1 files updated, 0 files merged, 0 files removed, 0 files unresolved % dir, options -Af +removing test/bar removing test/foo -removing test/bar R test/bar R test/foo ./foo