Mercurial > hg
comparison hgext/narrow/narrowwirepeer.py @ 51309:9b44b25dece1 stable
narrow: prevent removal of ACL-defined excludes
author | Arun Kulshreshtha <akulshreshtha@janestreet.com> |
---|---|
date | Thu, 04 Jan 2024 14:45:31 -0500 |
parents | 584fc92dd8d7 |
children |
comparison
equal
deleted
inserted
replaced
51308:bf7c24e12fad | 51309:9b44b25dece1 |
---|---|
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 | |
9 from mercurial.i18n import _ | |
10 | |
11 from mercurial.utils import stringutil | |
8 | 12 |
9 from mercurial import ( | 13 from mercurial import ( |
10 bundle2, | 14 bundle2, |
11 error, | 15 error, |
12 exchange, | 16 exchange, |
80 | 84 |
81 def splitpaths(data): | 85 def splitpaths(data): |
82 # work around ''.split(',') => [''] | 86 # work around ''.split(',') => [''] |
83 return data.split(b',') if data else [] | 87 return data.split(b',') if data else [] |
84 | 88 |
85 oldincludes = splitpaths(oldincludes) | 89 oldincludes = set(splitpaths(oldincludes)) |
86 newincludes = splitpaths(newincludes) | 90 newincludes = set(splitpaths(newincludes)) |
87 oldexcludes = splitpaths(oldexcludes) | 91 oldexcludes = set(splitpaths(oldexcludes)) |
88 newexcludes = splitpaths(newexcludes) | 92 newexcludes = set(splitpaths(newexcludes)) |
89 | 93 |
90 # enforce narrow acl if set | 94 # enforce narrow acl if set |
91 if repo.ui.has_section(exchange._NARROWACL_SECTION): | 95 if repo.ui.has_section(exchange._NARROWACL_SECTION): |
92 exchange.applynarrowacl(repo, {'includepats': newincludes}) | 96 kwargs = exchange.applynarrowacl( |
97 repo, {'includepats': newincludes, 'excludepats': newexcludes} | |
98 ) | |
99 newincludes = kwargs['includepats'] | |
100 requiredexcludes = kwargs['excludepats'] - newexcludes | |
101 if requiredexcludes: | |
102 # XXX: The below code to get the username was copied from exchange.py, | |
103 # where it is noted that this is technically a layering violation for | |
104 # assuming the existence of HTTP. Using it anyway to make the error | |
105 # message consistent with the error message for invalid includes. | |
106 ui = repo.ui | |
107 username = ui.shortuser( | |
108 ui.environ.get(b'REMOTE_USER') or ui.username() | |
109 ) | |
110 raise error.Abort( | |
111 _(b"The following excludes cannot be removed for %s: %s") | |
112 % (username, stringutil.pprint(list(requiredexcludes))) | |
113 ) | |
114 newexcludes = kwargs['excludepats'] | |
93 | 115 |
94 # validate the patterns | 116 # validate the patterns |
95 narrowspec.validatepatterns(set(oldincludes)) | 117 narrowspec.validatepatterns(oldincludes) |
96 narrowspec.validatepatterns(set(newincludes)) | 118 narrowspec.validatepatterns(newincludes) |
97 narrowspec.validatepatterns(set(oldexcludes)) | 119 narrowspec.validatepatterns(oldexcludes) |
98 narrowspec.validatepatterns(set(newexcludes)) | 120 narrowspec.validatepatterns(newexcludes) |
99 | 121 |
100 common = wireprototypes.decodelist(commonheads) | 122 common = wireprototypes.decodelist(commonheads) |
101 known = wireprototypes.decodelist(known) | 123 known = wireprototypes.decodelist(known) |
102 if ellipses == b'0': | 124 if ellipses == b'0': |
103 ellipses = False | 125 ellipses = False |