##// END OF EJS Templates
refactor some unlink/remove code and make sure we prune empty dir
Benoit Boissinot -
r1415:c6e6ca96 default
parent child Browse files
Show More
@@ -1441,12 +1441,7 b' def remove(ui, repo, pat, *pats, **opts)'
1441 if okaytoremove(abs, rel, exact):
1441 if okaytoremove(abs, rel, exact):
1442 if ui.verbose or not exact: ui.status(_('removing %s\n') % rel)
1442 if ui.verbose or not exact: ui.status(_('removing %s\n') % rel)
1443 names.append(abs)
1443 names.append(abs)
1444 for name in names:
1444 repo.remove(names, unlink=True)
1445 try:
1446 os.unlink(name)
1447 except OSError, inst:
1448 if inst.errno != errno.ENOENT: raise
1449 repo.remove(names)
1450
1445
1451 def rename(ui, repo, *pats, **opts):
1446 def rename(ui, repo, *pats, **opts):
1452 """rename files; equivalent of copy + remove"""
1447 """rename files; equivalent of copy + remove"""
@@ -1454,12 +1449,8 b' def rename(ui, repo, *pats, **opts):'
1454 names = []
1449 names = []
1455 for abs, rel, exact in copied:
1450 for abs, rel, exact in copied:
1456 if ui.verbose or not exact: ui.status(_('removing %s\n') % rel)
1451 if ui.verbose or not exact: ui.status(_('removing %s\n') % rel)
1457 try:
1458 os.unlink(rel)
1459 except OSError, inst:
1460 if inst.errno != errno.ENOENT: raise
1461 names.append(abs)
1452 names.append(abs)
1462 repo.remove(names)
1453 repo.remove(names, unlink=True)
1463 return errs
1454 return errs
1464
1455
1465 def revert(ui, repo, *names, **opts):
1456 def revert(ui, repo, *names, **opts):
@@ -536,7 +536,13 b' class localrepository:'
536 else:
536 else:
537 self.dirstate.forget([f])
537 self.dirstate.forget([f])
538
538
539 def remove(self, list):
539 def remove(self, list, unlink=False):
540 if unlink:
541 for f in list:
542 try:
543 util.unlink(self.wjoin(f))
544 except OSError, inst:
545 if inst.errno != errno.ENOENT: raise
540 for f in list:
546 for f in list:
541 p = self.wjoin(f)
547 p = self.wjoin(f)
542 if os.path.exists(p):
548 if os.path.exists(p):
@@ -1264,14 +1270,11 b' class localrepository:'
1264 for f in remove:
1270 for f in remove:
1265 self.ui.note(_("removing %s\n") % f)
1271 self.ui.note(_("removing %s\n") % f)
1266 try:
1272 try:
1267 os.unlink(self.wjoin(f))
1273 util.unlink(self.wjoin(f))
1268 except OSError, inst:
1274 except OSError, inst:
1269 if inst.errno != errno.ENOENT:
1275 if inst.errno != errno.ENOENT:
1270 self.ui.warn(_("update failed to remove %s: %s!\n") %
1276 self.ui.warn(_("update failed to remove %s: %s!\n") %
1271 (f, inst.strerror))
1277 (f, inst.strerror))
1272 # try removing directories that might now be empty
1273 try: os.removedirs(os.path.dirname(self.wjoin(f)))
1274 except: pass
1275 if moddirstate:
1278 if moddirstate:
1276 if branch_merge:
1279 if branch_merge:
1277 self.dirstate.update(remove, 'r')
1280 self.dirstate.update(remove, 'r')
@@ -310,6 +310,13 b' def rename(src, dst):'
310 os.unlink(dst)
310 os.unlink(dst)
311 os.rename(src, dst)
311 os.rename(src, dst)
312
312
313 def unlink(f):
314 """unlink and remove the directory if it is empty"""
315 os.unlink(f)
316 # try removing directories that might now be empty
317 try: os.removedirs(os.path.dirname(f))
318 except: pass
319
313 def copyfiles(src, dst, hardlink=None):
320 def copyfiles(src, dst, hardlink=None):
314 """Copy a directory tree using hardlinks if possible"""
321 """Copy a directory tree using hardlinks if possible"""
315
322
General Comments 0
You need to be logged in to leave comments. Login now