hgext3rd/topic/discovery.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Thu, 19 Apr 2018 10:50:24 +0200
changeset 3678 d725fe3e3989
parent 3186 9d9ff55d1bb1
child 3689 415c872d3308
permissions -rw-r--r--
topic: handle wireproto module change from b4d85bc122bd This module have been scattered in other place, so we need to detect and handle this for 4.6+
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1934
9d6d30e36cdd discovery: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1921
diff changeset
     1
from __future__ import absolute_import
9d6d30e36cdd discovery: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1921
diff changeset
     2
3182
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
     3
import collections
1887
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
     4
import weakref
1934
9d6d30e36cdd discovery: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1921
diff changeset
     5
1887
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
     6
from mercurial.i18n import _
1934
9d6d30e36cdd discovery: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1921
diff changeset
     7
from mercurial import (
1944
daad8249d5cf discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1934
diff changeset
     8
    bundle2,
daad8249d5cf discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1934
diff changeset
     9
    discovery,
1934
9d6d30e36cdd discovery: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1921
diff changeset
    10
    error,
9d6d30e36cdd discovery: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1921
diff changeset
    11
    exchange,
1944
daad8249d5cf discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1934
diff changeset
    12
    extensions,
2676
10dedac0d82e topic: also insert the extra head check with using the new head checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2675
diff changeset
    13
    util,
1934
9d6d30e36cdd discovery: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1921
diff changeset
    14
)
9d6d30e36cdd discovery: move to new style import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1921
diff changeset
    15
3678
d725fe3e3989 topic: handle wireproto module change from b4d85bc122bd
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3186
diff changeset
    16
try:
d725fe3e3989 topic: handle wireproto module change from b4d85bc122bd
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3186
diff changeset
    17
    from mercurial import wireproto
d725fe3e3989 topic: handle wireproto module change from b4d85bc122bd
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3186
diff changeset
    18
    wireproto.branchmap
d725fe3e3989 topic: handle wireproto module change from b4d85bc122bd
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3186
diff changeset
    19
except ImportError: # <= hg-4.5
d725fe3e3989 topic: handle wireproto module change from b4d85bc122bd
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3186
diff changeset
    20
    from mercurial import wireprotov1server as wireproto
d725fe3e3989 topic: handle wireproto module change from b4d85bc122bd
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3186
diff changeset
    21
2558
65cf338258d2 fix: fix _headssummary api
Boris Feld <boris.feld@octobus.net>
parents: 1965
diff changeset
    22
def _headssummary(orig, *args):
65cf338258d2 fix: fix _headssummary api
Boris Feld <boris.feld@octobus.net>
parents: 1965
diff changeset
    23
    # In mercurial < 4.2, we receive repo, remote and outgoing as arguments
3186
9d9ff55d1bb1 compat: fix comp ability of the new phase logic for Mercurial < 4.4
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3182
diff changeset
    24
    pushop = None
2558
65cf338258d2 fix: fix _headssummary api
Boris Feld <boris.feld@octobus.net>
parents: 1965
diff changeset
    25
    if len(args) == 3:
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2567
diff changeset
    26
        pushoparg = False
2558
65cf338258d2 fix: fix _headssummary api
Boris Feld <boris.feld@octobus.net>
parents: 1965
diff changeset
    27
        repo, remote, outgoing = args
65cf338258d2 fix: fix _headssummary api
Boris Feld <boris.feld@octobus.net>
parents: 1965
diff changeset
    28
65cf338258d2 fix: fix _headssummary api
Boris Feld <boris.feld@octobus.net>
parents: 1965
diff changeset
    29
    # In mercurial > 4.3, we receive the pushop as arguments
65cf338258d2 fix: fix _headssummary api
Boris Feld <boris.feld@octobus.net>
parents: 1965
diff changeset
    30
    elif len(args) == 1:
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2567
diff changeset
    31
        pushoparg = True
2558
65cf338258d2 fix: fix _headssummary api
Boris Feld <boris.feld@octobus.net>
parents: 1965
diff changeset
    32
        pushop = args[0]
65cf338258d2 fix: fix _headssummary api
Boris Feld <boris.feld@octobus.net>
parents: 1965
diff changeset
    33
        repo = pushop.repo.unfiltered()
65cf338258d2 fix: fix _headssummary api
Boris Feld <boris.feld@octobus.net>
parents: 1965
diff changeset
    34
        remote = pushop.remote
65cf338258d2 fix: fix _headssummary api
Boris Feld <boris.feld@octobus.net>
parents: 1965
diff changeset
    35
    else:
65cf338258d2 fix: fix _headssummary api
Boris Feld <boris.feld@octobus.net>
parents: 1965
diff changeset
    36
        msg = 'topic-ext _headssummary() takes 1 or 3 arguments (%d given)'
65cf338258d2 fix: fix _headssummary api
Boris Feld <boris.feld@octobus.net>
parents: 1965
diff changeset
    37
        raise TypeError(msg % len(args))
65cf338258d2 fix: fix _headssummary api
Boris Feld <boris.feld@octobus.net>
parents: 1965
diff changeset
    38
1886
0504e76bfbd9 push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    39
    publishing = ('phases' not in remote.listkeys('namespaces')
0504e76bfbd9 push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    40
                  or bool(remote.listkeys('phases').get('publishing', False)))
3182
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    41
    if ((publishing or not remote.capable('topics'))
3186
9d9ff55d1bb1 compat: fix comp ability of the new phase logic for Mercurial < 4.4
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3182
diff changeset
    42
            and not getattr(pushop, 'publish', False)):
2567
6eb87513024b fix: fix _headssummary call to orig
Boris Feld <boris.feld@octobus.net>
parents: 2558
diff changeset
    43
        return orig(*args)
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2567
diff changeset
    44
3182
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    45
    publishedset = ()
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    46
    remotebranchmap = None
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    47
    origremotebranchmap = remote.branchmap
3186
9d9ff55d1bb1 compat: fix comp ability of the new phase logic for Mercurial < 4.4
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3182
diff changeset
    48
    # < hg-4.4 do not have a --publish flag anyway
9d9ff55d1bb1 compat: fix comp ability of the new phase logic for Mercurial < 4.4
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3182
diff changeset
    49
    if pushoparg and util.safehasattr(pushop, 'remotephases'):
3182
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    50
        publishednode = [c.node() for c in pushop.outdatedphases]
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    51
        publishedset = repo.revs('ancestors(%ln + %ln)',
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    52
                                 publishednode,
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    53
                                 pushop.remotephases.publicheads)
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    54
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    55
        rev = repo.unfiltered().changelog.nodemap.get
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    56
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    57
        def remotebranchmap():
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    58
            # drop topic information from changeset about to be published
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    59
            result = collections.defaultdict(list)
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    60
            for branch, heads in origremotebranchmap().iteritems():
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    61
                if ':' not in branch:
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    62
                    result[branch].extend(heads)
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    63
                else:
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    64
                    namedbranch = branch.split(':', 1)[0]
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    65
                    for h in heads:
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    66
                        r = rev(h)
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    67
                        if r is not None and r in publishedset:
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    68
                            result[namedbranch].append(h)
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    69
                        else:
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    70
                            result[branch].append(h)
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    71
            for heads in result.itervalues():
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    72
                heads.sort()
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    73
            return result
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    74
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2567
diff changeset
    75
    class repocls(repo.__class__):
2696
a32afe67e8a6 topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2695
diff changeset
    76
        # awful hack to see branch as "branch:topic"
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2567
diff changeset
    77
        def __getitem__(self, key):
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2567
diff changeset
    78
            ctx = super(repocls, self).__getitem__(key)
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2567
diff changeset
    79
            oldbranch = ctx.branch
3182
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    80
            rev = ctx.rev()
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2567
diff changeset
    81
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2567
diff changeset
    82
            def branch():
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2567
diff changeset
    83
                branch = oldbranch()
3182
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    84
                if rev in publishedset:
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
    85
                    return branch
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2567
diff changeset
    86
                topic = ctx.topic()
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2567
diff changeset
    87
                if topic:
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2567
diff changeset
    88
                    branch = "%s:%s" % (branch, topic)
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2567
diff changeset
    89
                return branch
1965
0421772a9c30 discovery: flake8
Sean Farley <sean@farley.io>
parents: 1944
diff changeset
    90
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2567
diff changeset
    91
            ctx.branch = branch
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2567
diff changeset
    92
            return ctx
1965
0421772a9c30 discovery: flake8
Sean Farley <sean@farley.io>
parents: 1944
diff changeset
    93
2696
a32afe67e8a6 topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2695
diff changeset
    94
        def revbranchcache(self):
a32afe67e8a6 topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2695
diff changeset
    95
            rbc = super(repocls, self).revbranchcache()
a32afe67e8a6 topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2695
diff changeset
    96
            changelog = self.changelog
a32afe67e8a6 topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2695
diff changeset
    97
a32afe67e8a6 topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2695
diff changeset
    98
            def branchinfo(rev):
a32afe67e8a6 topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2695
diff changeset
    99
                branch, close = changelog.branchinfo(rev)
3182
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
   100
                if rev in publishedset:
bc09dd507c41 topic: fix new head detection when using --publish on a topic
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2696
diff changeset
   101
                    return branch, close
2696
a32afe67e8a6 topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2695
diff changeset
   102
                topic = repo[rev].topic()
a32afe67e8a6 topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2695
diff changeset
   103
                if topic:
a32afe67e8a6 topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2695
diff changeset
   104
                    branch = "%s:%s" % (branch, topic)
a32afe67e8a6 topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2695
diff changeset
   105
                return branch, close
a32afe67e8a6 topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2695
diff changeset
   106
a32afe67e8a6 topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2695
diff changeset
   107
            rbc.branchinfo = branchinfo
a32afe67e8a6 topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2695
diff changeset
   108
            return rbc
a32afe67e8a6 topic: also have the revbranchcache during the discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2695
diff changeset
   109
2695
b4824e169f18 topic: cleanup the repository wrapping logic in topic discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2676
diff changeset
   110
    oldrepocls = repo.__class__
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2567
diff changeset
   111
    try:
1886
0504e76bfbd9 push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   112
        repo.__class__ = repocls
3186
9d9ff55d1bb1 compat: fix comp ability of the new phase logic for Mercurial < 4.4
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3182
diff changeset
   113
        if remotebranchmap is not None:
9d9ff55d1bb1 compat: fix comp ability of the new phase logic for Mercurial < 4.4
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3182
diff changeset
   114
            remote.branchmap = remotebranchmap
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2567
diff changeset
   115
        unxx = repo.filtered('unfiltered-topic')
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2567
diff changeset
   116
        repo.unfiltered = lambda: unxx
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2567
diff changeset
   117
        if pushoparg:
2695
b4824e169f18 topic: cleanup the repository wrapping logic in topic discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2676
diff changeset
   118
            pushop.repo = repo
b4824e169f18 topic: cleanup the repository wrapping logic in topic discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2676
diff changeset
   119
            summary = orig(pushop)
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2567
diff changeset
   120
        else:
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2567
diff changeset
   121
            summary = orig(repo, remote, outgoing)
1886
0504e76bfbd9 push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   122
        for key, value in summary.iteritems():
0504e76bfbd9 push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   123
            if ':' in key: # This is a topic
0504e76bfbd9 push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   124
                if value[0] is None and value[1]:
2674
9585fac76d2d topic: adjust head checking wrapping to not interfere with concurrent push
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2673
diff changeset
   125
                    summary[key] = ([value[1][0]], ) + value[1:]
1886
0504e76bfbd9 push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   126
        return summary
0504e76bfbd9 push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   127
    finally:
2653
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2567
diff changeset
   128
        if 'unfiltered' in vars(repo):
13313d0cab71 topicmap: massive rework
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2567
diff changeset
   129
            del repo.unfiltered
2695
b4824e169f18 topic: cleanup the repository wrapping logic in topic discovery
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2676
diff changeset
   130
        repo.__class__ = oldrepocls
3186
9d9ff55d1bb1 compat: fix comp ability of the new phase logic for Mercurial < 4.4
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3182
diff changeset
   131
        if remotebranchmap is not None:
9d9ff55d1bb1 compat: fix comp ability of the new phase logic for Mercurial < 4.4
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3182
diff changeset
   132
            remote.branchmap = origremotebranchmap
1886
0504e76bfbd9 push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   133
0504e76bfbd9 push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   134
def wireprotobranchmap(orig, repo, proto):
0504e76bfbd9 push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   135
    oldrepo = repo.__class__
0504e76bfbd9 push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   136
    try:
0504e76bfbd9 push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   137
        class repocls(repo.__class__):
0504e76bfbd9 push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   138
            def branchmap(self):
0504e76bfbd9 push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   139
                usetopic = not self.publishing()
0504e76bfbd9 push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   140
                return super(repocls, self).branchmap(topic=usetopic)
0504e76bfbd9 push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   141
        repo.__class__ = repocls
0504e76bfbd9 push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   142
        return orig(repo, proto)
0504e76bfbd9 push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   143
    finally:
0504e76bfbd9 push: allow pushing new topic to non-publishing server by default
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   144
        repo.__class__ = oldrepo
1887
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   145
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   146
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   147
# Discovery have deficiency around phases, branch can get new heads with pure
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   148
# phases change. This happened with a changeset was allowed to be pushed
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   149
# because it had a topic, but it later become public and create a new branch
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   150
# head.
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   151
#
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   152
# Handle this by doing an extra check for new head creation server side
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   153
def _nbheads(repo):
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   154
    data = {}
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   155
    for b in repo.branchmap().iterbranches():
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   156
        if ':' in b[0]:
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   157
            continue
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   158
        data[b[0]] = len(b[1])
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   159
    return data
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   160
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   161
def handlecheckheads(orig, op, inpart):
2675
304232cc14b6 topic: some document for an obscure function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2674
diff changeset
   162
    """This is used to check for new heads when publishing changeset"""
1887
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   163
    orig(op, inpart)
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   164
    if op.repo.publishing():
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   165
        return
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   166
    tr = op.gettransaction()
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   167
    if tr.hookargs['source'] not in ('push', 'serve'): # not a push
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   168
        return
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   169
    tr._prepushheads = _nbheads(op.repo)
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   170
    reporef = weakref.ref(op.repo)
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   171
    oldvalidator = tr.validator
1921
4898296d7d25 discovery: whitespace
Sean Farley <sean@farley.io>
parents: 1920
diff changeset
   172
1887
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   173
    def validator(tr):
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   174
        repo = reporef()
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   175
        if repo is not None:
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   176
            repo.invalidatecaches()
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   177
            finalheads = _nbheads(repo)
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   178
            for branch, oldnb in tr._prepushheads.iteritems():
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   179
                newnb = finalheads.pop(branch, 0)
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   180
                if oldnb < newnb:
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   181
                    msg = _('push create a new head on branch "%s"' % branch)
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   182
                    raise error.Abort(msg)
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   183
            for branch, newnb in finalheads.iteritems():
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   184
                if 1 < newnb:
1921
4898296d7d25 discovery: whitespace
Sean Farley <sean@farley.io>
parents: 1920
diff changeset
   185
                    msg = _('push create more than 1 head on new branch "%s"'
4898296d7d25 discovery: whitespace
Sean Farley <sean@farley.io>
parents: 1920
diff changeset
   186
                            % branch)
1887
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   187
                    raise error.Abort(msg)
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   188
        return oldvalidator(tr)
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   189
    tr.validator = validator
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   190
handlecheckheads.params = frozenset()
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   191
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   192
def _pushb2phases(orig, pushop, bundler):
2673
1014341c637b topic: also detect head checking using the concurrent part
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2653
diff changeset
   193
    checktypes = ('check:heads', 'check:updated-heads')
1014341c637b topic: also detect head checking using the concurrent part
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2653
diff changeset
   194
    hascheck = any(p.type in checktypes for p in bundler._parts)
1014341c637b topic: also detect head checking using the concurrent part
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2653
diff changeset
   195
    if not hascheck and pushop.outdatedphases:
1887
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   196
        exchange._pushb2ctxcheckheads(pushop, bundler)
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   197
    return orig(pushop, bundler)
68125d026b07 push: hackish handeling of new branch head from phase move
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1886
diff changeset
   198
1903
58cdf061d49a topic: don't take topic into account when pushing to non-topic repo
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1901
diff changeset
   199
def wireprotocaps(orig, repo, proto):
58cdf061d49a topic: don't take topic into account when pushing to non-topic repo
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1901
diff changeset
   200
    caps = orig(repo, proto)
58cdf061d49a topic: don't take topic into account when pushing to non-topic repo
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1901
diff changeset
   201
    if repo.peer().capable('topics'):
58cdf061d49a topic: don't take topic into account when pushing to non-topic repo
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1901
diff changeset
   202
        caps.append('topics')
58cdf061d49a topic: don't take topic into account when pushing to non-topic repo
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1901
diff changeset
   203
    return caps
1944
daad8249d5cf discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1934
diff changeset
   204
daad8249d5cf discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1934
diff changeset
   205
def modsetup(ui):
daad8249d5cf discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1934
diff changeset
   206
    """run at uisetup time to install all destinations wrapping"""
daad8249d5cf discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1934
diff changeset
   207
    extensions.wrapfunction(discovery, '_headssummary', _headssummary)
daad8249d5cf discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1934
diff changeset
   208
    extensions.wrapfunction(wireproto, 'branchmap', wireprotobranchmap)
daad8249d5cf discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1934
diff changeset
   209
    extensions.wrapfunction(wireproto, '_capabilities', wireprotocaps)
2676
10dedac0d82e topic: also insert the extra head check with using the new head checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2675
diff changeset
   210
    # we need a proper wrap b2 part stuff
1944
daad8249d5cf discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1934
diff changeset
   211
    extensions.wrapfunction(bundle2, 'handlecheckheads', handlecheckheads)
daad8249d5cf discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1934
diff changeset
   212
    bundle2.handlecheckheads.params = frozenset()
daad8249d5cf discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1934
diff changeset
   213
    bundle2.parthandlermapping['check:heads'] = bundle2.handlecheckheads
2676
10dedac0d82e topic: also insert the extra head check with using the new head checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2675
diff changeset
   214
    if util.safehasattr(bundle2, 'handlecheckupdatedheads'):
10dedac0d82e topic: also insert the extra head check with using the new head checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2675
diff changeset
   215
        # we still need a proper wrap b2 part stuff
10dedac0d82e topic: also insert the extra head check with using the new head checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2675
diff changeset
   216
        extensions.wrapfunction(bundle2, 'handlecheckupdatedheads', handlecheckheads)
10dedac0d82e topic: also insert the extra head check with using the new head checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2675
diff changeset
   217
        bundle2.handlecheckupdatedheads.params = frozenset()
10dedac0d82e topic: also insert the extra head check with using the new head checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 2675
diff changeset
   218
        bundle2.parthandlermapping['check:updated-heads'] = bundle2.handlecheckupdatedheads
1944
daad8249d5cf discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1934
diff changeset
   219
    extensions.wrapfunction(exchange, '_pushb2phases', _pushb2phases)
daad8249d5cf discovery: move all setup into a 'modsetup' function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1934
diff changeset
   220
    exchange.b2partsgenmapping['phase'] = exchange._pushb2phases