changeset 14450:d1a1578c5f78

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.
author Adrian Buehlmann <adrian@cadifra.com>
date Fri, 27 May 2011 15:59:52 +0200
parents 7d171c05a631
children c78d41db6f88 658eca733a35
files mercurial/commands.py
diffstat 1 files changed, 20 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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',