[Updated] [+++- ] D8633: share: introduce config option to store requires in .hg/store
pulkit (Pulkit Goyal)
phabricator at mercurial-scm.org
Mon Aug 10 15:28:33 UTC 2020
pulkit updated this revision to Diff 22381.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D8633?vs=22328&id=22381
BRANCH
default
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D8633/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D8633
AFFECTED FILES
mercurial/configitems.py
mercurial/localrepo.py
mercurial/requirements.py
mercurial/scmutil.py
mercurial/store.py
tests/test-journal-share.t
tests/test-narrow-share.t
tests/test-remotefilelog-share.t
tests/test-share-bookmarks.t
tests/test-share-safe.t
tests/test-share.t
CHANGE DETAILS
diff --git a/tests/test-share.t b/tests/test-share.t
--- a/tests/test-share.t
+++ b/tests/test-share.t
@@ -1,3 +1,10 @@
+#testcases safe normal
+
+#if safe
+ $ echo "[format]" >> $HGRCPATH
+ $ echo "exp-share-safe = True" >> $HGRCPATH
+#endif
+
$ echo "[extensions]" >> $HGRCPATH
$ echo "share = " >> $HGRCPATH
@@ -255,6 +262,7 @@
Test sharing a repository which was created with store requirement disable
$ hg init nostore --config format.usestore=false
+ ignoring enabled 'format.exp-share-safe' config because it is incompatible with disabled 'format.usestore' config (safe !)
$ hg share nostore sharednostore
abort: cannot create shared repository as source was created with 'format.usestore' config disabled
[255]
diff --git a/tests/test-share-safe.t b/tests/test-share-safe.t
new file mode 100644
--- /dev/null
+++ b/tests/test-share-safe.t
@@ -0,0 +1,69 @@
+setup
+
+ $ cat >> $HGRCPATH <<EOF
+ > [extensions]
+ > share =
+ > [format]
+ > exp-share-safe = True
+ > EOF
+
+prepare source repo
+
+ $ hg init source
+ $ cd source
+ $ cat .hg/requires
+ exp-sharesafe
+ $ cat .hg/store/requires
+ dotencode
+ fncache
+ generaldelta
+ revlogv1
+ sparserevlog
+ store
+ $ hg debugrequirements
+ dotencode
+ exp-sharesafe
+ fncache
+ generaldelta
+ revlogv1
+ sparserevlog
+ store
+
+ $ echo a > a
+ $ hg ci -Aqm "added a"
+ $ echo b > b
+ $ hg ci -Aqm "added b"
+ $ cd ..
+
+Create a shared repo and check the requirements are shared and read correctly
+ $ hg share source shared1
+ updating working directory
+ 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ $ cd shared1
+ $ cat .hg/requires
+ exp-sharesafe
+ shared
+
+ $ hg debugrequirements -R ../source
+ dotencode
+ exp-sharesafe
+ fncache
+ generaldelta
+ revlogv1
+ sparserevlog
+ store
+
+ $ hg debugrequirements
+ dotencode
+ exp-sharesafe
+ fncache
+ generaldelta
+ revlogv1
+ shared
+ sparserevlog
+ store
+
+ $ echo c > c
+ $ hg ci -Aqm "added c"
+
+ $ hg unshare
diff --git a/tests/test-share-bookmarks.t b/tests/test-share-bookmarks.t
--- a/tests/test-share-bookmarks.t
+++ b/tests/test-share-bookmarks.t
@@ -1,4 +1,10 @@
#testcases vfs svfs
+#testcases safe normal
+
+#if safe
+ $ echo "[format]" >> $HGRCPATH
+ $ echo "exp-share-safe = True" >> $HGRCPATH
+#endif
$ echo "[extensions]" >> $HGRCPATH
$ echo "share = " >> $HGRCPATH
@@ -284,3 +290,4 @@
$ hg init brokenrepo --config format.bookmarks-in-store=True --config format.usestore=false
ignoring enabled 'format.bookmarks-in-store' config beacuse it is incompatible with disabled 'format.usestore' config
+ ignoring enabled 'format.exp-share-safe' config because it is incompatible with disabled 'format.usestore' config (safe !)
diff --git a/tests/test-remotefilelog-share.t b/tests/test-remotefilelog-share.t
--- a/tests/test-remotefilelog-share.t
+++ b/tests/test-remotefilelog-share.t
@@ -1,5 +1,12 @@
#require no-windows
+#testcases safe normal
+
+#if safe
+ $ echo "[format]" >> $HGRCPATH
+ $ echo "exp-share-safe = True" >> $HGRCPATH
+#endif
+
$ . "$TESTDIR/remotefilelog-library.sh"
$ cat >> $HGRCPATH <<EOF
diff --git a/tests/test-narrow-share.t b/tests/test-narrow-share.t
--- a/tests/test-narrow-share.t
+++ b/tests/test-narrow-share.t
@@ -1,4 +1,10 @@
#testcases flat tree
+#testcases safe normal
+
+#if safe
+ $ echo "[format]" >> $HGRCPATH
+ $ echo "exp-share-safe = True" >> $HGRCPATH
+#endif
$ . "$TESTDIR/narrow-library.sh"
diff --git a/tests/test-journal-share.t b/tests/test-journal-share.t
--- a/tests/test-journal-share.t
+++ b/tests/test-journal-share.t
@@ -1,3 +1,10 @@
+#testcases safe normal
+
+#if safe
+ $ echo "[format]" >> $HGRCPATH
+ $ echo "exp-share-safe = True" >> $HGRCPATH
+#endif
+
Journal extension test: tests the share extension support
$ cat >> testmocks.py << EOF
diff --git a/mercurial/store.py b/mercurial/store.py
--- a/mercurial/store.py
+++ b/mercurial/store.py
@@ -384,6 +384,7 @@
b'00changelog.i',
b'phaseroots',
b'obsstore',
+ b'requires',
]
@@ -455,7 +456,7 @@
yield x
def copylist(self):
- return [b'requires'] + _data
+ return _data
def write(self, tr):
pass
@@ -704,6 +705,7 @@
b'00manifest.i',
b'00changelog.d',
b'00changelog.i',
+ b'requires',
)
return [b'requires', b'00changelog.i'] + [b'store/' + f for f in d]
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -1479,7 +1479,7 @@
Returns (wcreq, storereq)
"""
- if False:
+ if requirementsmod.SHARESAFE_REQUIREMENT in requirements:
wc, store = set(), set()
for r in requirements:
if r in requirementsmod.WORKING_DIR_REQUIREMENTS:
diff --git a/mercurial/requirements.py b/mercurial/requirements.py
--- a/mercurial/requirements.py
+++ b/mercurial/requirements.py
@@ -45,7 +45,14 @@
# The repository use persistent nodemap for the changelog and the manifest.
NODEMAP_REQUIREMENT = b'persistent-nodemap'
+# A repository with share implemented safely. The repository has different
+# store and working copy requirements i.e. both `.hg/requires` and
+# `.hg/store/requires` are present.
+SHARESAFE_REQUIREMENT = b'exp-sharesafe'
+
# List of requirements which are working directory specific
# These requirements cannot be shared between repositories if they
# share the same store
-WORKING_DIR_REQUIREMENTS = set([SPARSE_REQUIREMENT])
\ No newline at end of file
+# SHARESAFE_REQUIREMENT needs to be stored in working dir to mark that rest of
+# the requirements are stored in store's requires
+WORKING_DIR_REQUIREMENTS = set([SPARSE_REQUIREMENT, SHARESAFE_REQUIREMENT])
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -543,6 +543,20 @@
raise error.RepoError(_(b'repository %s not found') % path)
requirements = _readrequires(hgvfs, True)
+ shared = b'shared' in requirements or b'relshared' in requirements
+ if shared:
+ sharedvfs = _getsharedvfs(hgvfs, requirements)
+
+ # if .hg/requires contains the sharesafe requirement, it means
+ # there exists a `.hg/store/requires` too and we should read it
+ if requirementsmod.SHARESAFE_REQUIREMENT in requirements:
+ if shared:
+ # This is a shared repo
+ storevfs = vfsmod.vfs(sharedvfs.join(b'store'))
+ else:
+ storevfs = vfsmod.vfs(hgvfs.join(b'store'), cacheaudited=True)
+
+ requirements |= _readrequires(storevfs, False)
# The .hg/hgrc file may load extensions or contain config options
# that influence repository construction. Attempt to load it and
@@ -585,9 +599,7 @@
# accessed is determined by various requirements. If `shared` or
# `relshared` requirements are present, this indicates current repository
# is a share and store exists in path mentioned in `.hg/sharedpath`
- shared = b'shared' in requirements or b'relshared' in requirements
if shared:
- sharedvfs = _getsharedvfs(hgvfs, requirements)
storebasepath = sharedvfs.base
cachepath = sharedvfs.join(b'cache')
features.add(repository.REPO_FEATURE_SHARED_STORAGE)
@@ -1043,6 +1055,7 @@
requirementsmod.SPARSEREVLOG_REQUIREMENT,
requirementsmod.NODEMAP_REQUIREMENT,
bookmarks.BOOKMARKS_IN_STORE_REQUIREMENT,
+ requirementsmod.SHARESAFE_REQUIREMENT,
}
_basesupported = supportedformats | {
b'store',
@@ -3321,6 +3334,11 @@
if ui.configbool(b'format', b'use-persistent-nodemap'):
requirements.add(requirementsmod.NODEMAP_REQUIREMENT)
+ # if share-safe is enabled, let's create the new repository with the new
+ # requirement
+ if ui.configbool(b'format', b'exp-share-safe'):
+ requirements.add(requirementsmod.SHARESAFE_REQUIREMENT)
+
return requirements
@@ -3351,6 +3369,16 @@
)
)
+ if requirementsmod.SHARESAFE_REQUIREMENT in requirements:
+ ui.warn(
+ _(
+ b"ignoring enabled 'format.exp-share-safe' config because "
+ b"it is incompatible with disabled 'format.usestore'"
+ b" config\n"
+ )
+ )
+ dropped.add(requirementsmod.SHARESAFE_REQUIREMENT)
+
return dropped
@@ -3475,7 +3503,26 @@
b'layout',
)
- scmutil.writerequires(hgvfs, requirements)
+ if (
+ requirementsmod.SHARESAFE_REQUIREMENT in requirements
+ and b'store' in requirements
+ ):
+ if b'sharedrepo' in createopts:
+ req = set([b'shared', requirementsmod.SHARESAFE_REQUIREMENT])
+ if b'relshared' in requirements:
+ req.add(b'relshared')
+ scmutil.writerequires(hgvfs, req)
+ else:
+ scmutil.writerequires(
+ hgvfs, set([requirementsmod.SHARESAFE_REQUIREMENT])
+ )
+ storevfs = vfsmod.vfs(hgvfs.join(b'store'), cacheaudited=True)
+ scmutil.writerequires(
+ storevfs,
+ requirements - set([requirementsmod.SHARESAFE_REQUIREMENT]),
+ )
+ else:
+ scmutil.writerequires(hgvfs, requirements)
# Write out file telling readers where to find the shared store.
if b'sharedrepo' in createopts:
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -784,6 +784,9 @@
b'format', b'exp-use-side-data', default=False, experimental=True,
)
coreconfigitem(
+ b'format', b'exp-share-safe', default=False, experimental=True,
+)
+coreconfigitem(
b'format', b'internal-phase', default=False, experimental=True,
)
coreconfigitem(
To: pulkit, #hg-reviewers, durin42, marmoute
Cc: indygreg, marmoute, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20200810/0e55985e/attachment-0002.html>
More information about the Mercurial-patches
mailing list