hgext3rd/serverminitopic.py
author Sushil khanchi <sushilkhanchi97@gmail.com>
Tue, 22 Jan 2019 18:40:10 +0530
changeset 4385 34322fb3afca
parent 4364 b74a31c69ad5
child 4394 c6d1b0a6babe
permissions -rw-r--r--
evolve: add test for the case where public divergence on difference parents This test make sure that public divergence resolution also handle the case when divergentes changeset does not share the same parent at one end because one end simply rebase. The other side has actual an actual diff change. For now this would work only for the case when we need to relocate the mutable one. Other case is still left to work on.
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
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   149
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   150
    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
   151
        # 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
   152
        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
   153
            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
   154
        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
   155
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   156
    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
   157
        """return an deep copy of the branchcache object"""
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   158
        new = self.__class__(self, self.tipnode, self.tiprev, self.filteredhash,
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   159
                             self._closednodes)
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   160
        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
   161
        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
   162
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   163
    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
   164
        """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
   165
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   166
        - 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
   167
        - 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
   168
        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
   169
        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
   170
            return False
3518
d938808e31bc serverminitopic: attempt to fix assertion for repoview in branchmap
Sean Farley <sean@farley.io>
parents: 3511
diff changeset
   171
        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
   172
            # 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
   173
            # 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
   174
            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
   175
        else:
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   176
            try:
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 = 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
   178
                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
   179
            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
   180
                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
   181
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   182
    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
   183
        # 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
   184
        # 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
   185
        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
   186
            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
   187
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   188
    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
   189
        """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
   190
        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
   191
        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
   192
        """
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   193
        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
   194
        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
   195
            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
   196
3207
35c79686a635 serverminitopic: also avoid reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3206
diff changeset
   197
def wrapread(orig, repo):
35c79686a635 serverminitopic: also avoid reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3206
diff changeset
   198
    # 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
   199
    # 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
   200
    # exists before the turned the feature on.
35c79686a635 serverminitopic: also avoid reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3206
diff changeset
   201
    if mighttopic(repo):
35c79686a635 serverminitopic: also avoid reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3206
diff changeset
   202
        return None
35c79686a635 serverminitopic: also avoid reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3206
diff changeset
   203
    return orig(repo)
35c79686a635 serverminitopic: also avoid reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3206
diff changeset
   204
3206
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   205
# 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
   206
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   207
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
   208
    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
   209
    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
   210
        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
   211
    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
   212
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   213
# 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
   214
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   215
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
   216
    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
   217
    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
   218
        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
   219
        # 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
   220
        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
   221
            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
   222
                pass
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   223
        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
   224
    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
   225
    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
   226
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   227
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
   228
    wrapclass(branchmap, 'branchcache', _topiccache)
3207
35c79686a635 serverminitopic: also avoid reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 3206
diff changeset
   229
    extensions.wrapfunction(branchmap, 'read', wrapread)
3206
3ccde4699cf0 topic: introduce a minimal extensions to enable topic on the server
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
   230
    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
   231
    extensions.wrapfunction(context.changectx, 'branch', topicbranch)