Patchwork D10434: subrepo: introduce a `repo_rel_or_abs_source` function

login
register
mail settings
Submitter phabricator
Date April 15, 2021, 7:36 a.m.
Message ID <differential-rev-PHID-DREV-6b7uvpbwosmds4reela3-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48751/
State Superseded
Headers show

Comments

phabricator - April 15, 2021, 7:36 a.m.
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




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

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"""