Mercurial > public > mercurial-scm > hg
comparison mercurial/subrepo.py @ 24673:105758d1b37b
subrepo: add _relpath field to centralize subrelpath logic
This patch adds propertycache-ed "_relpath" field to
"abstractsubrepo", to centralize "subrelpath" logic into it.
Now, "subrelpath()" can always return "_relpath" field of the
specified subrepo object, because it is ensured that subrepo object
has it. To reduce changes in this patch, "subrelpath()" itself is
still kept, even though it seems to be redundant.
This is also a part of eliminating "os.path.*" API invocations for
"Windows UTF-8 Plan".
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Fri, 10 Apr 2015 00:36:42 +0900 |
parents | dd0b86f740ef |
children | 93b0e0db7929 |
comparison
equal
deleted
inserted
replaced
24672:dd0b86f740ef | 24673:105758d1b37b |
---|---|
278 parent = parent._subparent | 278 parent = parent._subparent |
279 return repo.root[len(pathutil.normasprefix(parent.root)):] | 279 return repo.root[len(pathutil.normasprefix(parent.root)):] |
280 | 280 |
281 def subrelpath(sub): | 281 def subrelpath(sub): |
282 """return path to this subrepo as seen from outermost repo""" | 282 """return path to this subrepo as seen from outermost repo""" |
283 if util.safehasattr(sub, '_relpath'): | 283 return sub._relpath |
284 return sub._relpath | |
285 if not util.safehasattr(sub, '_repo'): | |
286 return sub._path | |
287 return reporelpath(sub._repo) | |
288 | 284 |
289 def _abssource(repo, push=False, abort=True): | 285 def _abssource(repo, push=False, abort=True): |
290 """return pull/push path of repo - either based on parent repo .hgsub info | 286 """return pull/push path of repo - either based on parent repo .hgsub info |
291 or on the top repo config. Abort or return None if no source found.""" | 287 or on the top repo config. Abort or return None if no source found.""" |
292 if util.safehasattr(repo, '_subparent'): | 288 if util.safehasattr(repo, '_subparent'): |
555 @propertycache | 551 @propertycache |
556 def wvfs(self): | 552 def wvfs(self): |
557 """return vfs to access the working directory of this subrepository | 553 """return vfs to access the working directory of this subrepository |
558 """ | 554 """ |
559 return scmutil.vfs(self._ctx.repo().wvfs.join(self._path)) | 555 return scmutil.vfs(self._ctx.repo().wvfs.join(self._path)) |
556 | |
557 @propertycache | |
558 def _relpath(self): | |
559 """return path to this subrepository as seen from outermost repository | |
560 """ | |
561 return self.wvfs.reljoin(reporelpath(self._ctx.repo()), self._path) | |
560 | 562 |
561 class hgsubrepo(abstractsubrepo): | 563 class hgsubrepo(abstractsubrepo): |
562 def __init__(self, ctx, path, state): | 564 def __init__(self, ctx, path, state): |
563 super(hgsubrepo, self).__init__(ctx, path) | 565 super(hgsubrepo, self).__init__(ctx, path) |
564 self._state = state | 566 self._state = state |
1186 | 1188 |
1187 class gitsubrepo(abstractsubrepo): | 1189 class gitsubrepo(abstractsubrepo): |
1188 def __init__(self, ctx, path, state): | 1190 def __init__(self, ctx, path, state): |
1189 super(gitsubrepo, self).__init__(ctx, path) | 1191 super(gitsubrepo, self).__init__(ctx, path) |
1190 self._state = state | 1192 self._state = state |
1191 self._relpath = os.path.join(reporelpath(ctx.repo()), path) | |
1192 self._abspath = ctx.repo().wjoin(path) | 1193 self._abspath = ctx.repo().wjoin(path) |
1193 self._subparent = ctx.repo() | 1194 self._subparent = ctx.repo() |
1194 self._ensuregit() | 1195 self._ensuregit() |
1195 | 1196 |
1196 def _ensuregit(self): | 1197 def _ensuregit(self): |