# HG changeset patch # User Adrian Buehlmann # Date 1306504792 -7200 # Node ID d1a1578c5f7860b17f2f238b2c1e6adb555ffa4f # Parent 7d171c05a6312cd17c327247e2214a8ba6495ce7 commands.remove: don't use workingctx.remove(list, unlink=True) workingctx.remove(list, unlink=True) is unsuited here, because it does too much: it also unlinks added files. But the command 'hg remove' is specified to *never* unlink added files. Instead, we now unlink the files at the commands.remove level (if --after was not specified) and use workingctx.forget for all files. As an added bonus, this happens to eliminate a wlock acquire/release pair, since the previous implementation caused acquire wlock release wlock acquire wlock release wlock where the first pair of acquire/release was caused by the workingctx.forget call, and the second by the workingctx.remove call. diff -r 7d171c05a631 -r d1a1578c5f78 mercurial/commands.py --- a/mercurial/commands.py Fri May 27 17:51:16 2011 +0300 +++ b/mercurial/commands.py Fri May 27 15:59:52 2011 +0200 @@ -8,7 +8,7 @@ from node import hex, bin, nullid, nullrev, short from lock import release from i18n import _, gettext -import os, re, sys, difflib, time, tempfile +import os, re, sys, difflib, time, tempfile, errno import hg, scmutil, util, revlog, extensions, copies, error, bookmarks import patch, help, url, encoding, templatekw, discovery import archival, changegroup, cmdutil, sshserver, hbisect, hgweb, hgweb.server @@ -3918,15 +3918,15 @@ ret = 1 if force: - remove, forget = modified + deleted + clean, added + list = modified + deleted + clean + added elif after: - remove, forget = deleted, [] + list = deleted for f in modified + added + clean: ui.warn(_('not removing %s: file still exists (use -f' ' to force removal)\n') % m.rel(f)) ret = 1 else: - remove, forget = deleted + clean, [] + list = deleted + clean for f in modified: ui.warn(_('not removing %s: file is modified (use -f' ' to force removal)\n') % m.rel(f)) @@ -3936,12 +3936,25 @@ ' to force removal)\n') % m.rel(f)) ret = 1 - for f in sorted(remove + forget): + for f in sorted(list): if ui.verbose or not m.exact(f): ui.status(_('removing %s\n') % m.rel(f)) - repo[None].forget(forget) - repo[None].remove(remove, unlink=not after) + wlock = repo.wlock() + try: + if not after: + for f in list: + if f in added: + continue # we never unlink added files on remove + try: + util.unlinkpath(repo.wjoin(f)) + except OSError, inst: + if inst.errno != errno.ENOENT: + raise + repo[None].forget(list) + finally: + wlock.release() + return ret @command('rename|move|mv',