comparison mercurial/merge.py @ 39464:3dd34b401bc2

merge: use vfs methods for I/O All I/O is supposed to be performed via vfs instances so filesystems can be abstracted. The previous commit ported the old code in purge, which didn't go through the vfs layer. This commit ports the purge code to use the vfs layer. The vfs layer didn't have a method to remove a single directory, so it was added as part of implementing this. Differential Revision: https://phab.mercurial-scm.org/D4478
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 04 Sep 2018 15:55:23 -0700
parents 7fea205fd5dc
children 24e493ec2229
comparison
equal deleted inserted replaced
39463:7fea205fd5dc 39464:3dd34b401bc2
7 7
8 from __future__ import absolute_import 8 from __future__ import absolute_import
9 9
10 import errno 10 import errno
11 import hashlib 11 import hashlib
12 import os
13 import shutil 12 import shutil
14 import struct 13 import struct
15 14
16 from .i18n import _ 15 from .i18n import _
17 from .node import ( 16 from .node import (
2265 or would be removed. 2264 or would be removed.
2266 """ 2265 """
2267 2266
2268 def remove(removefn, path): 2267 def remove(removefn, path):
2269 try: 2268 try:
2270 removefn(repo.wvfs.join(path)) 2269 removefn(path)
2271 except OSError: 2270 except OSError:
2272 m = _('%s cannot be removed') % path 2271 m = _('%s cannot be removed') % path
2273 if abortonerror: 2272 if abortonerror:
2274 raise error.Abort(m) 2273 raise error.Abort(m)
2275 else: 2274 else:
2291 2290
2292 if removefiles: 2291 if removefiles:
2293 for f in sorted(status.unknown + status.ignored): 2292 for f in sorted(status.unknown + status.ignored):
2294 if not noop: 2293 if not noop:
2295 repo.ui.note(_('removing file %s\n') % f) 2294 repo.ui.note(_('removing file %s\n') % f)
2296 remove(util.unlink, f) 2295 remove(repo.wvfs.unlink, f)
2297 res.append(f) 2296 res.append(f)
2298 2297
2299 if removeemptydirs: 2298 if removeemptydirs:
2300 for f in sorted(directories, reverse=True): 2299 for f in sorted(directories, reverse=True):
2301 if matcher(f) and not os.listdir(repo.wvfs.join(f)): 2300 if matcher(f) and not repo.wvfs.listdir(f):
2302 if not noop: 2301 if not noop:
2303 repo.ui.note(_('removing directory %s\n') % f) 2302 repo.ui.note(_('removing directory %s\n') % f)
2304 remove(os.rmdir, f) 2303 remove(repo.wvfs.rmdir, f)
2305 res.append(f) 2304 res.append(f)
2306 2305
2307 return res 2306 return res
2308 2307
2309 finally: 2308 finally: