Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 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 |
comparison
equal
deleted
inserted
replaced
6760:4faaa0535ea7 | 6761:cb981fc955fb |
---|---|
2195 after, force = opts.get('after'), opts.get('force') | 2195 after, force = opts.get('after'), opts.get('force') |
2196 if not pats and not after: | 2196 if not pats and not after: |
2197 raise util.Abort(_('no files specified')) | 2197 raise util.Abort(_('no files specified')) |
2198 | 2198 |
2199 m = cmdutil.match(repo, pats, opts) | 2199 m = cmdutil.match(repo, pats, opts) |
2200 mardu = map(dict.fromkeys, repo.status(match=m, unknown=True))[:5] | 2200 s = repo.status(match=m, clean=True) |
2201 modified, added, removed, deleted, unknown = mardu | 2201 modified, added, deleted, clean = s[0], s[1], s[3], s[6] |
2202 | 2202 |
2203 remove, forget = [], [] | 2203 def warn(files, reason): |
2204 for abs in repo.walk(m): | 2204 for f in files: |
2205 | 2205 ui.warn(_('not removing %s: file %s (use -f to force removal)\n') |
2206 reason = None | 2206 % (m.rel(f), reason)) |
2207 if abs in removed or abs in unknown: | 2207 |
2208 continue | 2208 if force: |
2209 | 2209 remove, forget = modified + deleted + clean, added |
2210 # last column | 2210 elif after: |
2211 elif abs in deleted: | 2211 remove, forget = deleted, [] |
2212 remove.append(abs) | 2212 warn(modified + added + clean, _('still exists')) |
2213 | 2213 else: |
2214 # rest of the third row | 2214 remove, forget = deleted + clean, [] |
2215 elif after and not force: | 2215 warn(modified, _('is modified')) |
2216 reason = _('still exists (use -f to force removal)') | 2216 warn(added, _('has been marked for add')) |
2217 | 2217 |
2218 # rest of the first column | 2218 files = remove + forget |
2219 elif abs in added: | 2219 files.sort() |
2220 if not force: | 2220 for f in files: |
2221 reason = _('has been marked for add (use -f to force removal)') | 2221 if ui.verbose or not m.exact(f): |
2222 else: | 2222 ui.status(_('removing %s\n') % m.rel(f)) |
2223 forget.append(abs) | |
2224 | |
2225 # rest of the third column | |
2226 elif abs in modified: | |
2227 if not force: | |
2228 reason = _('is modified (use -f to force removal)') | |
2229 else: | |
2230 remove.append(abs) | |
2231 | |
2232 # rest of the second column | |
2233 elif not reason: | |
2234 remove.append(abs) | |
2235 | |
2236 if reason: | |
2237 ui.warn(_('not removing %s: file %s\n') % (m.rel(abs), reason)) | |
2238 elif ui.verbose or not m.exact(abs): | |
2239 ui.status(_('removing %s\n') % m.rel(abs)) | |
2240 | 2223 |
2241 repo.forget(forget) | 2224 repo.forget(forget) |
2242 repo.remove(remove, unlink=not after) | 2225 repo.remove(remove, unlink=not after) |
2243 | 2226 |
2244 def rename(ui, repo, *pats, **opts): | 2227 def rename(ui, repo, *pats, **opts): |