Patchwork [4,of,4] phases: enforce internal phase support

login
register
mail settings
Submitter Boris Feld
Date Aug. 27, 2018, 10:39 a.m.
Message ID <e3cb6b56869cd8281437.1535366396@FB-lair>
Download mbox | patch
Permalink /patch/34079/
State Accepted
Headers show

Comments

Boris Feld - Aug. 27, 2018, 10:39 a.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1527610399 -7200
#      Tue May 29 18:13:19 2018 +0200
# Node ID e3cb6b56869cd8281437a3d0c4f6f60e5cae3836
# Parent  e4923ad20f33676790657ac8e3f088180d1312d4
# EXP-Topic internal-phase.new-phase
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r e3cb6b56869c
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.
Augie Fackler - Aug. 28, 2018, 5:49 p.m.
> On Aug 27, 2018, at 6:39 AM, Boris Feld <boris.feld@octobus.net> wrote:
> 
> # HG changeset patch
> # User Boris Feld <boris.feld@octobus.net>
> # Date 1527610399 -7200
> #      Tue May 29 18:13:19 2018 +0200
> # Node ID e3cb6b56869cd8281437a3d0c4f6f60e5cae3836
> # Parent  e4923ad20f33676790657ac8e3f088180d1312d4
> # EXP-Topic internal-phase.new-phase
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r e3cb6b56869c
> phases: enforce internal phase support

queued these, thanks

Patch

diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -140,6 +140,10 @@  mutablephases = tuple(allphases[1:])
 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 @@  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=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