view src/topic/topicmap.py @ 1885:d49f75eab6a3

topic: take topic in account for all branch head computation This changeset introduce a "topicmap" that is tracking not just the head of all branches, but the heads of all branch+topic pair. Including the head of the part of the branch without any topic. In practice this means that BRANCHNAME now resolve to the tipmost part for the branch without topic and impact various other logic like head checking during push and default destination for update and merge (these aspect will need adjustment in later changesets). The on-the-fly-temporary-monkey-patching process is pretty horrible, but allow to move forward without waiting on having core patched. We use 'branch:topic' as the branchmap key, this is a small and easy hack that help use a lot for (future) support of heads discovery/checking and on disc cache. I'm not sure it is worthwhile to improve this until an implementation into core. Note that this changeset change the branchmap in all cases, including during exchange, see next changeset for improved behavior. We also currently have the on-disk cache disabled because the core branchmap is lacking phase information in its cache key. This will get done in a later changesets
author Pierre-Yves David <pierre-yves.david@fb.com>
date Sat, 12 Mar 2016 15:36:17 +0000
parents
children e846b8f402d0
line wrap: on
line source

from mercurial import branchmap

def _filename(repo):
    """name of a branchcache file for a given repo or repoview"""
    filename = "cache/topicmap"
    if repo.filtername:
        filename = '%s-%s' % (filename, repo.filtername)
    return filename

oldbranchcache = branchmap.branchcache

class topiccache(oldbranchcache):

    def __init__(self, *args, **kwargs):
        otherbranchcache = branchmap.branchcache
        try:
            # super() call may fail otherwise
            branchmap.branchcache = oldbranchcache
            return super(topiccache, self).__init__(*args, **kwargs)
        finally:
            branchmap.branchcache = otherbranchcache

    def branchtip(self, branch, topic=''):
        '''Return the tipmost open head on branch head, otherwise return the
        tipmost closed head on branch.
        Raise KeyError for unknown branch.'''
        if topic:
            branch = '%s:%s' % (branch, topic)
        return super(topiccache, self).branchtip(branch)

    def branchheads(self, branch, closed=False, topic=''):
        if topic:
            branch = '%s:%s' % (branch, topic)
        return super(topiccache, self).branchheads(branch, closed=closed)

    def write(self, repo):
        # The cache key needs to take phase root in account because change to
        # what is public affect topics. We can't write on disk until we have this.
        return

    def update(self, repo, revgen):
        """Given a branchhead cache, self, that may have extra nodes or be
        missing heads, and a generator of nodes that are strictly a superset of
        heads missing, this function updates self to be correct.
        """
        oldgetbranchinfo = repo.revbranchcache().branchinfo
        try:
            def branchinfo(r):
                info = oldgetbranchinfo(r)
                topic = ''
                ctx = repo[r]
                if ctx.mutable():
                    topic = ctx.topic()
                branch = info[0]
                if topic:
                    branch = '%s:%s' % (branch, topic)
                return (branch, info[1])
            repo.revbranchcache().branchinfo = branchinfo
            return super(topiccache, self).update(repo, revgen)
        finally:
            repo.revbranchcache().branchinfo = oldgetbranchinfo