# HG changeset patch # User Gregory Szorc # Date 2018-02-13 00:15:34 # Node ID 0fe7e39dc6832849c9b72b58dd2ca3e18bf253b3 # Parent 802742769680a357bfdc2060dedacd7b743ff24d 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 diff --git a/hgext/journal.py b/hgext/journal.py --- a/hgext/journal.py +++ b/hgext/journal.py @@ -36,8 +36,6 @@ from mercurial import ( util, ) -from . import share - cmdtable = {} command = registrar.command(cmdtable) @@ -169,7 +167,7 @@ def unsharejournal(orig, ui, repo, repop """Copy shared journal entries into this repo when unsharing""" if (repo.path == repopath and repo.shared() and util.safehasattr(repo, 'journal')): - sharedrepo = share._getsrcrepo(repo) + sharedrepo = hg.sharedreposource(repo) sharedfeatures = _readsharedfeatures(repo) if sharedrepo and sharedfeatures > {'journal'}: # there is a shared repository and there are shared journal entries @@ -258,7 +256,7 @@ class journalstorage(object): self.sharedfeatures = self.sharedvfs = None if repo.shared(): features = _readsharedfeatures(repo) - sharedrepo = share._getsrcrepo(repo) + sharedrepo = hg.sharedreposource(repo) if sharedrepo is not None and 'journal' in features: self.sharedvfs = sharedrepo.vfs self.sharedfeatures = features diff --git a/hgext/narrow/narrowrepo.py b/hgext/narrow/narrowrepo.py --- a/hgext/narrow/narrowrepo.py +++ b/hgext/narrow/narrowrepo.py @@ -9,15 +9,12 @@ from __future__ import absolute_import from mercurial import ( bundlerepo, + hg, localrepo, match as matchmod, scmutil, ) -from .. import ( - share, -) - from . import ( narrowrevlog, narrowspec, @@ -37,7 +34,7 @@ def wrappostshare(orig, sourcerepo, dest def unsharenarrowspec(orig, ui, repo, repopath): if (REQUIREMENT in repo.requirements and repo.path == repopath and repo.shared()): - srcrepo = share._getsrcrepo(repo) + srcrepo = hg.sharedreposource(repo) with srcrepo.vfs(narrowspec.FILENAME) as f: spec = f.read() with repo.vfs(narrowspec.FILENAME, 'w') as f: diff --git a/hgext/narrow/narrowspec.py b/hgext/narrow/narrowspec.py --- a/hgext/narrow/narrowspec.py +++ b/hgext/narrow/narrowspec.py @@ -12,14 +12,11 @@ import errno from mercurial.i18n import _ from mercurial import ( error, + hg, match as matchmod, util, ) -from .. import ( - share, -) - FILENAME = 'narrowspec' def _parsestoredpatterns(text): @@ -133,7 +130,7 @@ def needsexpansion(includes): def load(repo): if repo.shared(): - repo = share._getsrcrepo(repo) + repo = hg.sharedreposource(repo) try: spec = repo.vfs.read(FILENAME) except IOError as e: @@ -150,7 +147,7 @@ def load(repo): def save(repo, includepats, excludepats): spec = format(includepats, excludepats) if repo.shared(): - repo = share._getsrcrepo(repo) + repo = hg.sharedreposource(repo) repo.vfs.write(FILENAME, spec) def restrictpatterns(req_includes, req_excludes, repo_includes, repo_excludes): diff --git a/hgext/share.py b/hgext/share.py --- a/hgext/share.py +++ b/hgext/share.py @@ -52,9 +52,6 @@ from mercurial import ( 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 @@ def _hassharedbookmarks(repo): 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 @@ def recordchange(orig, self, tr): 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 @@ def writerepo(orig, self, repo): orig(self, repo) if _hassharedbookmarks(self._repo): - srcrepo = _getsrcrepo(self._repo) + srcrepo = hg.sharedreposource(self._repo) if srcrepo is not None: orig(self, srcrepo) diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -202,6 +202,24 @@ def defaultdest(source): return '' return os.path.basename(os.path.normpath(path)) +def sharedreposource(repo): + """Returns repository object for source repository of a shared repo. + + If repo is not a shared repository, returns 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 share(ui, source, dest=None, update=True, bookmarks=True, defaultpath=None, relative=False): '''create a shared repository'''