hgext/simple4server.py
author Pierre-Yves David <pierre-yves.david@fb.com>
Thu, 07 May 2015 10:54:37 -0700
branchstable
changeset 1329 344774ef5a05
parent 1328 9321889d119a
child 1331 5e82d78f5872
permissions -rw-r--r--
simple4server: remove buggy wrapping of pull related function Not only the wrapping was all buggy, but simple4server is not supposed to affect client side pull.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
660
e6e47c432ffd hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     1
'''enable experimental obsolescence feature of Mercurial
e6e47c432ffd hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     2
e6e47c432ffd hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     3
OBSOLESCENCE IS AN EXPERIMENTAL FEATURE MAKE SURE YOU UNDERSTOOD THE INVOLVED
e6e47c432ffd hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     4
CONCEPT BEFORE USING IT.
e6e47c432ffd hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     5
e6e47c432ffd hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     6
/!\ THIS EXTENSION IS INTENDED FOR SERVER SIDE ONLY USAGE /!\
e6e47c432ffd hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     7
e6e47c432ffd hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     8
For client side usages it is recommended to use the evolve extension for
e6e47c432ffd hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     9
improved user interface.'''
e6e47c432ffd hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    10
1257
c52c15100fb2 prepare version 5.1.3
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1253
diff changeset
    11
testedwith = '3.3.3 3.4-rc'
1328
9321889d119a simple4server: update bugtracker link
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1257
diff changeset
    12
buglink = 'http://bz.selenic.com/'
873
c758717ff3c7 evolve: add 2.9.1 compatibility seal to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 872
diff changeset
    13
660
e6e47c432ffd hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    14
import mercurial.obsolete
e6e47c432ffd hgext: add a simpler extension to enable obsolete on server
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    15
mercurial.obsolete._enabled = True
822
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    16
852
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
    17
import struct
872
2a2db401a55b simple4server: fix a missing import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 869
diff changeset
    18
from mercurial import util
822
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    19
from mercurial import wireproto
852
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
    20
from mercurial import extensions
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
    21
from mercurial import obsolete
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
    22
from cStringIO import StringIO
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
    23
from mercurial import node
869
e9eeef0d07ec exchange: enforce permission on new wireprotocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 866
diff changeset
    24
from mercurial.hgweb import hgweb_mod
963
f80e8e3c3726 simple4server: backport the bundle2 exchange
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 888
diff changeset
    25
from mercurial import bundle2
f80e8e3c3726 simple4server: backport the bundle2 exchange
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 888
diff changeset
    26
from mercurial import localrepo
f80e8e3c3726 simple4server: backport the bundle2 exchange
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 888
diff changeset
    27
from mercurial import exchange
1245
580a8f5ea462 discovery: port the new hashing version to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1097
diff changeset
    28
from mercurial import node
852
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
    29
_pack = struct.pack
822
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    30
963
f80e8e3c3726 simple4server: backport the bundle2 exchange
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 888
diff changeset
    31
gboptslist = gboptsmap = None
f80e8e3c3726 simple4server: backport the bundle2 exchange
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 888
diff changeset
    32
try:
f80e8e3c3726 simple4server: backport the bundle2 exchange
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 888
diff changeset
    33
    from mercurial import obsolete
f80e8e3c3726 simple4server: backport the bundle2 exchange
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 888
diff changeset
    34
    if not obsolete._enabled:
f80e8e3c3726 simple4server: backport the bundle2 exchange
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 888
diff changeset
    35
        obsolete._enabled = True
f80e8e3c3726 simple4server: backport the bundle2 exchange
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 888
diff changeset
    36
    from mercurial import wireproto
f80e8e3c3726 simple4server: backport the bundle2 exchange
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 888
diff changeset
    37
    gboptslist = getattr(wireproto, 'gboptslist', None)
f80e8e3c3726 simple4server: backport the bundle2 exchange
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 888
diff changeset
    38
    gboptsmap = getattr(wireproto, 'gboptsmap', None)
f80e8e3c3726 simple4server: backport the bundle2 exchange
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 888
diff changeset
    39
except (ImportError, AttributeError):
f80e8e3c3726 simple4server: backport the bundle2 exchange
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 888
diff changeset
    40
    raise util.Abort('Your Mercurial is too old for this version of Evolve\n'
f80e8e3c3726 simple4server: backport the bundle2 exchange
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 888
diff changeset
    41
                     'requires version 3.0.1 or above')
f80e8e3c3726 simple4server: backport the bundle2 exchange
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 888
diff changeset
    42
882
48804a8d7472 simple4server: option to advertise obsolescence support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 878
diff changeset
    43
# Start of simple4server specific content
48804a8d7472 simple4server: option to advertise obsolescence support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 878
diff changeset
    44
48804a8d7472 simple4server: option to advertise obsolescence support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 878
diff changeset
    45
from mercurial import pushkey
48804a8d7472 simple4server: option to advertise obsolescence support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 878
diff changeset
    46
48804a8d7472 simple4server: option to advertise obsolescence support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 878
diff changeset
    47
# specific content also include the wrapping int extsetup
48804a8d7472 simple4server: option to advertise obsolescence support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 878
diff changeset
    48
def _nslist(orig, repo):
48804a8d7472 simple4server: option to advertise obsolescence support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 878
diff changeset
    49
    rep = orig(repo)
48804a8d7472 simple4server: option to advertise obsolescence support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 878
diff changeset
    50
    if not repo.ui.configbool('__temporary__', 'advertiseobsolete', True):
48804a8d7472 simple4server: option to advertise obsolescence support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 878
diff changeset
    51
        rep.pop('obsolete')
48804a8d7472 simple4server: option to advertise obsolescence support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 878
diff changeset
    52
    return rep
48804a8d7472 simple4server: option to advertise obsolescence support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 878
diff changeset
    53
48804a8d7472 simple4server: option to advertise obsolescence support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 878
diff changeset
    54
# End of simple4server specific content
48804a8d7472 simple4server: option to advertise obsolescence support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 878
diff changeset
    55
48804a8d7472 simple4server: option to advertise obsolescence support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 878
diff changeset
    56
48804a8d7472 simple4server: option to advertise obsolescence support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 878
diff changeset
    57
874
19a7ed6384a9 simple4server: add origin and documentation to most function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 873
diff changeset
    58
# from evolve extension: 1a23c7c52a43
822
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    59
def srv_pushobsmarkers(repo, proto):
874
19a7ed6384a9 simple4server: add origin and documentation to most function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 873
diff changeset
    60
    """That receives a stream of markers and apply then to the repo"""
822
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    61
    fp = StringIO()
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    62
    proto.redirect()
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    63
    proto.getfile(fp)
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    64
    data = fp.getvalue()
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    65
    fp.close()
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    66
    lock = repo.lock()
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    67
    try:
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    68
        tr = repo.transaction('pushkey: obsolete markers')
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    69
        try:
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    70
            repo.obsstore.mergemarkers(tr, data)
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    71
            tr.close()
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    72
        finally:
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    73
            tr.release()
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    74
    finally:
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    75
        lock.release()
888
097ddcb0da25 evolve: add a hook related to the new pushobsmarkers command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 884
diff changeset
    76
    repo.hook('evolve_pushobsmarkers')
822
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    77
    return wireproto.pushres(0)
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
    78
874
19a7ed6384a9 simple4server: add origin and documentation to most function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 873
diff changeset
    79
# from evolve extension: 1a23c7c52a43
852
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
    80
def _getobsmarkersstream(repo, heads=None, common=None):
874
19a7ed6384a9 simple4server: add origin and documentation to most function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 873
diff changeset
    81
    """Get a binary stream for all markers relevant to `::<heads> - ::<common>`
19a7ed6384a9 simple4server: add origin and documentation to most function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 873
diff changeset
    82
    """
852
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
    83
    revset = ''
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
    84
    args = []
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
    85
    repo = repo.unfiltered()
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
    86
    if heads is None:
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
    87
        revset = 'all()'
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
    88
    elif heads:
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
    89
        revset += "(::%ln)"
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
    90
        args.append(heads)
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
    91
    else:
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
    92
        assert False, 'pulling no heads?'
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
    93
    if common:
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
    94
        revset += ' - (::%ln)'
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
    95
        args.append(common)
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
    96
    nodes = [c.node() for c in repo.set(revset, *args)]
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
    97
    markers = repo.obsstore.relevantmarkers(nodes)
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
    98
    obsdata = StringIO()
1091
236a8e81551e compat: use in-core encodemarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1090
diff changeset
    99
    for chunk in obsolete.encodemarkers(markers, True):
236a8e81551e compat: use in-core encodemarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1090
diff changeset
   100
        obsdata.write(chunk)
852
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
   101
    obsdata.seek(0)
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
   102
    return obsdata
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
   103
1067
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   104
if not util.safehasattr(obsolete.obsstore, 'relevantmarkers'):
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   105
    # from evolve extension: 1a23c7c52a43
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   106
    class pruneobsstore(obsolete.obsstore):
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   107
        """And extended obsstore class that read parent information from v1 format
874
19a7ed6384a9 simple4server: add origin and documentation to most function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 873
diff changeset
   108
1067
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   109
        Evolve extension adds parent information in prune marker. We use it to make
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   110
        markers relevant to pushed changeset."""
852
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
   111
1067
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   112
        def __init__(self, *args, **kwargs):
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   113
            self.prunedchildren = {}
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   114
            return super(pruneobsstore, self).__init__(*args, **kwargs)
852
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
   115
1067
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   116
        def _load(self, markers):
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   117
            markers = self._prunedetectingmarkers(markers)
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   118
            return super(pruneobsstore, self)._load(markers)
852
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
   119
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
   120
1067
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   121
        def _prunedetectingmarkers(self, markers):
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   122
            for m in markers:
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   123
                if not m[1]: # no successors
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   124
                    meta = obsolete.decodemeta(m[3])
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   125
                    if 'p1' in meta:
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   126
                        p1 = node.bin(meta['p1'])
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   127
                        self.prunedchildren.setdefault(p1, set()).add(m)
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   128
                    if 'p2' in meta:
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   129
                        p2 = node.bin(meta['p2'])
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   130
                        self.prunedchildren.setdefault(p2, set()).add(m)
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   131
                yield m
852
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
   132
1067
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   133
    # from evolve extension: 1a23c7c52a43
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   134
    def relevantmarkers(self, nodes):
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   135
        """return a set of all obsolescence marker relevant to a set of node.
852
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
   136
1067
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   137
        "relevant" to a set of node mean:
852
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
   138
1067
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   139
        - marker that use this changeset as successors
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   140
        - prune marker of direct children on this changeset.
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   141
        - recursive application of the two rules on precursors of these markers
852
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
   142
1067
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   143
        It is a set so you cannot rely on order"""
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   144
        seennodes = set(nodes)
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   145
        seenmarkers = set()
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   146
        pendingnodes = set(nodes)
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   147
        precursorsmarkers = self.precursors
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   148
        prunedchildren = self.prunedchildren
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   149
        while pendingnodes:
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   150
            direct = set()
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   151
            for current in pendingnodes:
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   152
                direct.update(precursorsmarkers.get(current, ()))
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   153
                direct.update(prunedchildren.get(current, ()))
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   154
            direct -= seenmarkers
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   155
            pendingnodes = set([m[0] for m in direct])
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   156
            seenmarkers |= direct
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   157
            pendingnodes -= seennodes
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   158
            seennodes |= pendingnodes
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   159
        return seenmarkers
852
aa722de36179 exchange: fix pulling from simple for server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 826
diff changeset
   160
878
5cb2744a6d36 simple4server: update "from <changeset>" statement
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 877
diff changeset
   161
# from evolve extension: cf35f38d6a10
826
bee5e1105e6c exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 822
diff changeset
   162
def srv_pullobsmarkers(repo, proto, others):
874
19a7ed6384a9 simple4server: add origin and documentation to most function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 873
diff changeset
   163
    """serves a binary stream of markers.
19a7ed6384a9 simple4server: add origin and documentation to most function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 873
diff changeset
   164
19a7ed6384a9 simple4server: add origin and documentation to most function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 873
diff changeset
   165
    Serves relevant to changeset between heads and common. The stream is prefix
19a7ed6384a9 simple4server: add origin and documentation to most function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 873
diff changeset
   166
    by a -string- representation of an integer. This integer is the size of the
19a7ed6384a9 simple4server: add origin and documentation to most function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 873
diff changeset
   167
    stream."""
826
bee5e1105e6c exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 822
diff changeset
   168
    opts = wireproto.options('', ['heads', 'common'], others)
bee5e1105e6c exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 822
diff changeset
   169
    for k, v in opts.iteritems():
bee5e1105e6c exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 822
diff changeset
   170
        if k in ('heads', 'common'):
bee5e1105e6c exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 822
diff changeset
   171
            opts[k] = wireproto.decodelist(v)
bee5e1105e6c exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 822
diff changeset
   172
    obsdata = _getobsmarkersstream(repo, **opts)
877
cf35f38d6a10 exchange: fix changeset pulling over http
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 876
diff changeset
   173
    finaldata = StringIO()
cf35f38d6a10 exchange: fix changeset pulling over http
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 876
diff changeset
   174
    obsdata = obsdata.getvalue()
cf35f38d6a10 exchange: fix changeset pulling over http
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 876
diff changeset
   175
    finaldata.write('%20i' % len(obsdata))
cf35f38d6a10 exchange: fix changeset pulling over http
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 876
diff changeset
   176
    finaldata.write(obsdata)
cf35f38d6a10 exchange: fix changeset pulling over http
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 876
diff changeset
   177
    finaldata.seek(0)
cf35f38d6a10 exchange: fix changeset pulling over http
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 876
diff changeset
   178
    return wireproto.streamres(proto.groupchunks(finaldata))
826
bee5e1105e6c exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 822
diff changeset
   179
866
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   180
1246
c7db753ca300 #iforgottoamendagain
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1245
diff changeset
   181
# from evolve extension: 3249814dabd1
1245
580a8f5ea462 discovery: port the new hashing version to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1097
diff changeset
   182
def _obsrelsethashtreefm0(repo):
580a8f5ea462 discovery: port the new hashing version to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1097
diff changeset
   183
    return _obsrelsethashtree(repo, obsolete._fm0encodeonemarker)
874
19a7ed6384a9 simple4server: add origin and documentation to most function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 873
diff changeset
   184
1246
c7db753ca300 #iforgottoamendagain
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1245
diff changeset
   185
# from evolve extension: 3249814dabd1
1245
580a8f5ea462 discovery: port the new hashing version to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1097
diff changeset
   186
def _obsrelsethashtreefm1(repo):
580a8f5ea462 discovery: port the new hashing version to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1097
diff changeset
   187
    return _obsrelsethashtree(repo, obsolete._fm1encodeonemarker)
580a8f5ea462 discovery: port the new hashing version to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1097
diff changeset
   188
1246
c7db753ca300 #iforgottoamendagain
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1245
diff changeset
   189
# from evolve extension: 3249814dabd1
1245
580a8f5ea462 discovery: port the new hashing version to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1097
diff changeset
   190
def _obsrelsethashtree(repo, encodeonemarker):
866
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   191
    cache = []
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   192
    unfi = repo.unfiltered()
1245
580a8f5ea462 discovery: port the new hashing version to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1097
diff changeset
   193
    markercache = {}
866
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   194
    for i in unfi:
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   195
        ctx = unfi[i]
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   196
        entry = 0
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   197
        sha = util.sha1()
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   198
        # add data from p1
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   199
        for p in ctx.parents():
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   200
            p = p.rev()
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   201
            if p < 0:
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   202
                p = node.nullid
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   203
            else:
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   204
                p = cache[p][1]
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   205
            if p != node.nullid:
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   206
                entry += 1
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   207
                sha.update(p)
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   208
        tmarkers = repo.obsstore.relevantmarkers([ctx.node()])
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   209
        if tmarkers:
1245
580a8f5ea462 discovery: port the new hashing version to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1097
diff changeset
   210
            bmarkers = []
580a8f5ea462 discovery: port the new hashing version to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1097
diff changeset
   211
            for m in tmarkers:
580a8f5ea462 discovery: port the new hashing version to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1097
diff changeset
   212
                if not m in markercache:
580a8f5ea462 discovery: port the new hashing version to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1097
diff changeset
   213
                    markercache[m] = encodeonemarker(m)
580a8f5ea462 discovery: port the new hashing version to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1097
diff changeset
   214
                bmarkers.append(markercache[m])
866
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   215
            bmarkers.sort()
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   216
            for m in bmarkers:
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   217
                entry += 1
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   218
                sha.update(m)
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   219
        if entry:
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   220
            cache.append((ctx.node(), sha.digest()))
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   221
        else:
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   222
            cache.append((ctx.node(), node.nullid))
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   223
    return cache
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   224
1246
c7db753ca300 #iforgottoamendagain
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1245
diff changeset
   225
# from evolve extension: 3249814dabd1
1245
580a8f5ea462 discovery: port the new hashing version to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1097
diff changeset
   226
def _obshash(repo, nodes, version=0):
580a8f5ea462 discovery: port the new hashing version to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1097
diff changeset
   227
    if version == 0:
580a8f5ea462 discovery: port the new hashing version to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1097
diff changeset
   228
        hashs = _obsrelsethashtreefm0(repo)
580a8f5ea462 discovery: port the new hashing version to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1097
diff changeset
   229
    elif version ==1:
580a8f5ea462 discovery: port the new hashing version to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1097
diff changeset
   230
        hashs = _obsrelsethashtreefm1(repo)
580a8f5ea462 discovery: port the new hashing version to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1097
diff changeset
   231
    else:
580a8f5ea462 discovery: port the new hashing version to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1097
diff changeset
   232
        assert False
866
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   233
    nm = repo.changelog.nodemap
1073
f15f02007a0b obshash: resist to unknown revision during discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1067
diff changeset
   234
    revs = [nm.get(n) for n in nodes]
f15f02007a0b obshash: resist to unknown revision during discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1067
diff changeset
   235
    return [r is None and node.nullid or hashs[r][1] for r in revs]
866
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   236
1246
c7db753ca300 #iforgottoamendagain
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1245
diff changeset
   237
# from evolve extension: 3249814dabd1
866
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   238
def srv_obshash(repo, proto, nodes):
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   239
    return wireproto.encodelist(_obshash(repo, wireproto.decodelist(nodes)))
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   240
1246
c7db753ca300 #iforgottoamendagain
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1245
diff changeset
   241
# from evolve extension: 3249814dabd1
1245
580a8f5ea462 discovery: port the new hashing version to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1097
diff changeset
   242
def srv_obshash1(repo, proto, nodes):
580a8f5ea462 discovery: port the new hashing version to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1097
diff changeset
   243
    return wireproto.encodelist(_obshash(repo, wireproto.decodelist(nodes), version=1))
580a8f5ea462 discovery: port the new hashing version to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1097
diff changeset
   244
1246
c7db753ca300 #iforgottoamendagain
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1245
diff changeset
   245
# from evolve extension: 3249814dabd1
822
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
   246
def capabilities(orig, repo, proto):
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
   247
    """wrapper to advertise new capability"""
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
   248
    caps = orig(repo, proto)
884
4ae115cf3efd sinmple4server: advertise new cap only when advertising obsolescence
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 882
diff changeset
   249
    advertise = repo.ui.configbool('__temporary__', 'advertiseobsolete', True)
4ae115cf3efd sinmple4server: advertise new cap only when advertising obsolescence
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 882
diff changeset
   250
    if obsolete._enabled and advertise:
822
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
   251
        caps += ' _evoext_pushobsmarkers_0'
826
bee5e1105e6c exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 822
diff changeset
   252
        caps += ' _evoext_pullobsmarkers_0'
866
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   253
        caps += ' _evoext_obshash_0'
1245
580a8f5ea462 discovery: port the new hashing version to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1097
diff changeset
   254
        caps += ' _evoext_obshash_1'
1097
580a2d838996 pull: use discovery to pull less obsmarkers through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1091
diff changeset
   255
        caps += ' _evoext_getbundle_obscommon'
822
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
   256
    return caps
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
   257
1253
d03583da89c4 pull: fix bundle2 part generation
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1252
diff changeset
   258
def _getbundleobsmarkerpart(orig, bundler, repo, source, **kwargs):
1097
580a2d838996 pull: use discovery to pull less obsmarkers through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1091
diff changeset
   259
    if 'evo_obscommon' not in kwargs:
1253
d03583da89c4 pull: fix bundle2 part generation
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1252
diff changeset
   260
        return orig(bundler, repo, source, **kwargs)
d03583da89c4 pull: fix bundle2 part generation
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1252
diff changeset
   261
d03583da89c4 pull: fix bundle2 part generation
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1252
diff changeset
   262
    heads = kwargs.get('heads')
d03583da89c4 pull: fix bundle2 part generation
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1252
diff changeset
   263
    if 'evo_obscommon' not in kwargs:
d03583da89c4 pull: fix bundle2 part generation
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1252
diff changeset
   264
        return orig(bundler, repo, source, **kwargs)
1097
580a2d838996 pull: use discovery to pull less obsmarkers through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1091
diff changeset
   265
580a2d838996 pull: use discovery to pull less obsmarkers through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1091
diff changeset
   266
    if kwargs.get('obsmarkers', False):
580a2d838996 pull: use discovery to pull less obsmarkers through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1091
diff changeset
   267
        if heads is None:
580a2d838996 pull: use discovery to pull less obsmarkers through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1091
diff changeset
   268
            heads = repo.heads()
580a2d838996 pull: use discovery to pull less obsmarkers through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1091
diff changeset
   269
        obscommon = kwargs.get('evo_obscommon', ())
580a2d838996 pull: use discovery to pull less obsmarkers through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1091
diff changeset
   270
        obsset = repo.set('::%ln - ::%ln', heads, obscommon)
580a2d838996 pull: use discovery to pull less obsmarkers through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1091
diff changeset
   271
        subset = [c.node() for c in obsset]
580a2d838996 pull: use discovery to pull less obsmarkers through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1091
diff changeset
   272
        markers = repo.obsstore.relevantmarkers(subset)
580a2d838996 pull: use discovery to pull less obsmarkers through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1091
diff changeset
   273
        exchange.buildobsmarkerspart(bundler, markers)
963
f80e8e3c3726 simple4server: backport the bundle2 exchange
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 888
diff changeset
   274
876
8c9601a6c4e0 simple4server: update "from <changeset>" statement
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 875
diff changeset
   275
# from evolve extension: 10867a8e27c6
874
19a7ed6384a9 simple4server: add origin and documentation to most function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 873
diff changeset
   276
# heavily modified
822
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
   277
def extsetup(ui):
963
f80e8e3c3726 simple4server: backport the bundle2 exchange
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 888
diff changeset
   278
    localrepo.moderncaps.add('_evoext_b2x_obsmarkers_0')
1097
580a2d838996 pull: use discovery to pull less obsmarkers through bundle2
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1091
diff changeset
   279
    gboptsmap['evo_obscommon'] = 'nodes'
1067
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   280
    if not util.safehasattr(obsolete.obsstore, 'relevantmarkers'):
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   281
        obsolete.obsstore = pruneobsstore
5d063fed9e3d evolve: yield to relevant markers handling in core
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 963
diff changeset
   282
        obsolete.obsstore.relevantmarkers = relevantmarkers
869
e9eeef0d07ec exchange: enforce permission on new wireprotocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 866
diff changeset
   283
    hgweb_mod.perms['evoext_pushobsmarkers_0'] = 'push'
e9eeef0d07ec exchange: enforce permission on new wireprotocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 866
diff changeset
   284
    hgweb_mod.perms['evoext_pullobsmarkers_0'] = 'pull'
e9eeef0d07ec exchange: enforce permission on new wireprotocol command
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 866
diff changeset
   285
    hgweb_mod.perms['evoext_obshash'] = 'pull'
822
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
   286
    wireproto.commands['evoext_pushobsmarkers_0'] = (srv_pushobsmarkers, '')
826
bee5e1105e6c exchange: add the pullmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 822
diff changeset
   287
    wireproto.commands['evoext_pullobsmarkers_0'] = (srv_pullobsmarkers, '*')
875
10867a8e27c6 exchange: properly wrap wireprotocol capabilities
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 874
diff changeset
   288
    # wrap module content
1253
d03583da89c4 pull: fix bundle2 part generation
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1252
diff changeset
   289
    origfunc = exchange.getbundle2partsmapping['obsmarkers']
d03583da89c4 pull: fix bundle2 part generation
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1252
diff changeset
   290
    def newfunc(*args, **kwargs):
d03583da89c4 pull: fix bundle2 part generation
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1252
diff changeset
   291
        return _getbundleobsmarkerpart(origfunc, *args, **kwargs)
d03583da89c4 pull: fix bundle2 part generation
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1252
diff changeset
   292
    exchange.getbundle2partsmapping['obsmarkers'] = newfunc
822
5f5d269278e9 exchange: add the pushmarker wireproto command to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 660
diff changeset
   293
    extensions.wrapfunction(wireproto, 'capabilities', capabilities)
875
10867a8e27c6 exchange: properly wrap wireprotocol capabilities
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 874
diff changeset
   294
    # wrap command content
10867a8e27c6 exchange: properly wrap wireprotocol capabilities
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 874
diff changeset
   295
    oldcap, args = wireproto.commands['capabilities']
10867a8e27c6 exchange: properly wrap wireprotocol capabilities
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 874
diff changeset
   296
    def newcap(repo, proto):
10867a8e27c6 exchange: properly wrap wireprotocol capabilities
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 874
diff changeset
   297
        return capabilities(oldcap, repo, proto)
10867a8e27c6 exchange: properly wrap wireprotocol capabilities
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 874
diff changeset
   298
    wireproto.commands['capabilities'] = (newcap, args)
866
c6dc5822e640 simple4server: add the wireproto command for obsolescence markers discovery
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 852
diff changeset
   299
    wireproto.commands['evoext_obshash'] = (srv_obshash, 'nodes')
1245
580a8f5ea462 discovery: port the new hashing version to simple4server
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1097
diff changeset
   300
    wireproto.commands['evoext_obshash1'] = (srv_obshash1, 'nodes')
882
48804a8d7472 simple4server: option to advertise obsolescence support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 878
diff changeset
   301
    # specific simple4server content
48804a8d7472 simple4server: option to advertise obsolescence support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 878
diff changeset
   302
    extensions.wrapfunction(pushkey, '_nslist', _nslist)
48804a8d7472 simple4server: option to advertise obsolescence support
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 878
diff changeset
   303
    pushkey._namespaces['namespaces'] = (lambda *x: False, pushkey._nslist)
963
f80e8e3c3726 simple4server: backport the bundle2 exchange
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 888
diff changeset
   304