view src/topic/discovery.py @ 1886:0504e76bfbd9

push: allow pushing new topic to non-publishing server by default This improves and fix the behavior change introduced by the new "topicmap". * Topics are properly ignored when pushing to a publishing server, * pushing new topics is allowed without --force a non-publishing server, * Pushing extra heads on a topic requires --force. Create of new head on a branch by phase movement is not properly detected for now. We'll improve that part in a later changesets. There is more awful monkey patching going on. We'll have to refactor core to get rid of them.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Sat, 12 Mar 2016 18:19:27 +0000
parents
children 68125d026b07
line wrap: on
line source

from mercurial import branchmap
from . import topicmap

def _headssummary(orig, repo, remote, outgoing):
    publishing = ('phases' not in remote.listkeys('namespaces')
                  or bool(remote.listkeys('phases').get('publishing', False)))
    if publishing:
        return orig(repo, remote, outgoing)
    oldgetitem = repo.__getitem__
    oldrepo = repo.__class__
    oldbranchcache = branchmap.branchcache
    oldfilename = branchmap._filename
    try:
        class repocls(repo.__class__):
            def __getitem__(self, key):
                ctx = super(repocls, self).__getitem__(key)
                oldbranch = ctx.branch
                def branch():
                    branch = oldbranch()
                    topic = ctx.topic()
                    if topic:
                        branch = "%s:%s" % (branch, topic)
                    return branch
                ctx.branch = branch
                return ctx
        repo.__class__ = repocls
        branchmap.branchcache = topicmap.topiccache
        branchmap._filename = topicmap._filename
        summary = orig(repo, remote, outgoing)
        for key, value in summary.iteritems():
            if ':' in key: # This is a topic
                if value[0] is None and value[1]:
                    summary[key] = ([value[1].pop(0)], ) + value[1:]
        return summary
    finally:
        repo.__class__ = oldrepo
        branchmap.branchcache = oldbranchcache
        branchmap._filename = oldfilename

def wireprotobranchmap(orig, repo, proto):
    oldrepo = repo.__class__
    print repo
    try:
        class repocls(repo.__class__):
            def branchmap(self):
                usetopic = not self.publishing()
                return super(repocls, self).branchmap(topic=usetopic)
        repo.__class__ = repocls
        return orig(repo, proto)
    finally:
        repo.__class__ = oldrepo