Mercurial > hg
changeset 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 | 802742769680 |
children | 9fd8c2a3db5a |
files | hgext/journal.py hgext/narrow/narrowrepo.py hgext/narrow/narrowspec.py hgext/share.py mercurial/hg.py |
diffstat | 5 files changed, 28 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/journal.py Mon Feb 12 15:49:15 2018 -0800 +++ b/hgext/journal.py Mon Feb 12 16:15:34 2018 -0800 @@ -36,8 +36,6 @@ util, ) -from . import share - cmdtable = {} command = registrar.command(cmdtable) @@ -169,7 +167,7 @@ """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 @@ 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
--- a/hgext/narrow/narrowrepo.py Mon Feb 12 15:49:15 2018 -0800 +++ b/hgext/narrow/narrowrepo.py Mon Feb 12 16:15:34 2018 -0800 @@ -9,15 +9,12 @@ from mercurial import ( bundlerepo, + hg, localrepo, match as matchmod, scmutil, ) -from .. import ( - share, -) - from . import ( narrowrevlog, narrowspec, @@ -37,7 +34,7 @@ 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:
--- a/hgext/narrow/narrowspec.py Mon Feb 12 15:49:15 2018 -0800 +++ b/hgext/narrow/narrowspec.py Mon Feb 12 16:15:34 2018 -0800 @@ -12,14 +12,11 @@ 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 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 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):
--- 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)
--- a/mercurial/hg.py Mon Feb 12 15:49:15 2018 -0800 +++ b/mercurial/hg.py Mon Feb 12 16:15:34 2018 -0800 @@ -202,6 +202,24 @@ 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'''