phases: enforce internal phase support
We should not use the internal phase for repository without the requirement.
Otherwise, older clients could have a look at the repository and see the
internal changesets.
For now, we introduce a low-level Programming error, more UI friendly error
will be introduced later.
--- a/mercurial/phases.py Thu May 24 09:59:10 2018 +0200
+++ b/mercurial/phases.py Tue May 29 18:13:19 2018 +0200
@@ -140,6 +140,10 @@
remotehiddenphases = tuple(allphases[2:])
localhiddenphases = tuple(p for p in allphases if p & HIDEABLE_FLAG)
+def supportinternal(repo):
+ """True if the internal phase can be used on a repository"""
+ return 'internal-phase' in repo.requirements
+
def _readroots(repo, phasedefaults=None):
"""Read phase roots from disk
@@ -442,6 +446,9 @@
def _retractboundary(self, repo, tr, targetphase, nodes):
# Be careful to preserve shallow-copied values: do not update
# phaseroots values, replace them.
+ if targetphase == internal and not supportinternal(repo):
+ msg = 'this repository does not support the internal phase'
+ raise error.ProgrammingError(msg)
repo = repo.unfiltered()
currentroots = self.phaseroots[targetphase]
--- a/tests/test-phases.t Thu May 24 09:59:10 2018 +0200
+++ b/tests/test-phases.t Tue May 29 18:13:19 2018 +0200
@@ -832,8 +832,38 @@
Test for the "internal" phase
=============================
- $ hg init internal-phase
+Check we deny its usage on older repository
+
+ $ hg init no-internal-phase --config format.internal-phase=no
+ $ cd no-internal-phase
+ $ cat .hg/requires
+ dotencode
+ fncache
+ generaldelta
+ revlogv1
+ store
+ $ echo X > X
+ $ hg add X
+ $ hg status
+ A X
+ $ hg --config "phases.new-commit=internal" commit -m "my test internal commit" 2>&1 | grep ProgrammingError
+ ** ProgrammingError: this repository does not support the internal phase
+ raise error.ProgrammingError(msg)
+ mercurial.error.ProgrammingError: this repository does not support the internal phase
+
+ $ cd ..
+
+Check it works fine with repository that supports it.
+
+ $ hg init internal-phase --config format.internal-phase=yes
$ cd internal-phase
+ $ cat .hg/requires
+ dotencode
+ fncache
+ generaldelta
+ internal-phase
+ revlogv1
+ store
$ mkcommit A
test-debug-phase: new rev 0: x -> 1
test-hook-close-phase: 4a2df7238c3b48766b5e22fafbb8a2f506ec8256: -> draft