Patchwork [07,of,10] localrepo: move requirements to baselocalrepository

login
register
mail settings
Submitter Jun Wu
Date Feb. 10, 2017, 1:46 a.m.
Message ID <400747616e74d8af7ea0.1486691181@localhost.localdomain>
Download mbox | patch
Permalink /patch/18381/
State Deferred
Headers show

Comments

Jun Wu - Feb. 10, 2017, 1:46 a.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1486689107 28800
#      Thu Feb 09 17:11:47 2017 -0800
# Node ID 400747616e74d8af7ea053692e861d2495e56d78
# Parent  d93bba366d42f9537a5556d7ff948848b608d02c
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 400747616e74
localrepo: move requirements to baselocalrepository

See previous patches for why.

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -253,6 +253,5 @@  class baselocalrepository(object):
                                              'dotencode'))
 
-    def __init__(self, baseui, path):
-        self.requirements = set()
+    def __init__(self, baseui, path, create=False):
         self.wvfs = scmutil.vfs(path, expandpath=True, realpath=True)
         self.wopener = self.wvfs
@@ -273,4 +272,5 @@  class baselocalrepository(object):
 
         self.supported = self._loadsupported()
+        self.requirements = self._loadrequirements(create)
 
     def _loadextensions(self):
@@ -279,4 +279,17 @@  class baselocalrepository(object):
         pass
 
+    def _loadrequirements(self, create=False):
+        # read requirements without checking. subclasses should check them with
+        # self.supported and create missing files.
+        requirements = set()
+        if not create:
+            try:
+                requirements = scmutil.readrequires(self.vfs, self.supported,
+                                                    checkmissing=False)
+            except IOError as inst:
+                if inst.errno != errno.ENOENT:
+                    raise
+        return requirements
+
     def _loadsupported(self):
         # subclasses could run reposetup()s which affect supported.
@@ -303,38 +316,9 @@  class localrepository(baselocalrepositor
         # This list it to be filled by extension during repo setup
         self._phasedefaults = []
-        super(localrepository, self).__init__(baseui, path)
+        super(localrepository, self).__init__(baseui, path, create)
         self.auditor = pathutil.pathauditor(self.root, self._checknested)
         self.nofsauditor = pathutil.pathauditor(self.root, self._checknested,
                                                 realfs=False)
 
-        if not self.vfs.isdir():
-            if create:
-                self.requirements = newreporequirements(self)
-
-                if not self.wvfs.exists():
-                    self.wvfs.makedirs()
-                self.vfs.makedir(notindexed=True)
-
-                if 'store' in self.requirements:
-                    self.vfs.mkdir("store")
-
-                    # create an invalid changelog
-                    self.vfs.append(
-                        "00changelog.i",
-                        '\0\0\0\2' # represents revlogv2
-                        ' dummy changelog to prevent using the old repo layout'
-                    )
-            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)
-            except IOError as inst:
-                if inst.errno != errno.ENOENT:
-                    raise
-
         self.sharedpath = self.path
         try:
@@ -392,4 +376,36 @@  class localrepository(baselocalrepositor
         extensions.loadall(self.ui)
 
+    def _loadrequirements(self, create):
+        requirements = set()
+        path = self.origroot
+        if not self.vfs.isdir():
+            if create:
+                requirements = newreporequirements(self)
+
+                if not self.wvfs.exists():
+                    self.wvfs.makedirs()
+                self.vfs.makedir(notindexed=True)
+
+                if 'store' in requirements:
+                    self.vfs.mkdir("store")
+
+                    # create an invalid changelog
+                    self.vfs.append(
+                        "00changelog.i",
+                        '\0\0\0\2' # represents revlogv2
+                        ' dummy changelog to prevent using the old repo layout'
+                    )
+            else:
+                raise error.RepoError(_("repository %s not found") % path)
+        elif create:
+            raise error.RepoError(_("repository %s already exists") % path)
+        else:
+            try:
+                requirements = scmutil.readrequires(self.vfs, self.supported)
+            except IOError as inst:
+                if inst.errno != errno.ENOENT:
+                    raise
+        return requirements
+
     def _loadsupported(self):
         supported = set(self._basesupported) # use private copy