D2200: hg: move share._getsrcrepo into core
This revision was automatically updated to reflect the committed changes. Closed by commit rHG0fe7e39dc683: hg: move share._getsrcrepo into core (authored by indygreg, committed by ). REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D2200?vs=5569&id=5646 REVISION DETAIL https://phab.mercurial-scm.org/D2200 AFFECTED FILES hgext/journal.py hgext/narrow/narrowrepo.py hgext/narrow/narrowspec.py hgext/share.py mercurial/hg.py CHANGE DETAILS diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -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''' diff --git a/hgext/share.py b/hgext/share.py --- a/hgext/share.py +++ b/hgext/share.py @@ -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) 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 @@ 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): 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 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: diff --git a/hgext/journal.py b/hgext/journal.py --- a/hgext/journal.py +++ b/hgext/journa
D2200: hg: move share._getsrcrepo into core
pulkit added a comment. Fb's hg-experimental also uses a utility module just for this function, so I am +1 on moving this to core. https://bitbucket.org/facebook/hg-experimental/src/f27f094e91553d3cae5167c0b1c42ae940f888d5/hgext3rd/shareutil.py REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D2200 To: indygreg, #hg-reviewers Cc: pulkit, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D2200: hg: move share._getsrcrepo into core
indygreg created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REVISION SUMMARY 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. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D2200 AFFECTED FILES hgext/journal.py hgext/narrow/narrowrepo.py hgext/narrow/narrowspec.py hgext/share.py mercurial/hg.py CHANGE DETAILS diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -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''' diff --git a/hgext/share.py b/hgext/share.py --- a/hgext/share.py +++ b/hgext/share.py @@ -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) 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 @@ 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): 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 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: diff --git a/hgext/journal.py b/hgext/journa