diff hgext/share.py @ 36159:0fe7e39dc683

hg: move share._getsrcrepo into core The fact we were calling this from extensions was a sign that it should live in core. We were also able to remove some extra attribute aliases from the share extension. Differential Revision: https://phab.mercurial-scm.org/D2200
author Gregory Szorc <gregory.szorc@gmail.com>
date Mon, 12 Feb 2018 16:15:34 -0800
parents 0f5521e56b77
children c303d65d2e34
line wrap: on
line diff
--- a/hgext/share.py	Mon Feb 12 15:49:15 2018 -0800
+++ b/hgext/share.py	Mon Feb 12 16:15:34 2018 -0800
@@ -52,9 +52,6 @@
     util,
 )
 
-repository = hg.repository
-parseurl = hg.parseurl
-
 cmdtable = {}
 command = registrar.command(cmdtable)
 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
@@ -135,27 +132,9 @@
         return False
     return hg.sharedbookmarks in shared
 
-def _getsrcrepo(repo):
-    """
-    Returns the source repository object for a given shared repository.
-    If repo is not a shared repository, return None.
-    """
-    if repo.sharedpath == repo.path:
-        return None
-
-    if util.safehasattr(repo, 'srcrepo') and repo.srcrepo:
-        return repo.srcrepo
-
-    # the sharedpath always ends in the .hg; we want the path to the repo
-    source = repo.vfs.split(repo.sharedpath)[0]
-    srcurl, branches = parseurl(source)
-    srcrepo = repository(repo.ui, srcurl)
-    repo.srcrepo = srcrepo
-    return srcrepo
-
 def getbkfile(orig, repo):
     if _hassharedbookmarks(repo):
-        srcrepo = _getsrcrepo(repo)
+        srcrepo = hg.sharedreposource(repo)
         if srcrepo is not None:
             # just orig(srcrepo) doesn't work as expected, because
             # HG_PENDING refers repo.root.
@@ -186,7 +165,7 @@
     orig(self, tr)
 
     if _hassharedbookmarks(self._repo):
-        srcrepo = _getsrcrepo(self._repo)
+        srcrepo = hg.sharedreposource(self._repo)
         if srcrepo is not None:
             category = 'share-bookmarks'
             tr.addpostclose(category, lambda tr: self._writerepo(srcrepo))
@@ -196,6 +175,6 @@
     orig(self, repo)
 
     if _hassharedbookmarks(self._repo):
-        srcrepo = _getsrcrepo(self._repo)
+        srcrepo = hg.sharedreposource(self._repo)
         if srcrepo is not None:
             orig(self, srcrepo)