comparison mercurial/commands.py @ 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 5f6090e559fa
children 9e3a89c9e46c
comparison
equal deleted inserted replaced
14449:7d171c05a631 14450:d1a1578c5f78
6 # GNU General Public License version 2 or any later version. 6 # GNU General Public License version 2 or any later version.
7 7
8 from node import hex, bin, nullid, nullrev, short 8 from node import hex, bin, nullid, nullrev, short
9 from lock import release 9 from lock import release
10 from i18n import _, gettext 10 from i18n import _, gettext
11 import os, re, sys, difflib, time, tempfile 11 import os, re, sys, difflib, time, tempfile, errno
12 import hg, scmutil, util, revlog, extensions, copies, error, bookmarks 12 import hg, scmutil, util, revlog, extensions, copies, error, bookmarks
13 import patch, help, url, encoding, templatekw, discovery 13 import patch, help, url, encoding, templatekw, discovery
14 import archival, changegroup, cmdutil, sshserver, hbisect, hgweb, hgweb.server 14 import archival, changegroup, cmdutil, sshserver, hbisect, hgweb, hgweb.server
15 import merge as mergemod 15 import merge as mergemod
16 import minirst, revset 16 import minirst, revset
3916 if f not in repo.dirstate and not os.path.isdir(m.rel(f)): 3916 if f not in repo.dirstate and not os.path.isdir(m.rel(f)):
3917 ui.warn(_('not removing %s: file is untracked\n') % m.rel(f)) 3917 ui.warn(_('not removing %s: file is untracked\n') % m.rel(f))
3918 ret = 1 3918 ret = 1
3919 3919
3920 if force: 3920 if force:
3921 remove, forget = modified + deleted + clean, added 3921 list = modified + deleted + clean + added
3922 elif after: 3922 elif after:
3923 remove, forget = deleted, [] 3923 list = deleted
3924 for f in modified + added + clean: 3924 for f in modified + added + clean:
3925 ui.warn(_('not removing %s: file still exists (use -f' 3925 ui.warn(_('not removing %s: file still exists (use -f'
3926 ' to force removal)\n') % m.rel(f)) 3926 ' to force removal)\n') % m.rel(f))
3927 ret = 1 3927 ret = 1
3928 else: 3928 else:
3929 remove, forget = deleted + clean, [] 3929 list = deleted + clean
3930 for f in modified: 3930 for f in modified:
3931 ui.warn(_('not removing %s: file is modified (use -f' 3931 ui.warn(_('not removing %s: file is modified (use -f'
3932 ' to force removal)\n') % m.rel(f)) 3932 ' to force removal)\n') % m.rel(f))
3933 ret = 1 3933 ret = 1
3934 for f in added: 3934 for f in added:
3935 ui.warn(_('not removing %s: file has been marked for add (use -f' 3935 ui.warn(_('not removing %s: file has been marked for add (use -f'
3936 ' to force removal)\n') % m.rel(f)) 3936 ' to force removal)\n') % m.rel(f))
3937 ret = 1 3937 ret = 1
3938 3938
3939 for f in sorted(remove + forget): 3939 for f in sorted(list):
3940 if ui.verbose or not m.exact(f): 3940 if ui.verbose or not m.exact(f):
3941 ui.status(_('removing %s\n') % m.rel(f)) 3941 ui.status(_('removing %s\n') % m.rel(f))
3942 3942
3943 repo[None].forget(forget) 3943 wlock = repo.wlock()
3944 repo[None].remove(remove, unlink=not after) 3944 try:
3945 if not after:
3946 for f in list:
3947 if f in added:
3948 continue # we never unlink added files on remove
3949 try:
3950 util.unlinkpath(repo.wjoin(f))
3951 except OSError, inst:
3952 if inst.errno != errno.ENOENT:
3953 raise
3954 repo[None].forget(list)
3955 finally:
3956 wlock.release()
3957
3945 return ret 3958 return ret
3946 3959
3947 @command('rename|move|mv', 3960 @command('rename|move|mv',
3948 [('A', 'after', None, _('record a rename that has already occurred')), 3961 [('A', 'after', None, _('record a rename that has already occurred')),
3949 ('f', 'force', None, _('forcibly copy over an existing managed file')), 3962 ('f', 'force', None, _('forcibly copy over an existing managed file')),