Patchwork D8911: repository: introduce constant for sparse repo requirement and use it

login
register
mail settings
Submitter phabricator
Date Aug. 7, 2020, 12:45 p.m.
Message ID <differential-rev-PHID-DREV-zvzvlfglvepvj6xigiuk-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47010/
State Superseded
Headers show

Comments

phabricator - Aug. 7, 2020, 12:45 p.m.
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  In future we will like to much cleaner logic around which requirement is for
  working copy and which can go in store. To start with that, we first need to
  de-clutter the requirement values spread around and replace them with constants.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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

CHANGE DETAILS




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

Patch

diff --git a/mercurial/sparse.py b/mercurial/sparse.py
--- a/mercurial/sparse.py
+++ b/mercurial/sparse.py
@@ -26,6 +26,8 @@ 
 )
 from .utils import hashutil
 
+from .interfaces import repository
+
 # Whether sparse features are enabled. This variable is intended to be
 # temporary to facilitate porting sparse to core. It should eventually be
 # a per-repo option, possibly a repo requirement.
@@ -609,11 +611,11 @@ 
     # updated. But this requires massive rework to matcher() and its
     # consumers.
 
-    if b'exp-sparse' in oldrequires and removing:
-        repo.requirements.discard(b'exp-sparse')
+    if repository.SPARSE_REQUIREMENT in oldrequires and removing:
+        repo.requirements.discard(repository.SPARSE_REQUIREMENT)
         scmutil.writereporequirements(repo)
-    elif b'exp-sparse' not in oldrequires:
-        repo.requirements.add(b'exp-sparse')
+    elif repository.SPARSE_REQUIREMENT not in oldrequires:
+        repo.requirements.add(repository.SPARSE_REQUIREMENT)
         scmutil.writereporequirements(repo)
 
     try:
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -816,7 +816,7 @@ 
 
     ``error.RepoError`` should be raised on failure.
     """
-    if b'exp-sparse' in requirements and not sparse.enabled:
+    if repository.SPARSE_REQUIREMENT in requirements and not sparse.enabled:
         raise error.RepoError(
             _(
                 b'repository is using sparse feature but '
@@ -1067,7 +1067,7 @@ 
         b'shared',
         b'relshared',
         b'dotencode',
-        b'exp-sparse',
+        repository.SPARSE_REQUIREMENT,
         b'internal-phase',
     }
 
diff --git a/mercurial/interfaces/repository.py b/mercurial/interfaces/repository.py
--- a/mercurial/interfaces/repository.py
+++ b/mercurial/interfaces/repository.py
@@ -15,6 +15,9 @@ 
 # we should move this to just "narrow" or similar.
 NARROW_REQUIREMENT = b'narrowhg-experimental'
 
+# Enables sparse working directory usage
+SPARSE_REQUIREMENT = b'exp-sparse'
+
 # Local repository feature string.
 
 # Revlogs are being used for file storage.