comparison mercurial/cmdutil.py @ 38497:da2a7d8354b2

unlinkpath: make empty directory removal optional (issue5901) (issue5826) There are known cases where performing operations such as rebase from a directory that is newly created can fail or at least lead to being in a directory handle that no longer exists. This is even reproducible by just doing something as simple as: cd foo; hg rm * The behavior is different if you use `hg addremove`, the directory is not removed until we attempt to go back to the node after committing it: cd foo; rm *; hg addremove; hg ci -m'bye foo'; hg co .^; hg co tip Differential Revision: https://phab.mercurial-scm.org/D3859
author Kyle Lippincott <spectral@google.com>
date Thu, 28 Jun 2018 18:07:22 -0700
parents 8459e8d2f729
children b1bbff1dd99a
comparison
equal deleted inserted replaced
38496:2394cd58b81f 38497:da2a7d8354b2
1240 # fix up dirstate 1240 # fix up dirstate
1241 scmutil.dirstatecopy(ui, repo, wctx, abssrc, abstarget, 1241 scmutil.dirstatecopy(ui, repo, wctx, abssrc, abstarget,
1242 dryrun=dryrun, cwd=cwd) 1242 dryrun=dryrun, cwd=cwd)
1243 if rename and not dryrun: 1243 if rename and not dryrun:
1244 if not after and srcexists and not samefile: 1244 if not after and srcexists and not samefile:
1245 repo.wvfs.unlinkpath(abssrc) 1245 rmdir = repo.ui.configbool('experimental', 'removeemptydirs')
1246 repo.wvfs.unlinkpath(abssrc, rmdir=rmdir)
1246 wctx.forget([abssrc]) 1247 wctx.forget([abssrc])
1247 1248
1248 # pat: ossep 1249 # pat: ossep
1249 # dest ossep 1250 # dest ossep
1250 # srcs: list of (hgsep, hgsep, ossep, bool) 1251 # srcs: list of (hgsep, hgsep, ossep, bool)
2267 with repo.wlock(): 2268 with repo.wlock():
2268 if not after: 2269 if not after:
2269 for f in list: 2270 for f in list:
2270 if f in added: 2271 if f in added:
2271 continue # we never unlink added files on remove 2272 continue # we never unlink added files on remove
2272 repo.wvfs.unlinkpath(f, ignoremissing=True) 2273 rmdir = repo.ui.configbool('experimental',
2274 'removeemptydirs')
2275 repo.wvfs.unlinkpath(f, ignoremissing=True, rmdir=rmdir)
2273 repo[None].forget(list) 2276 repo[None].forget(list)
2274 2277
2275 if warn: 2278 if warn:
2276 for warning in warnings: 2279 for warning in warnings:
2277 ui.warn(warning) 2280 ui.warn(warning)
3027 fc = ctx[f] 3030 fc = ctx[f]
3028 repo.wwrite(f, fc.data(), fc.flags()) 3031 repo.wwrite(f, fc.data(), fc.flags())
3029 3032
3030 def doremove(f): 3033 def doremove(f):
3031 try: 3034 try:
3032 repo.wvfs.unlinkpath(f) 3035 rmdir = repo.ui.configbool('experimental', 'removeemptydirs')
3036 repo.wvfs.unlinkpath(f, rmdir=rmdir)
3033 except OSError: 3037 except OSError:
3034 pass 3038 pass
3035 repo.dirstate.remove(f) 3039 repo.dirstate.remove(f)
3036 3040
3037 audit_path = pathutil.pathauditor(repo.root, cached=True) 3041 audit_path = pathutil.pathauditor(repo.root, cached=True)