Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 2309:b2f37c7026ca
remove: rewrite to be ~400x faster, bit more friendly
old remove code called localrepo.changes for each file.
was very expensive:
$ hg --time rm arch>/dev/null
Time: real 1066.120 secs (user 1014.450+0.000 sys 18.090+0.000)
new code, same files:
$ hg --time rm arch>/dev/null
Time: real 2.770 secs (user 2.190+0.000 sys 0.580+0.000)
also mention "-f" if not removing files. also allow "-f" to forget
added files.
make test a bit better.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Thu, 18 May 2006 13:48:12 -0700 |
parents | 7c2623aedeb4 |
children | b30aa02c85e7 |
comparison
equal
deleted
inserted
replaced
2308:cb520d961d6a | 2309:b2f37c7026ca |
---|---|
2187 This command schedules the files to be removed at the next commit. | 2187 This command schedules the files to be removed at the next commit. |
2188 This only removes files from the current branch, not from the | 2188 This only removes files from the current branch, not from the |
2189 entire project history. If the files still exist in the working | 2189 entire project history. If the files still exist in the working |
2190 directory, they will be deleted from it. If invoked with --after, | 2190 directory, they will be deleted from it. If invoked with --after, |
2191 files that have been manually deleted are marked as removed. | 2191 files that have been manually deleted are marked as removed. |
2192 | |
2193 Modified files and added files are not removed by default. To | |
2194 remove them, use the -f/--force option. | |
2192 """ | 2195 """ |
2193 names = [] | 2196 names = [] |
2194 if not opts['after'] and not pats: | 2197 if not opts['after'] and not pats: |
2195 raise util.Abort(_('no files specified')) | 2198 raise util.Abort(_('no files specified')) |
2196 def okaytoremove(abs, rel, exact): | 2199 files, matchfn, anypats = matchpats(repo, pats, opts) |
2197 modified, added, removed, deleted, unknown = repo.changes(files=[abs]) | 2200 exact = dict.fromkeys(files) |
2201 mardu = map(dict.fromkeys, repo.changes(files=files, match=matchfn)) | |
2202 modified, added, removed, deleted, unknown = mardu | |
2203 remove, forget = [], [] | |
2204 for src, abs, rel, exact in walk(repo, pats, opts): | |
2198 reason = None | 2205 reason = None |
2199 if not deleted and opts['after']: | 2206 if abs not in deleted and opts['after']: |
2200 reason = _('is still present') | 2207 reason = _('is still present') |
2201 elif modified and not opts['force']: | 2208 elif abs in modified and not opts['force']: |
2202 reason = _('is modified') | 2209 reason = _('is modified (use -f to force removal)') |
2203 elif added: | 2210 elif abs in added: |
2204 reason = _('has been marked for add') | 2211 if opts['force']: |
2205 elif unknown: | 2212 forget.append(abs) |
2213 continue | |
2214 reason = _('has been marked for add (use -f to force removal)') | |
2215 elif abs in unknown: | |
2206 reason = _('is not managed') | 2216 reason = _('is not managed') |
2207 elif removed: | 2217 elif abs in removed: |
2208 return False | 2218 continue |
2209 if reason: | 2219 if reason: |
2210 if exact: | 2220 if exact: |
2211 ui.warn(_('not removing %s: file %s\n') % (rel, reason)) | 2221 ui.warn(_('not removing %s: file %s\n') % (rel, reason)) |
2212 else: | 2222 else: |
2213 return True | |
2214 for src, abs, rel, exact in walk(repo, pats, opts): | |
2215 if okaytoremove(abs, rel, exact): | |
2216 if ui.verbose or not exact: | 2223 if ui.verbose or not exact: |
2217 ui.status(_('removing %s\n') % rel) | 2224 ui.status(_('removing %s\n') % rel) |
2218 names.append(abs) | 2225 remove.append(abs) |
2219 repo.remove(names, unlink=not opts['after']) | 2226 repo.forget(forget) |
2227 repo.remove(remove, unlink=not opts['after']) | |
2220 | 2228 |
2221 def rename(ui, repo, *pats, **opts): | 2229 def rename(ui, repo, *pats, **opts): |
2222 """rename files; equivalent of copy + remove | 2230 """rename files; equivalent of copy + remove |
2223 | 2231 |
2224 Mark dest as copies of sources; mark sources for deletion. If | 2232 Mark dest as copies of sources; mark sources for deletion. If |