D10434: subrepo: introduce a `repo_rel_or_abs_source` function
marmoute (Pierre-Yves David)
phabricator at mercurial-scm.org
Thu Apr 15 07:36:42 UTC 2021
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REVISION SUMMARY
The `subrepoutil` module has various function to compute the path of a
sub-repository compared to the root of the top repository. However, they was no
function available to compute the relative path of the repository "source". And
we need this information for exchange operation (in our case, `hg outgoing`).
The information is currently build using the `repo._subtoppath` hack. We reuse
the same logic but in a dedicated function independent of the `repo._subtoppath`
hack.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D10434
AFFECTED FILES
mercurial/subrepoutil.py
CHANGE DETAILS
diff --git a/mercurial/subrepoutil.py b/mercurial/subrepoutil.py
--- a/mercurial/subrepoutil.py
+++ b/mercurial/subrepoutil.py
@@ -383,6 +383,24 @@
return subs, commitsubs, newstate
+def repo_rel_or_abs_source(repo):
+ """return the source of this repo
+
+ Either absolute or relative the outermost repo"""
+ parent = repo
+ chunks = []
+ while util.safehasattr(parent, b'_subparent'):
+ source = urlutil.url(parent._subsource)
+ chunks.append(bytes(source))
+ if source.isabs():
+ break
+ parent = parent._subparent
+
+ chunks.reverse()
+ path = posixpath.join(*chunks)
+ return posixpath.normpath(path)
+
+
def reporelpath(repo):
# type: (localrepo.localrepository) -> bytes
"""return path to this (sub)repo as seen from outermost repo"""
To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
More information about the Mercurial-devel
mailing list