Mercurial > hg-stable
changeset 45106:a03c177a4679
scmutil: add writereporequirements() and route requires writing through it
In upcoming patches, to implement Share Safe plan we will be introducing
requires file in store. We need to route all callers to a single function
to check for a share-safe requirement and if present, write requirements to
.hg/store/requires instead.
After this patch, callers directly calling scmutil.writerequires() are only
those where we don't have the repo object, for example when initializing
the repository object itself.
Differential Revision: https://phab.mercurial-scm.org/D8631
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Tue, 14 Apr 2020 16:43:54 +0530 |
parents | 5d09a120b4be |
children | 4a28f5e8408e |
files | hgext/largefiles/lfcommands.py hgext/largefiles/reposetup.py hgext/lfs/__init__.py hgext/lfs/wrapper.py hgext/narrow/narrowbundle2.py hgext/remotefilelog/__init__.py mercurial/bundle2.py mercurial/hg.py mercurial/localrepo.py mercurial/scmutil.py mercurial/sparse.py mercurial/streamclone.py mercurial/upgrade.py |
diffstat | 13 files changed, 27 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/largefiles/lfcommands.py Tue Jul 14 11:28:06 2020 -0700 +++ b/hgext/largefiles/lfcommands.py Tue Apr 14 16:43:54 2020 +0530 @@ -163,7 +163,7 @@ # to the destination repository's requirements. if lfiles: rdst.requirements.add(b'largefiles') - rdst._writerequirements() + scmutil.writereporequirements(rdst) else: class lfsource(filemap.filemap_source):
--- a/hgext/largefiles/reposetup.py Tue Jul 14 11:28:06 2020 -0700 +++ b/hgext/largefiles/reposetup.py Tue Apr 14 16:43:54 2020 +0530 @@ -448,7 +448,7 @@ lfutil.shortname + b'/' in f[0] for f in repo.store.datafiles() ): repo.requirements.add(b'largefiles') - repo._writerequirements() + scmutil.writereporequirements(repo) ui.setconfig( b'hooks', b'changegroup.lfiles', checkrequireslfiles, b'largefiles'
--- a/hgext/lfs/__init__.py Tue Jul 14 11:28:06 2020 -0700 +++ b/hgext/lfs/__init__.py Tue Apr 14 16:43:54 2020 +0530 @@ -255,7 +255,7 @@ ): repo.requirements.add(b'lfs') repo.features.add(repository.REPO_FEATURE_LFS) - repo._writerequirements() + scmutil.writereporequirements(repo) repo.prepushoutgoinghooks.add(b'lfs', wrapper.prepush) break
--- a/hgext/lfs/wrapper.py Tue Jul 14 11:28:06 2020 -0700 +++ b/hgext/lfs/wrapper.py Tue Apr 14 16:43:54 2020 +0530 @@ -312,7 +312,7 @@ # membership before assuming it is in the context. if any(f in ctx and ctx[f].islfs() for f, n in files): self.repo.requirements.add(b'lfs') - self.repo._writerequirements() + scmutil.writereporequirements(self.repo) return node
--- a/hgext/narrow/narrowbundle2.py Tue Jul 14 11:28:06 2020 -0700 +++ b/hgext/narrow/narrowbundle2.py Tue Apr 14 16:43:54 2020 +0530 @@ -20,6 +20,7 @@ localrepo, narrowspec, repair, + scmutil, util, wireprototypes, ) @@ -179,7 +180,7 @@ if not repository.NARROW_REQUIREMENT in op.repo.requirements: op.repo.requirements.add(repository.NARROW_REQUIREMENT) - op.repo._writerequirements() + scmutil.writereporequirements(op.repo) op.repo.setnarrowpats(includepats, excludepats) narrowspec.copytoworkingcopy(op.repo) @@ -195,7 +196,7 @@ if repository.NARROW_REQUIREMENT not in op.repo.requirements: op.repo.requirements.add(repository.NARROW_REQUIREMENT) - op.repo._writerequirements() + scmutil.writereporequirements(op.repo) op.repo.setnarrowpats(includepats, excludepats) narrowspec.copytoworkingcopy(op.repo)
--- a/hgext/remotefilelog/__init__.py Tue Jul 14 11:28:06 2020 -0700 +++ b/hgext/remotefilelog/__init__.py Tue Apr 14 16:43:54 2020 +0530 @@ -361,7 +361,7 @@ self.unfiltered().__class__, ) self.requirements.add(constants.SHALLOWREPO_REQUIREMENT) - self._writerequirements() + scmutil.writereporequirements(self) # Since setupclient hadn't been called, exchange.pull was not # wrapped. So we need to manually invoke our version of it.
--- a/mercurial/bundle2.py Tue Jul 14 11:28:06 2020 -0700 +++ b/mercurial/bundle2.py Tue Apr 14 16:43:54 2020 +0530 @@ -166,6 +166,7 @@ phases, pushkey, pycompat, + scmutil, streamclone, tags, url, @@ -1977,7 +1978,7 @@ op.repo.svfs.options = localrepo.resolvestorevfsoptions( op.repo.ui, op.repo.requirements, op.repo.features ) - op.repo._writerequirements() + scmutil.writereporequirements(op.repo) bundlesidedata = bool(b'exp-sidedata' in inpart.params) reposidedata = bool(b'exp-sidedata-flag' in op.repo.requirements)
--- a/mercurial/hg.py Tue Jul 14 11:28:06 2020 -0700 +++ b/mercurial/hg.py Tue Apr 14 16:43:54 2020 +0530 @@ -356,7 +356,7 @@ repo.requirements.discard(b'shared') repo.requirements.discard(b'relshared') - repo._writerequirements() + scmutil.writereporequirements(repo) # Removing share changes some fundamental properties of the repo instance. # So we instantiate a new repo object and operate on it rather than
--- a/mercurial/localrepo.py Tue Jul 14 11:28:06 2020 -0700 +++ b/mercurial/localrepo.py Tue Apr 14 16:43:54 2020 +0530 @@ -1298,9 +1298,6 @@ caps.add(b'bundle2=' + urlreq.quote(capsblob)) return caps - def _writerequirements(self): - scmutil.writerequires(self.vfs, self.requirements) - # Don't cache auditor/nofsauditor, or you'll end up with reference cycle: # self -> auditor -> self._checknested -> self
--- a/mercurial/scmutil.py Tue Jul 14 11:28:06 2020 -0700 +++ b/mercurial/scmutil.py Tue Apr 14 16:43:54 2020 +0530 @@ -1470,6 +1470,13 @@ repo._quick_access_changeid_invalidate() +def writereporequirements(repo, requirements=None): + """ writes requirements for the repo to .hg/requires """ + if requirements: + repo.requirements = requirements + writerequires(repo.vfs, repo.requirements) + + def writerequires(opener, requirements): with opener(b'requires', b'w', atomictemp=True) as fp: for r in sorted(requirements):
--- a/mercurial/sparse.py Tue Jul 14 11:28:06 2020 -0700 +++ b/mercurial/sparse.py Tue Apr 14 16:43:54 2020 +0530 @@ -601,10 +601,10 @@ if b'exp-sparse' in oldrequires and removing: repo.requirements.discard(b'exp-sparse') - scmutil.writerequires(repo.vfs, repo.requirements) + scmutil.writereporequirements(repo) elif b'exp-sparse' not in oldrequires: repo.requirements.add(b'exp-sparse') - scmutil.writerequires(repo.vfs, repo.requirements) + scmutil.writereporequirements(repo) try: writeconfig(repo, includes, excludes, profiles) @@ -613,7 +613,7 @@ if repo.requirements != oldrequires: repo.requirements.clear() repo.requirements |= oldrequires - scmutil.writerequires(repo.vfs, repo.requirements) + scmutil.writereporequirements(repo) writeconfig(repo, oldincludes, oldexcludes, oldprofiles) raise
--- a/mercurial/streamclone.py Tue Jul 14 11:28:06 2020 -0700 +++ b/mercurial/streamclone.py Tue Apr 14 16:43:54 2020 +0530 @@ -20,6 +20,7 @@ narrowspec, phases, pycompat, + scmutil, store, util, ) @@ -187,7 +188,7 @@ repo.svfs.options = localrepo.resolvestorevfsoptions( repo.ui, repo.requirements, repo.features ) - repo._writerequirements() + scmutil.writereporequirements(repo) if rbranchmap: repo._branchcaches.replace(repo, rbranchmap) @@ -730,4 +731,4 @@ repo.svfs.options = localrepo.resolvestorevfsoptions( repo.ui, repo.requirements, repo.features ) - repo._writerequirements() + scmutil.writereporequirements(repo)
--- a/mercurial/upgrade.py Tue Jul 14 11:28:06 2020 -0700 +++ b/mercurial/upgrade.py Tue Apr 14 16:43:54 2020 +0530 @@ -1091,8 +1091,8 @@ b'unable to read from repository\n' ) ) - scmutil.writerequires( - srcrepo.vfs, srcrepo.requirements | {b'upgradeinprogress'} + scmutil.writereporequirements( + srcrepo, srcrepo.requirements | {b'upgradeinprogress'} ) ui.status(_(b'starting in-place swap of repository data\n')) @@ -1122,7 +1122,7 @@ b'again\n' ) ) - scmutil.writerequires(srcrepo.vfs, requirements) + scmutil.writereporequirements(srcrepo, requirements) # The lock file from the old store won't be removed because nothing has a # reference to its new location. So clean it up manually. Alternatively, we