Esempio n. 1
0
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"))
Esempio n. 2
0
 def __init__(self, repo):
     self.lastrev = int(repo.sharedvfs.tryread(LASTREVFILE) or "0")
     self.map = nodemapmod.nodemap(repo.sharedvfs.join(MAPFILE))
     self.repo = repo