##// END OF EJS Templates
narrow_widen_acl: enforce narrowacl in narrow_widen (SEC)...
idlsoft -
r50136:6b10151b 6.1.3 stable
parent child Browse files
Show More
@@ -1,155 +1,161 b''
1 1 # narrowwirepeer.py - passes narrow spec with unbundle command
2 2 #
3 3 # Copyright 2017 Google, Inc.
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 from __future__ import absolute_import
9 9
10 10 from mercurial import (
11 11 bundle2,
12 12 error,
13 exchange,
13 14 extensions,
14 15 hg,
15 16 narrowspec,
16 17 wireprototypes,
17 18 wireprotov1peer,
18 19 wireprotov1server,
19 20 )
20 21
21 22 from . import narrowbundle2
22 23
23 24
24 25 def uisetup():
25 26 wireprotov1peer.wirepeer.narrow_widen = peernarrowwiden
26 27
27 28
28 29 def reposetup(repo):
29 30 def wirereposetup(ui, peer):
30 31 def wrapped(orig, cmd, *args, **kwargs):
31 32 if cmd == b'unbundle':
32 33 # TODO: don't blindly add include/exclude wireproto
33 34 # arguments to unbundle.
34 35 include, exclude = repo.narrowpats
35 36 kwargs["includepats"] = b','.join(include)
36 37 kwargs["excludepats"] = b','.join(exclude)
37 38 return orig(cmd, *args, **kwargs)
38 39
39 40 extensions.wrapfunction(peer, b'_calltwowaystream', wrapped)
40 41
41 42 hg.wirepeersetupfuncs.append(wirereposetup)
42 43
43 44
44 45 @wireprotov1server.wireprotocommand(
45 46 b'narrow_widen',
46 47 b'oldincludes oldexcludes'
47 48 b' newincludes newexcludes'
48 49 b' commonheads cgversion'
49 50 b' known ellipses',
50 51 permission=b'pull',
51 52 )
52 53 def narrow_widen(
53 54 repo,
54 55 proto,
55 56 oldincludes,
56 57 oldexcludes,
57 58 newincludes,
58 59 newexcludes,
59 60 commonheads,
60 61 cgversion,
61 62 known,
62 63 ellipses,
63 64 ):
64 65 """wireprotocol command to send data when a narrow clone is widen. We will
65 66 be sending a changegroup here.
66 67
67 68 The current set of arguments which are required:
68 69 oldincludes: the old includes of the narrow copy
69 70 oldexcludes: the old excludes of the narrow copy
70 71 newincludes: the new includes of the narrow copy
71 72 newexcludes: the new excludes of the narrow copy
72 73 commonheads: list of heads which are common between the server and client
73 74 cgversion(maybe): the changegroup version to produce
74 75 known: list of nodes which are known on the client (used in ellipses cases)
75 76 ellipses: whether to send ellipses data or not
76 77 """
77 78
78 79 preferuncompressed = False
79 80 try:
80 81
81 82 def splitpaths(data):
82 83 # work around ''.split(',') => ['']
83 84 return data.split(b',') if data else []
84 85
85 86 oldincludes = splitpaths(oldincludes)
86 87 newincludes = splitpaths(newincludes)
87 88 oldexcludes = splitpaths(oldexcludes)
88 89 newexcludes = splitpaths(newexcludes)
90
91 # enforce narrow acl if set
92 if repo.ui.has_section(exchange._NARROWACL_SECTION):
93 exchange.applynarrowacl(repo, {'includepats': newincludes})
94
89 95 # validate the patterns
90 96 narrowspec.validatepatterns(set(oldincludes))
91 97 narrowspec.validatepatterns(set(newincludes))
92 98 narrowspec.validatepatterns(set(oldexcludes))
93 99 narrowspec.validatepatterns(set(newexcludes))
94 100
95 101 common = wireprototypes.decodelist(commonheads)
96 102 known = wireprototypes.decodelist(known)
97 103 if ellipses == b'0':
98 104 ellipses = False
99 105 else:
100 106 ellipses = bool(ellipses)
101 107 cgversion = cgversion
102 108
103 109 bundler = bundle2.bundle20(repo.ui)
104 110 newmatch = narrowspec.match(
105 111 repo.root, include=newincludes, exclude=newexcludes
106 112 )
107 113 oldmatch = narrowspec.match(
108 114 repo.root, include=oldincludes, exclude=oldexcludes
109 115 )
110 116 if not ellipses:
111 117 bundle2.widen_bundle(
112 118 bundler,
113 119 repo,
114 120 oldmatch,
115 121 newmatch,
116 122 common,
117 123 known,
118 124 cgversion,
119 125 ellipses,
120 126 )
121 127 else:
122 128 narrowbundle2.generate_ellipses_bundle2_for_widening(
123 129 bundler,
124 130 repo,
125 131 oldmatch,
126 132 newmatch,
127 133 cgversion,
128 134 common,
129 135 known,
130 136 )
131 137 except error.Abort as exc:
132 138 bundler = bundle2.bundle20(repo.ui)
133 139 manargs = [(b'message', exc.message)]
134 140 advargs = []
135 141 if exc.hint is not None:
136 142 advargs.append((b'hint', exc.hint))
137 143 bundler.addpart(bundle2.bundlepart(b'error:abort', manargs, advargs))
138 144 preferuncompressed = True
139 145
140 146 chunks = bundler.getchunks()
141 147 return wireprototypes.streamres(
142 148 gen=chunks, prefer_uncompressed=preferuncompressed
143 149 )
144 150
145 151
146 152 def peernarrowwiden(remote, **kwargs):
147 153 for ch in ('commonheads', 'known'):
148 154 kwargs[ch] = wireprototypes.encodelist(kwargs[ch])
149 155
150 156 for ch in ('oldincludes', 'newincludes', 'oldexcludes', 'newexcludes'):
151 157 kwargs[ch] = b','.join(kwargs[ch])
152 158
153 159 kwargs['ellipses'] = b'%i' % bool(kwargs['ellipses'])
154 160 f = remote._callcompressable(b'narrow_widen', **kwargs)
155 161 return bundle2.getunbundler(remote.ui, f)
@@ -1,43 +1,79 b''
1 1 Make a narrow clone then archive it
2 2 $ . "$TESTDIR/narrow-library.sh"
3 3
4 4 $ hg init master
5 5 $ cd master
6 6
7 7 $ for x in `$TESTDIR/seq.py 3`; do
8 8 > echo $x > "f$x"
9 9 > hg add "f$x"
10 10 > hg commit -m "Add $x"
11 11 > done
12 12 $ cat >> .hg/hgrc << EOF
13 13 > [narrowacl]
14 14 > default.includes=f1 f2
15 15 > EOF
16 16 $ hg serve -a localhost -p $HGPORT1 -d --pid-file=hg.pid
17 17 $ cat hg.pid >> "$DAEMON_PIDS"
18 18
19 19 $ cd ..
20 20 $ hg clone http://localhost:$HGPORT1 narrowclone1
21 21 requesting all changes
22 22 adding changesets
23 23 adding manifests
24 24 adding file changes
25 25 added 3 changesets with 2 changes to 2 files
26 26 new changesets * (glob)
27 27 updating to branch default
28 28 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
29 29
30 30 The clone directory should only contain f1 and f2
31 31 $ ls -A -1 narrowclone1 | sort
32 32 .hg
33 33 f1
34 34 f2
35 35
36 36 Requirements should contain narrowhg
37 37 $ hg debugrequires -R narrowclone1 | grep narrowhg
38 38 narrowhg-experimental
39 39
40 40 NarrowHG should track f1 and f2
41 41 $ hg -R narrowclone1 tracked
42 42 I path:f1
43 43 I path:f2
44
45 Narrow should not be able to widen to include f3
46 $ hg -R narrowclone1 tracked --addinclude f3
47 comparing with http://localhost:$HGPORT1/
48 searching for changes
49 abort: The following includes are not accessible for test: ['path:f3']
50 [255]
51 $ ls -A -1 narrowclone1 | sort
52 .hg
53 f1
54 f2
55 $ hg -R narrowclone1 tracked
56 I path:f1
57 I path:f2
58
59 Narrow should allow widen to include f2
60 $ hg -R narrowclone1 tracked --removeinclude f2 > /dev/null
61 $ hg -R narrowclone1 tracked
62 I path:f1
63 $ ls -A -1 narrowclone1 | sort
64 .hg
65 f1
66 $ hg -R narrowclone1 tracked --addinclude f2
67 comparing with http://localhost:$HGPORT1/
68 searching for changes
69 adding changesets
70 adding manifests
71 adding file changes
72 added 0 changesets with 1 changes to 1 files
73 $ hg -R narrowclone1 tracked
74 I path:f1
75 I path:f2
76 $ ls -A -1 narrowclone1 | sort
77 .hg
78 f1
79 f2
General Comments 0
You need to be logged in to leave comments. Login now