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 mergefiles(ui, repo, wctx, shelvectx):
    """updates to wctx and merges the changes from shelvectx into the
    dirstate."""
    with ui.configoverride({("ui", "quiet"): True}):
        hg.update(repo, wctx.node())
        files = []
        files.extend(shelvectx.files())
        files.extend(shelvectx.p1().files())

        # revert will overwrite unknown files, so move them out of the way
        for file in repo.status(unknown=True).unknown:
            if file in files:
                util.rename(file, scmutil.origpath(ui, repo, file))
        ui.pushbuffer(True)
        cmdutil.revert(ui, repo, shelvectx, repo.dirstate.parents(),
                       *pathtofiles(repo, files), **{"no_backup": True})
        ui.popbuffer()
Esempio n. 3
0
def unsharejournal(orig, ui, repo, repopath):
    """Copy shared journal entries into this repo when unsharing"""
    if repo.path == repopath and repo.shared() and util.safehasattr(
            repo, "journal"):
        if repo.shared() and "journal" in repo.sharedfeatures:
            # there is a shared repository and there are shared journal entries
            # to copy. move shared data over from source to destination but
            # rename the local file first
            if repo.localvfs.exists("namejournal"):
                journalpath = repo.localvfs.join("namejournal")
                util.rename(journalpath, journalpath + ".bak")
            storage = repo.journal
            local = storage._open(repo.localvfs,
                                  filename="namejournal.bak",
                                  _newestfirst=False)
            shared = (
                e for e in storage._open(repo.sharedvfs, _newestfirst=False)
                if sharednamespaces.get(e.namespace) in repo.sharedfeatures)
            for entry in _mergeentriesiter(local, shared, order=min):
                storage._write(repo.localvfs, [entry])

    return orig(ui, repo, repopath)
Esempio n. 4
0
 def movetobackup(self):
     if not self.backupvfs.isdir():
         self.backupvfs.makedir()
     util.rename(self.filename(), self.backupfilename())