def git_cleanup(ui, repo): """clean up Git commit map after history editing""" items = repo.githandler._map.items() if ui.configbool("hggit", "indexedlognodemap", False): dir = repo.sharedvfs.join(repo.githandler.map_file + "-log") tempdir = dir + ".temp" if os.path.exists(tempdir): hgutil.removedirs(tempdir) nodemap = nodemapmod.nodemap(tempdir) for gitsha, hgsha in items: if hgsha in repo: nodemap.add(gitsha, hgsha) nodemap.flush() with repo.wlock(): tempdir2 = dir + ".temp2" hgutil.rename(dir, tempdir2) hgutil.rename(tempdir, dir) shutil.rmtree(tempdir2) new_map = [] for gitsha, hgsha in items: if hgsha in repo: new_map.append("%s %s\n" % (hex(gitsha), hex(hgsha))) wlock = repo.wlock() try: f = repo.sharedvfs(GitHandler.map_file, "wb") map(f.write, new_map) finally: wlock.release() ui.status(_("git commit map cleaned\n"))
print(" success") print("rmdir d1 - should fail with ENOTEMPTY") tryfunc(lambda: os.rmdir(d1)) print("rmdir d1/d2 - should succeed") tryfunc(lambda: os.rmdir(d2)) open(d2, "w").close() print("rmdir d1 - should fail with ENOTEMPTY") tryfunc(lambda: os.rmdir(d1)) os.unlink(d2) print("rmdir d1 - should succeed") tryfunc(lambda: os.rmdir(d1)) print("rmdir d1 - should fail with ENOENT") tryfunc(lambda: os.rmdir(d1)) os.mkdir(d1) os.mkdir(d2) print("removedirs d2 (and d1) - should succeed") tryfunc(lambda: util.removedirs(d2)) print("removedirs d1 - should fail with ENOENT") tryfunc(lambda: util.removedirs(d1))