Patchwork D8631: localrepo: add writerequirements() and route requires writing through it

login
register
mail settings
Submitter phabricator
Date June 15, 2020, 3:03 p.m.
Message ID <differential-rev-PHID-DREV-c4tqba7d7x4eehv4lhja-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46503/
State New
Headers show

Comments

phabricator - June 15, 2020, 3:03 p.m.
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  In upcoming patches, to implement Share Safe plan we will be introducing
  requires file in store. We need to route all callers 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 once
  where we don't have the repo object, for example when initializing the object
  itself.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8631

AFFECTED FILES
  mercurial/interfaces/repository.py
  mercurial/localrepo.py
  mercurial/sparse.py
  mercurial/upgrade.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -21,7 +21,6 @@ 
     metadata,
     pycompat,
     revlog,
-    scmutil,
     util,
     vfs as vfsmod,
 )
@@ -1091,9 +1090,7 @@ 
             b'unable to read from repository\n'
         )
     )
-    scmutil.writerequires(
-        srcrepo.vfs, srcrepo.requirements | {b'upgradeinprogress'}
-    )
+    srcrepo.writerequirements(srcrepo.requirements | {b'upgradeinprogress'})
 
     ui.status(_(b'starting in-place swap of repository data\n'))
     ui.status(_(b'replaced files will be backed up at %s\n') % backuppath)
@@ -1122,7 +1119,7 @@ 
             b'again\n'
         )
     )
-    scmutil.writerequires(srcrepo.vfs, requirements)
+    srcrepo.writerequirements(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
diff --git a/mercurial/sparse.py b/mercurial/sparse.py
--- a/mercurial/sparse.py
+++ b/mercurial/sparse.py
@@ -21,7 +21,6 @@ 
     mergestate as mergestatemod,
     pathutil,
     pycompat,
-    scmutil,
     util,
 )
 from .utils import hashutil
@@ -601,10 +600,10 @@ 
 
     if b'exp-sparse' in oldrequires and removing:
         repo.requirements.discard(b'exp-sparse')
-        scmutil.writerequires(repo.vfs, repo.requirements)
+        repo.writerequirements(repo.requirements)
     elif b'exp-sparse' not in oldrequires:
         repo.requirements.add(b'exp-sparse')
-        scmutil.writerequires(repo.vfs, repo.requirements)
+        repo.writerequirements(repo.requirements)
 
     try:
         writeconfig(repo, includes, excludes, profiles)
@@ -613,7 +612,7 @@ 
         if repo.requirements != oldrequires:
             repo.requirements.clear()
             repo.requirements |= oldrequires
-            scmutil.writerequires(repo.vfs, repo.requirements)
+            repo.writerequirements(repo.requirements)
         writeconfig(repo, oldincludes, oldexcludes, oldprofiles)
         raise
 
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1297,6 +1297,10 @@ 
             caps.add(b'bundle2=' + urlreq.quote(capsblob))
         return caps
 
+    def writerequirements(self, requirements):
+        self.requirements = requirements
+        self._writerequirements()
+
     def _writerequirements(self):
         scmutil.writerequires(self.vfs, self.requirements)
 
diff --git a/mercurial/interfaces/repository.py b/mercurial/interfaces/repository.py
--- a/mercurial/interfaces/repository.py
+++ b/mercurial/interfaces/repository.py
@@ -1809,6 +1809,9 @@ 
     def savecommitmessage(text):
         pass
 
+    def writerequirements(requirements):
+        """ writes current repository requirements """
+
 
 class completelocalrepository(
     ilocalrepositorymain, ilocalrepositoryfilestorage