##// END OF EJS Templates
localrepo: add auditor attribute which knows about subrepos
Martin Geisler -
r12162:af8c4929 default
parent child Browse files
Show More
@@ -28,6 +28,7 class localrepository(repo.repository):
28 28 self.root = os.path.realpath(util.expandpath(path))
29 29 self.path = os.path.join(self.root, ".hg")
30 30 self.origroot = path
31 self.auditor = util.path_auditor(self.root, self._checknested)
31 32 self.opener = util.opener(self.path)
32 33 self.wopener = util.opener(self.root)
33 34 self.baseui = baseui
@@ -111,6 +112,44 class localrepository(repo.repository):
111 112 self._datafilters = {}
112 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 153 @propertycache
115 154 def changelog(self):
116 155 c = changelog.changelog(self.sopener)
@@ -210,6 +210,10 class abstractsubrepo(object):
210 210 """
211 211 raise NotImplementedError
212 212
213 def checknested(path):
214 """check if path is a subrepository within this repository"""
215 return False
216
213 217 def commit(self, text, user, date):
214 218 """commit the current changes to the subrepo with the given
215 219 log message. Use given user and date if possible. Return the
@@ -280,6 +284,9 class hgsubrepo(abstractsubrepo):
280 284 return True
281 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 290 def commit(self, text, user, date):
284 291 self._repo.ui.debug("committing subrepo %s\n" % relpath(self))
285 292 n = self._repo.commit(text, user, date)
General Comments 0
You need to be logged in to leave comments. Login now