hgext/narrow/narrowwirepeer.py
author Kyle Lippincott <spectral@google.com>
Wed, 31 Mar 2021 12:46:54 -0700
changeset 46872 8bca353b1ebc
parent 45942 89a2afe31e82
child 48875 6000f5b25c9b
child 49241 6b10151b9621
permissions -rw-r--r--
match: convert O(n) to O(log n) in exactmatcher.visitchildrenset When using narrow, during rebase this is called (at least) once per directory in the set of files in the commit being rebased. Every time it's called, we did the set arithmetic (now extracted and cached), which was probably pretty cheap but not necessary to repeat each time, looped over every item in the matcher and kept things that started with the directory we were querying. With very large narrowspecs, and a commit that touched a file in a large number of directories, this was slow. In a pathological repo, the rebase of a single commit (that touched over 17k files, I believe in approximately as many directories) with a narrowspec that had >32k entries took 8,246s of profiled time, with 5,007s of that spent in visitchildrenset (transitively). With this change, the time spent in visitchildrenset is less than 34s (which is where my profile cut off). Most of the remaining time was network access due to our custom remotefilelog-based setup not properly prefetching. Differential Revision: https://phab.mercurial-scm.org/D10294
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
     1
# narrowwirepeer.py - passes narrow spec with unbundle command
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
     2
#
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
     3
# Copyright 2017 Google, Inc.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
     4
#
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
     7
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
     8
from __future__ import absolute_import
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
     9
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    10
from mercurial import (
40070
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    11
    bundle2,
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    12
    error,
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    13
    extensions,
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    14
    hg,
40070
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    15
    narrowspec,
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    16
    wireprototypes,
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    17
    wireprotov1peer,
39523
c90514043eaa narrow: add narrow and ellipses as server capabilities
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 36351
diff changeset
    18
    wireprotov1server,
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    19
)
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    20
42415
c767e655ffda narrow: use narrow_widen wireproto command to widen in case of ellipses
Pulkit Goyal <7895pulkit@gmail.com>
parents: 40344
diff changeset
    21
from . import narrowbundle2
c767e655ffda narrow: use narrow_widen wireproto command to widen in case of ellipses
Pulkit Goyal <7895pulkit@gmail.com>
parents: 40344
diff changeset
    22
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
    23
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    24
def uisetup():
40070
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    25
    wireprotov1peer.wirepeer.narrow_widen = peernarrowwiden
39523
c90514043eaa narrow: add narrow and ellipses as server capabilities
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 36351
diff changeset
    26
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
    27
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    28
def reposetup(repo):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    29
    def wirereposetup(ui, peer):
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    30
        def wrapped(orig, cmd, *args, **kwargs):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    31
            if cmd == b'unbundle':
36102
b60c577b6e03 narrowwirepeer: add TODO about how we add wireproto args to unbundle :(
Augie Fackler <augie@google.com>
parents: 36101
diff changeset
    32
                # TODO: don't blindly add include/exclude wireproto
b60c577b6e03 narrowwirepeer: add TODO about how we add wireproto args to unbundle :(
Augie Fackler <augie@google.com>
parents: 36101
diff changeset
    33
                # arguments to unbundle.
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    34
                include, exclude = repo.narrowpats
43503
313e3a279828 cleanup: remove pointless r-prefixes on double-quoted strings
Augie Fackler <augie@google.com>
parents: 43249
diff changeset
    35
                kwargs["includepats"] = b','.join(include)
313e3a279828 cleanup: remove pointless r-prefixes on double-quoted strings
Augie Fackler <augie@google.com>
parents: 43249
diff changeset
    36
                kwargs["excludepats"] = b','.join(exclude)
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    37
            return orig(cmd, *args, **kwargs)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
    38
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    39
        extensions.wrapfunction(peer, b'_calltwowaystream', wrapped)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
    40
36079
a2a6e724d61a narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff changeset
    41
    hg.wirepeersetupfuncs.append(wirereposetup)
40070
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    42
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
    43
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
    44
@wireprotov1server.wireprotocommand(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    45
    b'narrow_widen',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    46
    b'oldincludes oldexcludes'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    47
    b' newincludes newexcludes'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    48
    b' commonheads cgversion'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    49
    b' known ellipses',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    50
    permission=b'pull',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
    51
)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
    52
def narrow_widen(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
    53
    repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
    54
    proto,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
    55
    oldincludes,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
    56
    oldexcludes,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
    57
    newincludes,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
    58
    newexcludes,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
    59
    commonheads,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
    60
    cgversion,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
    61
    known,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
    62
    ellipses,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
    63
):
40070
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    64
    """wireprotocol command to send data when a narrow clone is widen. We will
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    65
    be sending a changegroup here.
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    66
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    67
    The current set of arguments which are required:
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    68
    oldincludes: the old includes of the narrow copy
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    69
    oldexcludes: the old excludes of the narrow copy
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    70
    newincludes: the new includes of the narrow copy
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    71
    newexcludes: the new excludes of the narrow copy
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    72
    commonheads: list of heads which are common between the server and client
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    73
    cgversion(maybe): the changegroup version to produce
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    74
    known: list of nodes which are known on the client (used in ellipses cases)
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    75
    ellipses: whether to send ellipses data or not
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    76
    """
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    77
40148
74558635dad5 narrow: don't compress the bundle2 when sending 'error:abort'
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40075
diff changeset
    78
    preferuncompressed = False
40070
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    79
    try:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
    80
42944
c2676b5a9f59 narrow: don't hexify paths and double-hexify known nodes on wire (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents: 42417
diff changeset
    81
        def splitpaths(data):
c2676b5a9f59 narrow: don't hexify paths and double-hexify known nodes on wire (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents: 42417
diff changeset
    82
            # work around ''.split(',') => ['']
c2676b5a9f59 narrow: don't hexify paths and double-hexify known nodes on wire (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents: 42417
diff changeset
    83
            return data.split(b',') if data else []
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
    84
42944
c2676b5a9f59 narrow: don't hexify paths and double-hexify known nodes on wire (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents: 42417
diff changeset
    85
        oldincludes = splitpaths(oldincludes)
c2676b5a9f59 narrow: don't hexify paths and double-hexify known nodes on wire (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents: 42417
diff changeset
    86
        newincludes = splitpaths(newincludes)
c2676b5a9f59 narrow: don't hexify paths and double-hexify known nodes on wire (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents: 42417
diff changeset
    87
        oldexcludes = splitpaths(oldexcludes)
c2676b5a9f59 narrow: don't hexify paths and double-hexify known nodes on wire (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents: 42417
diff changeset
    88
        newexcludes = splitpaths(newexcludes)
40070
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    89
        # validate the patterns
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    90
        narrowspec.validatepatterns(set(oldincludes))
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    91
        narrowspec.validatepatterns(set(newincludes))
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    92
        narrowspec.validatepatterns(set(oldexcludes))
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    93
        narrowspec.validatepatterns(set(newexcludes))
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    94
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    95
        common = wireprototypes.decodelist(commonheads)
42415
c767e655ffda narrow: use narrow_widen wireproto command to widen in case of ellipses
Pulkit Goyal <7895pulkit@gmail.com>
parents: 40344
diff changeset
    96
        known = wireprototypes.decodelist(known)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    97
        if ellipses == b'0':
40070
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    98
            ellipses = False
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
    99
        else:
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
   100
            ellipses = bool(ellipses)
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
   101
        cgversion = cgversion
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
   102
42417
a97b12f726e4 narrow: pass the bundle to bundle2.widen_bundle() instead of generating there
Pulkit Goyal <7895pulkit@gmail.com>
parents: 42415
diff changeset
   103
        bundler = bundle2.bundle20(repo.ui)
43249
63d440bef72a widening: pass in matchers instead of patterns
Martin von Zweigbergk <martinvonz@google.com>
parents: 43247
diff changeset
   104
        newmatch = narrowspec.match(
63d440bef72a widening: pass in matchers instead of patterns
Martin von Zweigbergk <martinvonz@google.com>
parents: 43247
diff changeset
   105
            repo.root, include=newincludes, exclude=newexcludes
63d440bef72a widening: pass in matchers instead of patterns
Martin von Zweigbergk <martinvonz@google.com>
parents: 43247
diff changeset
   106
        )
63d440bef72a widening: pass in matchers instead of patterns
Martin von Zweigbergk <martinvonz@google.com>
parents: 43247
diff changeset
   107
        oldmatch = narrowspec.match(
63d440bef72a widening: pass in matchers instead of patterns
Martin von Zweigbergk <martinvonz@google.com>
parents: 43247
diff changeset
   108
            repo.root, include=oldincludes, exclude=oldexcludes
63d440bef72a widening: pass in matchers instead of patterns
Martin von Zweigbergk <martinvonz@google.com>
parents: 43247
diff changeset
   109
        )
42415
c767e655ffda narrow: use narrow_widen wireproto command to widen in case of ellipses
Pulkit Goyal <7895pulkit@gmail.com>
parents: 40344
diff changeset
   110
        if not ellipses:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
   111
            bundle2.widen_bundle(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
   112
                bundler,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
   113
                repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
   114
                oldmatch,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
   115
                newmatch,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
   116
                common,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
   117
                known,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
   118
                cgversion,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
   119
                ellipses,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
   120
            )
42415
c767e655ffda narrow: use narrow_widen wireproto command to widen in case of ellipses
Pulkit Goyal <7895pulkit@gmail.com>
parents: 40344
diff changeset
   121
        else:
43242
561f9bc4b4c5 widening: duplicate generateellipsesbundle2() for widening
Martin von Zweigbergk <martinvonz@google.com>
parents: 43077
diff changeset
   122
            narrowbundle2.generate_ellipses_bundle2_for_widening(
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
   123
                bundler,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
   124
                repo,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
   125
                oldmatch,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
   126
                newmatch,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
   127
                cgversion,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
   128
                common,
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45682
diff changeset
   129
                known,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
   130
            )
40070
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
   131
    except error.Abort as exc:
40071
e8132a8897da narrow: start returning bundle2 from widen_bundle()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40070
diff changeset
   132
        bundler = bundle2.bundle20(repo.ui)
45682
d2e1dcd4490d errors: name arguments to Abort constructor
Martin von Zweigbergk <martinvonz@google.com>
parents: 43506
diff changeset
   133
        manargs = [(b'message', exc.message)]
40070
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
   134
        advargs = []
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
   135
        if exc.hint is not None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   136
            advargs.append((b'hint', exc.hint))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   137
        bundler.addpart(bundle2.bundlepart(b'error:abort', manargs, advargs))
40148
74558635dad5 narrow: don't compress the bundle2 when sending 'error:abort'
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 40075
diff changeset
   138
        preferuncompressed = True
40070
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
   139
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
   140
    chunks = bundler.getchunks()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
   141
    return wireprototypes.streamres(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
   142
        gen=chunks, prefer_uncompressed=preferuncompressed
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
   143
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42944
diff changeset
   144
40070
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
   145
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
   146
def peernarrowwiden(remote, **kwargs):
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43503
diff changeset
   147
    for ch in ('commonheads', 'known'):
40070
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
   148
        kwargs[ch] = wireprototypes.encodelist(kwargs[ch])
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
   149
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43503
diff changeset
   150
    for ch in ('oldincludes', 'newincludes', 'oldexcludes', 'newexcludes'):
42944
c2676b5a9f59 narrow: don't hexify paths and double-hexify known nodes on wire (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents: 42417
diff changeset
   151
        kwargs[ch] = b','.join(kwargs[ch])
c2676b5a9f59 narrow: don't hexify paths and double-hexify known nodes on wire (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents: 42417
diff changeset
   152
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43503
diff changeset
   153
    kwargs['ellipses'] = b'%i' % bool(kwargs['ellipses'])
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   154
    f = remote._callcompressable(b'narrow_widen', **kwargs)
40070
8feae5b989bc narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 39934
diff changeset
   155
    return bundle2.getunbundler(remote.ui, f)