Patchwork [4,of,5,requirements-tidy] localrepo: use _replacerequirements()

login
register
mail settings
Submitter Gregory Szorc
Date Oct. 1, 2015, 7:29 p.m.
Message ID <2a5e349408a2b19fda78.1443727798@gps-mbp.local>
Download mbox | patch
Permalink /patch/10722/
State Rejected
Headers show

Comments

Gregory Szorc - Oct. 1, 2015, 7:29 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1443727278 25200
#      Thu Oct 01 12:21:18 2015 -0700
# Node ID 2a5e349408a2b19fda784ef02f9e564c67351a34
# Parent  699e72d262bcef563d434f9f45c8cd39d9bac083
localrepo: use _replacerequirements()

We now a unified API for manipulating requirements. Use it.

This removes all consumers of _applyopenerreqs() and
_writerequirements() from outside _replacementrequirements(), making
those functions inlineable.

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -243,40 +243,41 @@  class localrepository(object):
             if create:
                 if not self.wvfs.exists():
                     self.wvfs.makedirs()
                 self.vfs.makedir(notindexed=True)
-                self.requirements.update(self._baserequirements(create))
+                requirements = set(self._baserequirements(create))
+
                 if self.ui.configbool('format', 'usestore', True):
                     self.vfs.mkdir("store")
-                    self.requirements.add("store")
+                    requirements.add('store')
                     if self.ui.configbool('format', 'usefncache', True):
-                        self.requirements.add("fncache")
+                        requirements.add('fncache')
                         if self.ui.configbool('format', 'dotencode', True):
-                            self.requirements.add('dotencode')
+                            requirements.add('dotencode')
                     # create an invalid changelog
                     self.vfs.append(
                         "00changelog.i",
                         '\0\0\0\2' # represents revlogv2
                         ' dummy changelog to prevent using the old repo layout'
                     )
                 # experimental config: format.generaldelta
                 if self.ui.configbool('format', 'generaldelta', False):
-                    self.requirements.add("generaldelta")
+                    requirements.add('generaldelta')
                 if self.ui.configbool('experimental', 'treemanifest', False):
-                    self.requirements.add("treemanifest")
+                    requirements.add('treemanifest')
                 if self.ui.configbool('experimental', 'manifestv2', False):
-                    self.requirements.add("manifestv2")
+                    requirements.add('manifestv2')
             else:
                 raise error.RepoError(_("repository %s not found") % path)
         elif create:
             raise error.RepoError(_("repository %s already exists") % path)
         else:
             try:
-                self.requirements = scmutil.readrequires(
-                        self.vfs, self.supported)
+                requirements = scmutil.readrequires(self.vfs, self.supported)
             except IOError as inst:
                 if inst.errno != errno.ENOENT:
                     raise
+                requirements = set()
 
         self.sharedpath = self.path
         try:
             vfs = scmutil.vfs(self.vfs.read("sharedpath").rstrip('\n'),
@@ -289,17 +290,16 @@  class localrepository(object):
         except IOError as inst:
             if inst.errno != errno.ENOENT:
                 raise
 
-        self.store = store.store(
-                self.requirements, self.sharedpath, scmutil.vfs)
+        self.store = store.store(requirements, self.sharedpath, scmutil.vfs)
         self.spath = self.store.path
         self.svfs = self.store.vfs
         self.sjoin = self.store.join
         self.vfs.createmode = self.store.createmode
-        self._applyopenerreqs()
-        if create:
-            self._writerequirements()
+
+        # We can't call _replacerequirements() until we have a store vfs.
+        self._replacerequirements(requirements, frominit=not create)
 
         self._dirstatevalidatewarned = False
 
         self._branchcaches = {}
@@ -1871,12 +1871,10 @@  class localrepository(object):
 
             # new requirements = old non-format requirements +
             #                    new format-related remote requirements
             # requirements from the streamed-in repository
-            self.requirements = remotereqs | (
+            self._replacerequirements(remotereqs |
                     self.requirements - self.supportedformats)
-            self._applyopenerreqs()
-            self._writerequirements()
 
             if remotebranchmap:
                 rbheads = []
                 closed = []