Read about our upcoming Code of Conduct on this issue

Commit e20e63b6 authored by Pulkit Goyal's avatar Pulkit Goyal
Browse files

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
parent 5d09a120b4be
......@@ -163,7 +163,7 @@ def lfconvert(ui, src, dest, *pats, **opts):
# to the destination repository's requirements.
if lfiles:
rdst.requirements.add(b'largefiles')
rdst._writerequirements()
scmutil.writereporequirements(rdst)
else:
class lfsource(filemap.filemap_source):
......
......@@ -448,7 +448,7 @@ def reposetup(ui, repo):
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'
......
......@@ -255,7 +255,7 @@ def _reposetup(ui, repo):
):
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
......
......@@ -312,7 +312,7 @@ def convertsink(orig, sink):
# 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
......
......@@ -20,6 +20,7 @@ from mercurial import (
localrepo,
narrowspec,
repair,
scmutil,
util,
wireprototypes,
)
......@@ -179,7 +180,7 @@ def _handlechangespec_2(op, inpart):
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 @@ def _handlenarrowspecs(op, inpart):
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)
......
......@@ -361,7 +361,7 @@ def cloneshallow(orig, ui, repo, *args, **opts):
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.
......
......@@ -166,6 +166,7 @@ from . import (
phases,
pushkey,
pycompat,
scmutil,
streamclone,
tags,
url,
......@@ -1977,7 +1978,7 @@ def handlechangegroup(op, inpart):
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)
......
......@@ -356,7 +356,7 @@ def unshare(ui, repo):
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
......
......@@ -1298,9 +1298,6 @@ class localrepository(object):
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
......
......@@ -1470,6 +1470,13 @@ def movedirstate(repo, newctx, match=None):
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):
......
......@@ -601,10 +601,10 @@ def _updateconfigandrefreshwdir(
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 @@ def _updateconfigandrefreshwdir(
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
......
......@@ -20,6 +20,7 @@ from . import (
narrowspec,
phases,
pycompat,
scmutil,
store,
util,
)
......@@ -187,7 +188,7 @@ def maybeperformlegacystreamclone(pullop):
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 @@ def applybundlev2(repo, fp, filecount, filesize, requirements):
repo.svfs.options = localrepo.resolvestorevfsoptions(
repo.ui, repo.requirements, repo.features
)
repo._writerequirements()
scmutil.writereporequirements(repo)
......@@ -1091,8 +1091,8 @@ def _upgraderepo(
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 @@ def _upgraderepo(
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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment