# HG changeset patch # User Boris Feld # Date 2018-05-29 16:13:19 # Node ID 7775c1fb8fa0d67f16d4b3c89ce3aacd35074506 # Parent 7a9f15ed3b9617c0116d73a05df5bcf0b44f0c7b 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. 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