Show More
@@ -28,6 +28,7 b' class localrepository(repo.repository):' | |||||
28 | self.root = os.path.realpath(util.expandpath(path)) |
|
28 | self.root = os.path.realpath(util.expandpath(path)) | |
29 | self.path = os.path.join(self.root, ".hg") |
|
29 | self.path = os.path.join(self.root, ".hg") | |
30 | self.origroot = path |
|
30 | self.origroot = path | |
|
31 | self.auditor = util.path_auditor(self.root, self._checknested) | |||
31 | self.opener = util.opener(self.path) |
|
32 | self.opener = util.opener(self.path) | |
32 | self.wopener = util.opener(self.root) |
|
33 | self.wopener = util.opener(self.root) | |
33 | self.baseui = baseui |
|
34 | self.baseui = baseui | |
@@ -111,6 +112,44 b' class localrepository(repo.repository):' | |||||
111 | self._datafilters = {} |
|
112 | self._datafilters = {} | |
112 | self._transref = self._lockref = self._wlockref = None |
|
113 | self._transref = self._lockref = self._wlockref = None | |
113 |
|
114 | |||
|
115 | def _checknested(self, path): | |||
|
116 | """Determine if path is a legal nested repository.""" | |||
|
117 | if not path.startswith(self.root): | |||
|
118 | return False | |||
|
119 | subpath = path[len(self.root) + 1:] | |||
|
120 | ||||
|
121 | # XXX: Checking against the current working copy is wrong in | |||
|
122 | # the sense that it can reject things like | |||
|
123 | # | |||
|
124 | # $ hg cat -r 10 sub/x.txt | |||
|
125 | # | |||
|
126 | # if sub/ is no longer a subrepository in the working copy | |||
|
127 | # parent revision. | |||
|
128 | # | |||
|
129 | # However, it can of course also allow things that would have | |||
|
130 | # been rejected before, such as the above cat command if sub/ | |||
|
131 | # is a subrepository now, but was a normal directory before. | |||
|
132 | # The old path auditor would have rejected by mistake since it | |||
|
133 | # panics when it sees sub/.hg/. | |||
|
134 | # | |||
|
135 | # All in all, checking against the working copy parent | |||
|
136 | # revision seems sensible since we want to prevent access to | |||
|
137 | # nested repositories on the filesystem *now*. | |||
|
138 | ctx = self['.'] | |||
|
139 | parts = util.splitpath(subpath) | |||
|
140 | while parts: | |||
|
141 | prefix = os.sep.join(parts) | |||
|
142 | if prefix in ctx.substate: | |||
|
143 | if prefix == subpath: | |||
|
144 | return True | |||
|
145 | else: | |||
|
146 | sub = ctx.sub(prefix) | |||
|
147 | return sub.checknested(subpath[len(prefix) + 1:]) | |||
|
148 | else: | |||
|
149 | parts.pop() | |||
|
150 | return False | |||
|
151 | ||||
|
152 | ||||
114 | @propertycache |
|
153 | @propertycache | |
115 | def changelog(self): |
|
154 | def changelog(self): | |
116 | c = changelog.changelog(self.sopener) |
|
155 | c = changelog.changelog(self.sopener) |
@@ -210,6 +210,10 b' class abstractsubrepo(object):' | |||||
210 | """ |
|
210 | """ | |
211 | raise NotImplementedError |
|
211 | raise NotImplementedError | |
212 |
|
212 | |||
|
213 | def checknested(path): | |||
|
214 | """check if path is a subrepository within this repository""" | |||
|
215 | return False | |||
|
216 | ||||
213 | def commit(self, text, user, date): |
|
217 | def commit(self, text, user, date): | |
214 | """commit the current changes to the subrepo with the given |
|
218 | """commit the current changes to the subrepo with the given | |
215 | log message. Use given user and date if possible. Return the |
|
219 | log message. Use given user and date if possible. Return the | |
@@ -280,6 +284,9 b' class hgsubrepo(abstractsubrepo):' | |||||
280 | return True |
|
284 | return True | |
281 | return w.dirty() # working directory changed |
|
285 | return w.dirty() # working directory changed | |
282 |
|
286 | |||
|
287 | def checknested(self, path): | |||
|
288 | return self._repo._checknested(self._repo.wjoin(path)) | |||
|
289 | ||||
283 | def commit(self, text, user, date): |
|
290 | def commit(self, text, user, date): | |
284 | self._repo.ui.debug("committing subrepo %s\n" % relpath(self)) |
|
291 | self._repo.ui.debug("committing subrepo %s\n" % relpath(self)) | |
285 | n = self._repo.commit(text, user, date) |
|
292 | n = self._repo.commit(text, user, date) |
General Comments 0
You need to be logged in to leave comments.
Login now