[PATCH] phase: add an archived phases

Boris Feld boris.feld at octobus.net
Wed Oct 17 15:57:18 UTC 2018


# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1539780421 -7200
#      Wed Oct 17 14:47:01 2018 +0200
# Node ID 12dd6c5ad6ba17fa4f98f4009bc0b53a7f7f5f8b
# Parent  5644f7c8982e805e53f56fcbfe0322e9de58a934
# EXP-Topic archived-phase
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 12dd6c5ad6ba
phase: add an archived phases

This phase allows for hidden changesets in the "user space". It differs from
the "internal" phase which is intended for internal by-product only. There
have been discussions at the 4.8 sprint to use such phase to speedup cleanup
after history rewriting operation.

Shipping it in the same release as the 'internal-phase' groups the associated
`requires` entry. The important bit is to have support for this phase in the
earliest version of mercurial possible. Adding the UI to manipulate this new
phase later seems fine.

The current plan for archived usage and user interface are as follow. On a
repository with internal-phase on and evolution off:

* history rewriting command set rewritten changeset in the archived phase.
  (This mean updating the cleanupnodes method).
* keep `hg unbundle .hg/strip-backup/X.hg` as a way to restore changeset for
  now
  (backup bundle need to contains phase data)
* [maybe] add a `hg strip --soft` advance flag
  (a light way to expose the feature without getting in the way of a better
  UI)

Mercurial 4.8 freeze is too close to get the above in by then. However, having
a consistency `requirement` meaning would be nice.

diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -129,11 +129,13 @@ HIDEABLE_FLAG = 32 # Phases that are hid
 # record phase index
 public, draft, secret = range(3)
 internal = INTERNAL_FLAG | HIDEABLE_FLAG
+archived = HIDEABLE_FLAG
 allphases = range(internal + 1)
 trackedphases = allphases[1:]
 # record phase names
 phasenames = [None] * len(allphases)
 phasenames[:3] = ['public', 'draft', 'secret']
+phasenames[archived] = 'archived'
 phasenames[internal] = 'internal'
 # record phase property
 mutablephases = tuple(allphases[1:])
@@ -446,8 +448,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'
+        if targetphase in (archived, internal) and not supportinternal(repo):
+            name = phasenames[targetphase]
+            msg = 'this repository does not support the %s phase' % name
             raise error.ProgrammingError(msg)
 
         repo = repo.unfiltered()
diff --git a/tests/test-phases.t b/tests/test-phases.t
--- a/tests/test-phases.t
+++ b/tests/test-phases.t
@@ -850,6 +850,10 @@ Check we deny its usage on older reposit
   ** ProgrammingError: this repository does not support the internal phase
       raise error.ProgrammingError(msg)
   mercurial.error.ProgrammingError: this repository does not support the internal phase
+  $ hg --config "phases.new-commit=archived" commit -m "my test archived commit" 2>&1 | grep ProgrammingError
+  ** ProgrammingError: this repository does not support the archived phase
+      raise error.ProgrammingError(msg)
+  mercurial.error.ProgrammingError: this repository does not support the archived phase
 
   $ cd ..
 
@@ -878,7 +882,8 @@ Commit an internal changesets
   test-debug-phase: new rev 1:  x -> 96
   test-hook-close-phase: c01c42dffc7f81223397e99652a0703f83e1c5ea:   -> internal
 
-Usual visibility rules apply when working directory parents
+The changeset is a working parent descendant.
+Per the usual visibility rules, it is made visible.
 
   $ hg log -G -l 3
   @  changeset:   1:c01c42dffc7f
@@ -904,3 +909,45 @@ Commit is hidden as expected
      date:        Thu Jan 01 00:00:00 1970 +0000
      summary:     A
   
+
+Test for archived phase
+-----------------------
+
+Commit an archived changesets
+
+  $ echo B > B
+  $ hg add B
+  $ hg status
+  A B
+  $ hg --config "phases.new-commit=archived" commit -m "my test archived commit"
+  test-debug-phase: new rev 2:  x -> 32
+  test-hook-close-phase: 8df5997c3361518f733d1ae67cd3adb9b0eaf125:   -> archived
+
+The changeset is a working parent descendant.
+Per the usual visibility rules, it is made visible.
+
+  $ hg log -G -l 3
+  @  changeset:   2:8df5997c3361
+  |  tag:         tip
+  |  parent:      0:4a2df7238c3b
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     my test archived commit
+  |
+  o  changeset:   0:4a2df7238c3b
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     A
+  
+
+Commit is hidden as expected
+
+  $ hg up 0
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg log -G
+  @  changeset:   0:4a2df7238c3b
+     tag:         tip
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     A
+  


More information about the Mercurial-devel mailing list