Esempio n. 1
0
def getbkfile(orig, repo):
    if _hassharedbookmarks(repo):
        srcrepo = hg.sharedreposource(repo)
        if srcrepo is not None:
            # just orig(srcrepo) doesn't work as expected, because
            # HG_PENDING refers repo.root.
            try:
                fp, pending = txnutil.trypending(repo.root, repo.vfs,
                                                 'bookmarks')
                if pending:
                    # only in this case, bookmark information in repo
                    # is up-to-date.
                    return fp
                fp.close()
            except IOError as inst:
                if inst.errno != errno.ENOENT:
                    raise

            # otherwise, we should read bookmarks from srcrepo,
            # because .hg/bookmarks in srcrepo might be already
            # changed via another sharing repo
            repo = srcrepo

            # TODO: Pending changes in repo are still invisible in
            # srcrepo, because bookmarks.pending is written only into repo.
            # See also https://www.mercurial-scm.org/wiki/SharedRepository
    return orig(repo)
Esempio n. 2
0
def writerepo(orig, self, repo):
    # First write local bookmarks file in case we ever unshare
    orig(self, repo)

    if _hassharedbookmarks(self._repo):
        srcrepo = hg.sharedreposource(self._repo)
        if srcrepo is not None:
            orig(self, srcrepo)
Esempio n. 3
0
def unsharenarrowspec(orig, ui, repo, repopath):
    if (changegroup.NARROW_REQUIREMENT in repo.requirements
            and repo.path == repopath and repo.shared()):
        srcrepo = hg.sharedreposource(repo)
        with srcrepo.vfs(narrowspec.FILENAME) as f:
            spec = f.read()
        with repo.vfs(narrowspec.FILENAME, 'w') as f:
            f.write(spec)
    return orig(ui, repo, repopath)
Esempio n. 4
0
def recordchange(orig, self, tr):
    # Continue with write to local bookmarks file as usual
    orig(self, tr)

    if _hassharedbookmarks(self._repo):
        srcrepo = hg.sharedreposource(self._repo)
        if srcrepo is not None:
            category = 'share-bookmarks'
            tr.addpostclose(category, lambda tr: self._writerepo(srcrepo))
Esempio n. 5
0
    def __init__(self, repo):
        self.user = procutil.getuser()
        self.ui = repo.ui
        self.vfs = repo.vfs

        # is this working copy using a shared storage?
        self.sharedfeatures = self.sharedvfs = None
        if repo.shared():
            features = _readsharedfeatures(repo)
            sharedrepo = hg.sharedreposource(repo)
            if sharedrepo is not None and b'journal' in features:
                self.sharedvfs = sharedrepo.vfs
                self.sharedfeatures = features
Esempio n. 6
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')):
        sharedrepo = hg.sharedreposource(repo)
        sharedfeatures = _readsharedfeatures(repo)
        if sharedrepo and sharedfeatures > {b'journal'}:
            # there is a shared repository and there are shared journal entries
            # to copy. move shared date over from source to destination but
            # move the local file first
            if repo.vfs.exists(b'namejournal'):
                journalpath = repo.vfs.join(b'namejournal')
                util.rename(journalpath, journalpath + b'.bak')
            storage = repo.journal
            local = storage._open(repo.vfs,
                                  filename=b'namejournal.bak',
                                  _newestfirst=False)
            shared = (
                e for e in storage._open(sharedrepo.vfs, _newestfirst=False)
                if sharednamespaces.get(e.namespace) in sharedfeatures)
            for entry in _mergeentriesiter(local, shared, order=min):
                storage._write(repo.vfs, entry)

    return orig(ui, repo, repopath)