Patchwork [13,of,25,RFC] phase: add an internal phases

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

Comments

Boris Feld - June 7, 2018, 2:11 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1527092946 -7200
#      Wed May 23 18:29:06 2018 +0200
# Node ID e7b11679c4b43c3933bda699fc387bbfd496762e
# Parent  08a0b07117c200dda12c721bf60bc27e9541feb1
# EXP-Topic internal-phase
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r e7b11679c4b4
phase: add an internal phases

The phase is meant to be use for internal commit that are a byproduct of command
operation (eg:shelve).

This changeset focus on getting the most important feature in, more advance API
is to be introduced in later changesets.

The phase approach to handle internal has multiple advantages:
* simple to implement, reuse optimized code,
* fits well with existing phases. We don't want internal changeset to be
  exchanged or served
* easy to extend to for lifecycle handling.

More thinking about internal changeset at https://www.mercurial-scm.org/wiki/InternalsPlan

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3912,7 +3912,7 @@  def phase(ui, repo, *revs, **opts):
     # search for a unique phase argument
     targetphase = None
     for idx, name in enumerate(phases.phasenames):
-        if opts[name]:
+        if opts.get(name, False):
             if targetphase is not None:
                 raise error.Abort(_('only one phase can be specified'))
             targetphase = idx
diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -123,11 +123,12 @@  from . import (
 
 _fphasesentry = struct.Struct('>i20s')
 
-allphases = public, draft, secret = range(3)
+allphases = public, draft, secret, internal = range(4)
 trackedphases = allphases[1:]
-phasenames = ['public', 'draft', 'secret']
+phasenames = ['public', 'draft', 'secret', 'internal']
 mutablephases = tuple(allphases[1:])
 remotehiddenphases = tuple(allphases[2:])
+localhiddenphases = tuple(allphases[3:])
 
 def _readroots(repo, phasedefaults=None):
     """Read phase roots from disk
diff --git a/mercurial/repoview.py b/mercurial/repoview.py
--- a/mercurial/repoview.py
+++ b/mercurial/repoview.py
@@ -28,7 +28,10 @@  def hideablerevs(repo):
     branchmap (see mercurial.branchmap.subsettable), you cannot set "public"
     changesets as "hideable". Doing so would break multiple code assertions and
     lead to crashes."""
-    return obsolete.getrevs(repo, 'obsolete')
+    obsoletes = obsolete.getrevs(repo, 'obsolete')
+    internals = repo._phasecache.getrevset(repo, phases.localhiddenphases)
+    internals = frozenset(internals)
+    return obsoletes | internals
 
 def pinnedrevs(repo):
     """revisions blocking hidden changesets from being filtered
diff --git a/tests/test-phases.t b/tests/test-phases.t
--- a/tests/test-phases.t
+++ b/tests/test-phases.t
@@ -826,3 +826,51 @@  Try various actions. only the draft move
   rollback completed
   abort: pretxnclose-phase.nopublish_D hook exited with status 1
   [255]
+
+  $ cd ..
+
+Test for the "internal" phase
+=============================
+
+  $ hg init internal-phase
+  $ cd internal-phase
+  $ mkcommit A
+  test-debug-phase: new rev 0:  x -> 1
+  test-hook-close-phase: 4a2df7238c3b48766b5e22fafbb8a2f506ec8256:   -> draft
+
+Commit an internal changesets
+
+  $ echo B > B
+  $ hg add B
+  $ hg status
+  A B
+  $ hg --config "phases.new-commit=3" commit -m "my test internal commit"
+  test-debug-phase: new rev 1:  x -> 3
+  test-hook-close-phase: c01c42dffc7f81223397e99652a0703f83e1c5ea:   -> internal
+
+Usual visibility rules apply when working directory parents
+
+  $ hg log -G -l 3
+  @  changeset:   1:c01c42dffc7f
+  |  tag:         tip
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     my test internal 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
+