hgext3rd/serverminitopic.py
author Matt Harbison <matt_harbison@yahoo.com>
Sat, 27 Apr 2019 22:59:48 -0400
changeset 4624 c9798965b1f4
parent 4521 5303b9128714
child 4758 f0ecf2137824
permissions -rw-r--r--
revset: switch internal uses and tests to `predecessors` from legacy name
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3206
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     1
"""enable a minimal verison of topic for server
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     2
4364
b74a31c69ad5 minitopic: add warning about extensions state and testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4187
diff changeset
     3
! This extensions is not actively maintained
b74a31c69ad5 minitopic: add warning about extensions state and testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4187
diff changeset
     4
! We recommand using the main topic extension instead
b74a31c69ad5 minitopic: add warning about extensions state and testing
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 4187
diff changeset
     5
3206
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     6
Non publishing repository will see topic as "branch:topic" in the branch field.
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     7
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     8
In addition to adding the extensions, the feature must be manually enabled in the config:
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
     9
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    10
    [experimental]
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    11
    server-mini-topic = yes
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    12
"""
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    13
import hashlib
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    14
import contextlib
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    15
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    16
from mercurial import (
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    17
    branchmap,
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    18
    context,
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    19
    encoding,
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    20
    extensions,
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    21
    node,
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    22
    registrar,
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    23
    util,
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    24
)
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    25
3679
b12c5d107187 minitopic: handle wireproto module change from b4d85bc122bd
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3651
diff changeset
    26
try:
b12c5d107187 minitopic: handle wireproto module change from b4d85bc122bd
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3651
diff changeset
    27
    from mercurial import wireproto
b12c5d107187 minitopic: handle wireproto module change from b4d85bc122bd
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3651
diff changeset
    28
    wireproto.branchmap
b12c5d107187 minitopic: handle wireproto module change from b4d85bc122bd
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3651
diff changeset
    29
except ImportError: # <= hg-4.5
b12c5d107187 minitopic: handle wireproto module change from b4d85bc122bd
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3651
diff changeset
    30
    from mercurial import wireprotov1server as wireproto
b12c5d107187 minitopic: handle wireproto module change from b4d85bc122bd
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3651
diff changeset
    31
3206
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    32
if util.safehasattr(registrar, 'configitem'):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    33
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    34
    configtable = {}
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    35
    configitem = registrar.configitem(configtable)
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    36
    configitem('experimental', 'server-mini-topic',
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    37
               default=False,
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    38
    )
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    39
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    40
def hasminitopic(repo):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    41
    """true if minitopic is enabled on the repository
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    42
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    43
    (The value is cached on the repository)
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    44
    """
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    45
    enabled = getattr(repo, '_hasminitopic', None)
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    46
    if enabled is None:
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    47
        enabled = (repo.ui.configbool('experimental', 'server-mini-topic')
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    48
                   and not repo.publishing())
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    49
        repo._hasminitopic = enabled
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    50
    return enabled
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    51
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    52
### make topic visible though "ctx.branch()"
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    53
3651
fa15068a9945 serverminitopic: wrap context.changectx.branch instead of context.changectx
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3518
diff changeset
    54
def topicbranch(orig, self):
fa15068a9945 serverminitopic: wrap context.changectx.branch instead of context.changectx
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3518
diff changeset
    55
    branch = orig(self)
fa15068a9945 serverminitopic: wrap context.changectx.branch instead of context.changectx
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3518
diff changeset
    56
    if hasminitopic(self._repo) and self.phase():
fa15068a9945 serverminitopic: wrap context.changectx.branch instead of context.changectx
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3518
diff changeset
    57
        topic = self._changeset.extra.get('topic')
fa15068a9945 serverminitopic: wrap context.changectx.branch instead of context.changectx
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3518
diff changeset
    58
        if topic is not None:
fa15068a9945 serverminitopic: wrap context.changectx.branch instead of context.changectx
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3518
diff changeset
    59
            topic = encoding.tolocal(topic)
fa15068a9945 serverminitopic: wrap context.changectx.branch instead of context.changectx
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3518
diff changeset
    60
            branch = '%s:%s' % (branch, topic)
fa15068a9945 serverminitopic: wrap context.changectx.branch instead of context.changectx
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3518
diff changeset
    61
    return branch
3206
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    62
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    63
### avoid caching topic data in rev-branch-cache
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    64
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    65
class revbranchcacheoverlay(object):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    66
    """revbranch mixin that don't use the cache for non public changeset"""
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    67
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    68
    def _init__(self, *args, **kwargs):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    69
        super(revbranchcacheoverlay, self).__init__(*args, **kwargs)
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    70
        if 'branchinfo' in vars(self):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    71
            del self.branchinfo
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    72
4187
49d442a2207f topic: add the changelog argument to branchinfo()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 3679
diff changeset
    73
    def branchinfo(self, rev, changelog=None):
3206
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    74
        """return branch name and close flag for rev, using and updating
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    75
        persistent cache."""
3511
768f752b5364 serverminitopic: fix wrong object being passed to phase
Sean Farley <sean@farley.io>
parents: 3207
diff changeset
    76
        phase = self._repo._phasecache.phase(self._repo, rev)
3206
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    77
        if phase:
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    78
            ctx = self._repo[rev]
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    79
            return ctx.branch(), ctx.closesbranch()
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    80
        return super(revbranchcacheoverlay, self).branchinfo(rev)
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    81
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    82
def reposetup(ui, repo):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    83
    """install a repo class with a special revbranchcache"""
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    84
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    85
    if hasminitopic(repo):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    86
        repo = repo.unfiltered()
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    87
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    88
        class minitopicrepo(repo.__class__):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    89
            """repository subclass that install the modified cache"""
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    90
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    91
            def revbranchcache(self):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    92
                if self._revbranchcache is None:
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    93
                    cache = super(minitopicrepo, self).revbranchcache()
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    94
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    95
                    class topicawarerbc(revbranchcacheoverlay, cache.__class__):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    96
                        pass
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    97
                    cache.__class__ = topicawarerbc
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    98
                    if 'branchinfo' in vars(cache):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
    99
                        del cache.branchinfo
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   100
                    self._revbranchcache = cache
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   101
                return self._revbranchcache
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   102
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   103
        repo.__class__ = minitopicrepo
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   104
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   105
### topic aware branch head cache
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   106
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   107
def _phaseshash(repo, maxrev):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   108
    """uniq ID for a phase matching a set of rev"""
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   109
    revs = set()
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   110
    cl = repo.changelog
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   111
    fr = cl.filteredrevs
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   112
    nm = cl.nodemap
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   113
    for roots in repo._phasecache.phaseroots[1:]:
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   114
        for n in roots:
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   115
            r = nm.get(n)
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   116
            if r not in fr and r < maxrev:
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   117
                revs.add(r)
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   118
    key = node.nullid
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   119
    revs = sorted(revs)
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   120
    if revs:
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   121
        s = hashlib.sha1()
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   122
        for rev in revs:
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   123
            s.update('%s;' % rev)
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   124
        key = s.digest()
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   125
    return key
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   126
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   127
# needed to prevent reference used for 'super()' call using in branchmap.py to
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   128
# no go into cycle. (yes, URG)
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   129
_oldbranchmap = branchmap.branchcache
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   130
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   131
@contextlib.contextmanager
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   132
def oldbranchmap():
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   133
    previous = branchmap.branchcache
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   134
    try:
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   135
        branchmap.branchcache = _oldbranchmap
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   136
        yield
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   137
    finally:
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   138
        branchmap.branchcache = previous
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   139
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   140
_publiconly = set([
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   141
    'base',
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   142
    'immutable',
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   143
])
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   144
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   145
def mighttopic(repo):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   146
    return hasminitopic(repo) and repo.filtername not in _publiconly
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   147
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   148
class _topiccache(branchmap.branchcache): # combine me with branchmap.branchcache
4394
c6d1b0a6babe topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents: 4364
diff changeset
   149
    @classmethod
c6d1b0a6babe topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents: 4364
diff changeset
   150
    def fromfile(cls, repo):
c6d1b0a6babe topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents: 4364
diff changeset
   151
        orig = super(_topiccache, cls).fromfile
c6d1b0a6babe topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents: 4364
diff changeset
   152
        return wrapread(orig, repo)
3206
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   153
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   154
    def __init__(self, *args, **kwargs):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   155
        # super() call may fail otherwise
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   156
        with oldbranchmap():
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   157
            super(_topiccache, self).__init__(*args, **kwargs)
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   158
        self.phaseshash = None
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   159
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   160
    def copy(self):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   161
        """return an deep copy of the branchcache object"""
4521
5303b9128714 serverminitopic: add compatibility for branchcache that now uses self._entries
Anton Shestakov <av6@dwimlabs.net>
parents: 4394
diff changeset
   162
        if util.safehasattr(self, '_entries'):
5303b9128714 serverminitopic: add compatibility for branchcache that now uses self._entries
Anton Shestakov <av6@dwimlabs.net>
parents: 4394
diff changeset
   163
            _entries = self._entries
5303b9128714 serverminitopic: add compatibility for branchcache that now uses self._entries
Anton Shestakov <av6@dwimlabs.net>
parents: 4394
diff changeset
   164
        else:
5303b9128714 serverminitopic: add compatibility for branchcache that now uses self._entries
Anton Shestakov <av6@dwimlabs.net>
parents: 4394
diff changeset
   165
            # hg <= 4.9 (624d6683c705, b137a6793c51)
5303b9128714 serverminitopic: add compatibility for branchcache that now uses self._entries
Anton Shestakov <av6@dwimlabs.net>
parents: 4394
diff changeset
   166
            _entries = self
5303b9128714 serverminitopic: add compatibility for branchcache that now uses self._entries
Anton Shestakov <av6@dwimlabs.net>
parents: 4394
diff changeset
   167
        new = self.__class__(_entries, self.tipnode, self.tiprev,
5303b9128714 serverminitopic: add compatibility for branchcache that now uses self._entries
Anton Shestakov <av6@dwimlabs.net>
parents: 4394
diff changeset
   168
                             self.filteredhash, self._closednodes)
3206
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   169
        new.phaseshash = self.phaseshash
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   170
        return new
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   171
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   172
    def validfor(self, repo):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   173
        """Is the cache content valid regarding a repo
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   174
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   175
        - False when cached tipnode is unknown or if we detect a strip.
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   176
        - True when cache is up to date or a subset of current repo."""
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   177
        valid = super(_topiccache, self).validfor(repo)
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   178
        if not valid:
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   179
            return False
3518
d938808e31bc serverminitopic: attempt to fix assertion for repoview in branchmap
Sean Farley <sean@farley.io>
parents: 3511
diff changeset
   180
        elif self.phaseshash is None:
3206
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   181
            # phasehash at None means this is a branchmap
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   182
            # coming from a public only set
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   183
            return True
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   184
        else:
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   185
            try:
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   186
                valid = self.phaseshash == _phaseshash(repo, self.tiprev)
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   187
                return valid
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   188
            except IndexError:
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   189
                return False
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   190
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   191
    def write(self, repo):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   192
        # we expect (hope) mutable set to be small enough to be that computing
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   193
        # it all the time will be fast enough
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   194
        if not mighttopic(repo):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   195
            super(_topiccache, self).write(repo)
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   196
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   197
    def update(self, repo, revgen):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   198
        """Given a branchhead cache, self, that may have extra nodes or be
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   199
        missing heads, and a generator of nodes that are strictly a superset of
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   200
        heads missing, this function updates self to be correct.
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   201
        """
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   202
        super(_topiccache, self).update(repo, revgen)
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   203
        if mighttopic(repo):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   204
            self.phaseshash = _phaseshash(repo, self.tiprev)
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   205
3207
35c79686a635 serverminitopic: also avoid reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3206
diff changeset
   206
def wrapread(orig, repo):
35c79686a635 serverminitopic: also avoid reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3206
diff changeset
   207
    # Avoiding to write cache for filter where topic applies is a good step,
35c79686a635 serverminitopic: also avoid reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3206
diff changeset
   208
    # but we need to also avoid reading it. Existing branchmap cache might
35c79686a635 serverminitopic: also avoid reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3206
diff changeset
   209
    # exists before the turned the feature on.
35c79686a635 serverminitopic: also avoid reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3206
diff changeset
   210
    if mighttopic(repo):
35c79686a635 serverminitopic: also avoid reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3206
diff changeset
   211
        return None
35c79686a635 serverminitopic: also avoid reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3206
diff changeset
   212
    return orig(repo)
35c79686a635 serverminitopic: also avoid reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3206
diff changeset
   213
3206
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   214
# advertise topic capabilities
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   215
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   216
def wireprotocaps(orig, repo, proto):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   217
    caps = orig(repo, proto)
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   218
    if hasminitopic(repo):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   219
        caps.append('topics')
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   220
    return caps
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   221
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   222
# wrap the necessary bit
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   223
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   224
def wrapclass(container, oldname, new):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   225
    old = getattr(container, oldname)
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   226
    if not issubclass(old, new):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   227
        targetclass = new
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   228
        # check if someone else already wrapped the class and handle that
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   229
        if not issubclass(new, old):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   230
            class targetclass(new, old):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   231
                pass
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   232
        setattr(container, oldname, targetclass)
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   233
    current = getattr(container, oldname)
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   234
    assert issubclass(current, new), (current, new, targetclass)
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   235
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   236
def uisetup(ui):
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   237
    wrapclass(branchmap, 'branchcache', _topiccache)
4394
c6d1b0a6babe topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents: 4364
diff changeset
   238
    try:
c6d1b0a6babe topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents: 4364
diff changeset
   239
        # Mercurial 4.8 and older
c6d1b0a6babe topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents: 4364
diff changeset
   240
        extensions.wrapfunction(branchmap, 'read', wrapread)
c6d1b0a6babe topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents: 4364
diff changeset
   241
    except AttributeError:
c6d1b0a6babe topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents: 4364
diff changeset
   242
        # Mercurial 4.9; branchcache.fromfile now takes care of this
c6d1b0a6babe topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents: 4364
diff changeset
   243
        # which is alredy defined on _topiccache
c6d1b0a6babe topic: make topics compatible with branchmap refactor
Martijn Pieters <mj@octobus.net>
parents: 4364
diff changeset
   244
        pass
3206
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   245
    extensions.wrapfunction(wireproto, '_capabilities', wireprotocaps)
3651
fa15068a9945 serverminitopic: wrap context.changectx.branch instead of context.changectx
Pulkit Goyal <7895pulkit@gmail.com>
parents: 3518
diff changeset
   246
    extensions.wrapfunction(context.changectx, 'branch', topicbranch)