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