D2925: localrepo: move featuresetupfuncs out of localrepository class (API)

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Thu Mar 22 00:09:52 EDT 2018


indygreg updated this revision to Diff 7240.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2925?vs=7217&id=7240

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

AFFECTED FILES
  hgext/largefiles/__init__.py
  hgext/lfs/__init__.py
  mercurial/localrepo.py
  tests/test-requires.t

CHANGE DETAILS

diff --git a/tests/test-requires.t b/tests/test-requires.t
--- a/tests/test-requires.t
+++ b/tests/test-requires.t
@@ -41,7 +41,7 @@
   >             supported |= {'featuresetup-test'}
   >             return
   > def uisetup(ui):
-  >     localrepo.localrepository.featuresetupfuncs.add(featuresetup)
+  >     localrepo.featuresetupfuncs.add(featuresetup)
   > EOF
   $ cat > supported/.hg/hgrc <<EOF
   > [extensions]
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -305,6 +305,15 @@
 # clients.
 REVLOGV2_REQUIREMENT = 'exp-revlogv2.0'
 
+# Functions receiving (ui, features) that extensions can register to impact
+# the ability to load repositories with custom requirements. Only
+# functions defined in loaded extensions are called.
+#
+# The function receives a set of requirement strings that the repository
+# is capable of opening. Functions will typically add elements to the
+# set to reflect that the extension knows how to handle that requirements.
+featuresetupfuncs = set()
+
 class localrepository(object):
 
     # obsolete experimental requirements:
@@ -332,10 +341,6 @@
         'treemanifest',
     }
 
-    # a list of (ui, featureset) functions.
-    # only functions defined in module of enabled extensions are invoked
-    featuresetupfuncs = set()
-
     # list of prefix for file which can be written without 'wlock'
     # Extensions should extend this list when needed
     _wlockfreeprefix = {
@@ -395,11 +400,11 @@
         except IOError:
             pass
 
-        if self.featuresetupfuncs:
+        if featuresetupfuncs:
             self.supported = set(self._basesupported) # use private copy
             extmods = set(m.__name__ for n, m
                           in extensions.extensions(self.ui))
-            for setupfunc in self.featuresetupfuncs:
+            for setupfunc in featuresetupfuncs:
                 if setupfunc.__module__ in extmods:
                     setupfunc(self.ui, self.supported)
         else:
diff --git a/hgext/lfs/__init__.py b/hgext/lfs/__init__.py
--- a/hgext/lfs/__init__.py
+++ b/hgext/lfs/__init__.py
@@ -199,7 +199,7 @@
     supported |= {'lfs'}
 
 def uisetup(ui):
-    localrepo.localrepository.featuresetupfuncs.add(featuresetup)
+    localrepo.featuresetupfuncs.add(featuresetup)
 
 def reposetup(ui, repo):
     # Nothing to do with a remote repo
diff --git a/hgext/largefiles/__init__.py b/hgext/largefiles/__init__.py
--- a/hgext/largefiles/__init__.py
+++ b/hgext/largefiles/__init__.py
@@ -146,7 +146,7 @@
     supported |= {'largefiles'}
 
 def uisetup(ui):
-    localrepo.localrepository.featuresetupfuncs.add(featuresetup)
+    localrepo.featuresetupfuncs.add(featuresetup)
     hg.wirepeersetupfuncs.append(proto.wirereposetup)
     uisetupmod.uisetup(ui)
 



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list