Patchwork [15,of,25,RFC] phase: enforce internal phase support

login
register
mail settings
Submitter Boris Feld
Date June 7, 2018, 2:11 p.m.
Message ID <ef202521c3c3389198ff.1528380674@Laptop-Boris.lan>
Download mbox | patch
Permalink /patch/32009/
State New
Headers show

Comments

Boris Feld - June 7, 2018, 2:11 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1527610399 -7200
#      Tue May 29 18:13:19 2018 +0200
# Node ID ef202521c3c3389198ff917e11dcb7847de3658d
# Parent  d6ac390e2ebdf51f095168fe314dd956db09e2b9
# EXP-Topic internal-phase
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r ef202521c3c3
phase: enforce internal phase support

We should not use the internal phase for repository without the requirement.
Otherwise older client 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.

Patch

diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -130,6 +130,10 @@  mutablephases = tuple(allphases[1:])
 remotehiddenphases = tuple(allphases[2:])
 localhiddenphases = tuple(allphases[3:])
 
+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
 
@@ -422,6 +426,9 @@  class phasecache(object):
     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]
diff --git a/tests/test-phases.t b/tests/test-phases.t
--- a/tests/test-phases.t
+++ b/tests/test-phases.t
@@ -832,8 +832,38 @@  Try various actions. only the draft move
 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=3" 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