author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Sun, 07 Jan 2024 02:38:38 +0100 | |
changeset 51349 | cc806f20d756 |
parent 51309 | 9b44b25dece1 |
child 51863 | f4733654f144 |
permissions | -rw-r--r-- |
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 |
|
51309
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
9 |
from mercurial.i18n import _ |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
10 |
|
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
11 |
from mercurial.utils import stringutil |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
12 |
|
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
13 |
from mercurial import ( |
40070
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39934
diff
changeset
|
14 |
bundle2, |
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39934
diff
changeset
|
15 |
error, |
49241
6b10151b9621
narrow_widen_acl: enforce narrowacl in narrow_widen (SEC)
Sandu Turcan <idlsoft@gmail.com>
parents:
45942
diff
changeset
|
16 |
exchange, |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
17 |
extensions, |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
18 |
hg, |
40070
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39934
diff
changeset
|
19 |
narrowspec, |
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39934
diff
changeset
|
20 |
wireprototypes, |
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39934
diff
changeset
|
21 |
wireprotov1peer, |
39523
c90514043eaa
narrow: add narrow and ellipses as server capabilities
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
36351
diff
changeset
|
22 |
wireprotov1server, |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
23 |
) |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
24 |
|
42415
c767e655ffda
narrow: use narrow_widen wireproto command to widen in case of ellipses
Pulkit Goyal <7895pulkit@gmail.com>
parents:
40344
diff
changeset
|
25 |
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
|
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 uisetup(): |
40070
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39934
diff
changeset
|
29 |
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
|
30 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
31 |
|
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
32 |
def reposetup(repo): |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
33 |
def wirereposetup(ui, peer): |
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
34 |
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
|
35 |
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
|
36 |
# 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
|
37 |
# arguments to unbundle. |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
38 |
include, exclude = repo.narrowpats |
43503
313e3a279828
cleanup: remove pointless r-prefixes on double-quoted strings
Augie Fackler <augie@google.com>
parents:
43249
diff
changeset
|
39 |
kwargs["includepats"] = b','.join(include) |
313e3a279828
cleanup: remove pointless r-prefixes on double-quoted strings
Augie Fackler <augie@google.com>
parents:
43249
diff
changeset
|
40 |
kwargs["excludepats"] = b','.join(exclude) |
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
41 |
return orig(cmd, *args, **kwargs) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
42 |
|
50787
584fc92dd8d7
wrapfunction: use sysstr instead of bytes as argument in "narrow"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49244
diff
changeset
|
43 |
extensions.wrapfunction(peer, '_calltwowaystream', wrapped) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
44 |
|
36079
a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
45 |
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
|
46 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
47 |
|
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
48 |
@wireprotov1server.wireprotocommand( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
49 |
b'narrow_widen', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
50 |
b'oldincludes oldexcludes' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
51 |
b' newincludes newexcludes' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
52 |
b' commonheads cgversion' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
53 |
b' known ellipses', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
54 |
permission=b'pull', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
55 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
56 |
def narrow_widen( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
57 |
repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
58 |
proto, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
59 |
oldincludes, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
60 |
oldexcludes, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
61 |
newincludes, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
62 |
newexcludes, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
63 |
commonheads, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
64 |
cgversion, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
65 |
known, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
66 |
ellipses, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
67 |
): |
40070
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39934
diff
changeset
|
68 |
"""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
|
69 |
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
|
70 |
|
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39934
diff
changeset
|
71 |
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
|
72 |
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
|
73 |
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
|
74 |
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
|
75 |
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
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
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
|
80 |
""" |
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39934
diff
changeset
|
81 |
|
40148
74558635dad5
narrow: don't compress the bundle2 when sending 'error:abort'
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40075
diff
changeset
|
82 |
preferuncompressed = False |
40070
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39934
diff
changeset
|
83 |
try: |
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 |
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
|
86 |
# 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
|
87 |
return data.split(b',') if data else [] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
88 |
|
51309
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
89 |
oldincludes = set(splitpaths(oldincludes)) |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
90 |
newincludes = set(splitpaths(newincludes)) |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
91 |
oldexcludes = set(splitpaths(oldexcludes)) |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
92 |
newexcludes = set(splitpaths(newexcludes)) |
49241
6b10151b9621
narrow_widen_acl: enforce narrowacl in narrow_widen (SEC)
Sandu Turcan <idlsoft@gmail.com>
parents:
45942
diff
changeset
|
93 |
|
6b10151b9621
narrow_widen_acl: enforce narrowacl in narrow_widen (SEC)
Sandu Turcan <idlsoft@gmail.com>
parents:
45942
diff
changeset
|
94 |
# enforce narrow acl if set |
6b10151b9621
narrow_widen_acl: enforce narrowacl in narrow_widen (SEC)
Sandu Turcan <idlsoft@gmail.com>
parents:
45942
diff
changeset
|
95 |
if repo.ui.has_section(exchange._NARROWACL_SECTION): |
51309
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
96 |
kwargs = exchange.applynarrowacl( |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
97 |
repo, {'includepats': newincludes, 'excludepats': newexcludes} |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
98 |
) |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
99 |
newincludes = kwargs['includepats'] |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
100 |
requiredexcludes = kwargs['excludepats'] - newexcludes |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
101 |
if requiredexcludes: |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
102 |
# XXX: The below code to get the username was copied from exchange.py, |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
103 |
# where it is noted that this is technically a layering violation for |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
104 |
# assuming the existence of HTTP. Using it anyway to make the error |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
105 |
# message consistent with the error message for invalid includes. |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
106 |
ui = repo.ui |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
107 |
username = ui.shortuser( |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
108 |
ui.environ.get(b'REMOTE_USER') or ui.username() |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
109 |
) |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
110 |
raise error.Abort( |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
111 |
_(b"The following excludes cannot be removed for %s: %s") |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
112 |
% (username, stringutil.pprint(list(requiredexcludes))) |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
113 |
) |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
114 |
newexcludes = kwargs['excludepats'] |
49241
6b10151b9621
narrow_widen_acl: enforce narrowacl in narrow_widen (SEC)
Sandu Turcan <idlsoft@gmail.com>
parents:
45942
diff
changeset
|
115 |
|
40070
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39934
diff
changeset
|
116 |
# validate the patterns |
51309
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
117 |
narrowspec.validatepatterns(oldincludes) |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
118 |
narrowspec.validatepatterns(newincludes) |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
119 |
narrowspec.validatepatterns(oldexcludes) |
9b44b25dece1
narrow: prevent removal of ACL-defined excludes
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents:
50787
diff
changeset
|
120 |
narrowspec.validatepatterns(newexcludes) |
40070
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39934
diff
changeset
|
121 |
|
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39934
diff
changeset
|
122 |
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
|
123 |
known = wireprototypes.decodelist(known) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
124 |
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
|
125 |
ellipses = False |
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39934
diff
changeset
|
126 |
else: |
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39934
diff
changeset
|
127 |
ellipses = bool(ellipses) |
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39934
diff
changeset
|
128 |
cgversion = cgversion |
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39934
diff
changeset
|
129 |
|
42417
a97b12f726e4
narrow: pass the bundle to bundle2.widen_bundle() instead of generating there
Pulkit Goyal <7895pulkit@gmail.com>
parents:
42415
diff
changeset
|
130 |
bundler = bundle2.bundle20(repo.ui) |
43249
63d440bef72a
widening: pass in matchers instead of patterns
Martin von Zweigbergk <martinvonz@google.com>
parents:
43247
diff
changeset
|
131 |
newmatch = narrowspec.match( |
63d440bef72a
widening: pass in matchers instead of patterns
Martin von Zweigbergk <martinvonz@google.com>
parents:
43247
diff
changeset
|
132 |
repo.root, include=newincludes, exclude=newexcludes |
63d440bef72a
widening: pass in matchers instead of patterns
Martin von Zweigbergk <martinvonz@google.com>
parents:
43247
diff
changeset
|
133 |
) |
63d440bef72a
widening: pass in matchers instead of patterns
Martin von Zweigbergk <martinvonz@google.com>
parents:
43247
diff
changeset
|
134 |
oldmatch = narrowspec.match( |
63d440bef72a
widening: pass in matchers instead of patterns
Martin von Zweigbergk <martinvonz@google.com>
parents:
43247
diff
changeset
|
135 |
repo.root, include=oldincludes, exclude=oldexcludes |
63d440bef72a
widening: pass in matchers instead of patterns
Martin von Zweigbergk <martinvonz@google.com>
parents:
43247
diff
changeset
|
136 |
) |
42415
c767e655ffda
narrow: use narrow_widen wireproto command to widen in case of ellipses
Pulkit Goyal <7895pulkit@gmail.com>
parents:
40344
diff
changeset
|
137 |
if not ellipses: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
138 |
bundle2.widen_bundle( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
139 |
bundler, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
140 |
repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
141 |
oldmatch, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
142 |
newmatch, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
143 |
common, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
144 |
known, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
145 |
cgversion, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
146 |
ellipses, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
147 |
) |
42415
c767e655ffda
narrow: use narrow_widen wireproto command to widen in case of ellipses
Pulkit Goyal <7895pulkit@gmail.com>
parents:
40344
diff
changeset
|
148 |
else: |
43242
561f9bc4b4c5
widening: duplicate generateellipsesbundle2() for widening
Martin von Zweigbergk <martinvonz@google.com>
parents:
43077
diff
changeset
|
149 |
narrowbundle2.generate_ellipses_bundle2_for_widening( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45682
diff
changeset
|
150 |
bundler, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45682
diff
changeset
|
151 |
repo, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45682
diff
changeset
|
152 |
oldmatch, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45682
diff
changeset
|
153 |
newmatch, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45682
diff
changeset
|
154 |
cgversion, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45682
diff
changeset
|
155 |
common, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45682
diff
changeset
|
156 |
known, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
157 |
) |
40070
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39934
diff
changeset
|
158 |
except error.Abort as exc: |
40071
e8132a8897da
narrow: start returning bundle2 from widen_bundle()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40070
diff
changeset
|
159 |
bundler = bundle2.bundle20(repo.ui) |
45682
d2e1dcd4490d
errors: name arguments to Abort constructor
Martin von Zweigbergk <martinvonz@google.com>
parents:
43506
diff
changeset
|
160 |
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
|
161 |
advargs = [] |
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39934
diff
changeset
|
162 |
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
|
163 |
advargs.append((b'hint', exc.hint)) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
164 |
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
|
165 |
preferuncompressed = True |
40070
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39934
diff
changeset
|
166 |
|
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39934
diff
changeset
|
167 |
chunks = bundler.getchunks() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
168 |
return wireprototypes.streamres( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
169 |
gen=chunks, prefer_uncompressed=preferuncompressed |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
170 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42944
diff
changeset
|
171 |
|
40070
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39934
diff
changeset
|
172 |
|
8feae5b989bc
narrow: the first version of narrow_widen wireprotocol command
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39934
diff
changeset
|
173 |
def peernarrowwiden(remote, **kwargs): |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
174 |
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
|
175 |
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
|
176 |
|
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
177 |
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
|
178 |
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
|
179 |
|
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43503
diff
changeset
|
180 |
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
|
181 |
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
|
182 |
return bundle2.getunbundler(remote.ui, f) |