[PATCH 4 of 6 evolve-ext for-the-record] inhibit: ensure no visible changesets are obsolete after an update

Pierre-Yves David pierre-yves.david at ens-lyon.org
Wed Apr 1 18:50:11 CDT 2015


# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1427741117 25200
#      Mon Mar 30 11:45:17 2015 -0700
# Node ID 63ee05dd557aca27e17ade54987e95886d5574fb
# Parent  37c00aeb47629b0af6ca29c714dee963e055c790
inhibit: ensure no visible changesets are obsolete after an update

When updating to a commit we want to inhibit any obsolete commit affecting
the changeset we are updating to. In other words we don't want any
visible commit to be obsolete.

diff --git a/hgext/inhibit.py b/hgext/inhibit.py
--- a/hgext/inhibit.py
+++ b/hgext/inhibit.py
@@ -26,10 +26,11 @@ from mercurial import extensions
 from mercurial import cmdutil
 from mercurial import scmutil
 from mercurial import repoview
 from mercurial import revset
 from mercurial import error
+from mercurial import commands
 
 cmdtable = {}
 command = cmdutil.command(cmdtable)
 
 def reposetup(ui, repo):
@@ -46,10 +47,23 @@ def reposetup(ui, repo):
             return obsinhibit
 
     repo.__class__ = obsinhibitedrepo
     repo._explicitaccess = set()
 
+
+def _update(orig, ui, repo, *args, **kwargs):
+    """
+    When moving to a commit we want to inhibit any obsolete commit affecting
+    the changeset we are updating to. In other words we don't want any visible
+    commit to be obsolete.
+    """
+    res = orig(ui, repo, *args, **kwargs)
+    newhead = repo['.'].node()
+    _inhibitmarkers(repo, [newhead])
+    return res
+
+
 # obsolescence inhibitor
 ########################
 
 def _schedulewrite(tr, obsinhibit):
     """Make sure on disk content will be updated on transaction commit"""
@@ -135,10 +149,13 @@ def extsetup(ui):
     obsolete.cachefuncs['bumped'] = lambda repo: set()
     # wrap create marker to make it able to lift the inhibition
     extensions.wrapfunction(obsolete, 'createmarkers', _createmarkers)
     extensions.wrapfunction(repoview, '_getdynamicblockers', _accessvisible)
     extensions.wrapfunction(revset, 'posttreebuilthook', _posttreebuilthook)
+    # wrap update to make sure that no obsolete commit is visible after an
+    # update
+    extensions.wrapcommand(commands.table, 'update', _update)
 
 def gethashsymbols(tree):
     # Returns the list of symbols of the tree that look like hashes
     # for example for the revset 3::abe3ff it will return ('abe3ff')
     if not tree:
diff --git a/tests/test-inhibit.t b/tests/test-inhibit.t
--- a/tests/test-inhibit.t
+++ b/tests/test-inhibit.t
@@ -171,11 +171,67 @@ check public revision got cleared
   |
   o  4:98065434e5c6 add cE
   |
   o  0:54ccbc537fc2 add cA
   
+Update should inhibit all related unstable commits
 
+  $ hg update 2 --hidden
+  2 files updated, 0 files merged, 3 files removed, 0 files unresolved
+  working directory parent is obsolete!
+  $ hg log -G
+  o  9:55c73a90e4b4 add cJ
+  |
+  | o  7:18214586bf78 add cJ
+  |/
+  o  6:cf5c4f4554ce add cH
+  |
+  o  5:5419eb264a33 add cG
+  |
+  o  4:98065434e5c6 add cE
+  |
+  | @  2:7df62a38b9bf add cC
+  | |
+  | o  1:02bcbc3f6e56 add cB
+  |/
+  o  0:54ccbc537fc2 add cA
+  
+
+  $ hg update 9
+  4 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  $ hg log -G
+  @  9:55c73a90e4b4 add cJ
+  |
+  | o  7:18214586bf78 add cJ
+  |/
+  o  6:cf5c4f4554ce add cH
+  |
+  o  5:5419eb264a33 add cG
+  |
+  o  4:98065434e5c6 add cE
+  |
+  | o  2:7df62a38b9bf add cC
+  | |
+  | o  1:02bcbc3f6e56 add cB
+  |/
+  o  0:54ccbc537fc2 add cA
+  
+  $ hg prune --hidden 1::
+  3 changesets pruned
+  $ hg log -G
+  @  9:55c73a90e4b4 add cJ
+  |
+  | o  7:18214586bf78 add cJ
+  |/
+  o  6:cf5c4f4554ce add cH
+  |
+  o  5:5419eb264a33 add cG
+  |
+  o  4:98065434e5c6 add cE
+  |
+  o  0:54ccbc537fc2 add cA
+  
 Test that direct access make changesets visible
 
   $ hg export 2db36d8066ff 02bcbc3f6e56
   # HG changeset patch
   # User test
@@ -227,11 +283,11 @@ But only with hash
   [255]
 
 
 With severals hidden sha, rebase of one hidden stack onto another one:
   $ hg update -C 0
-  0 files updated, 0 files merged, 3 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 4 files removed, 0 files unresolved
   $ mkcommit cK
   created new head
   $ mkcommit cL
   $ hg update -C 9
   4 files updated, 0 files merged, 2 files removed, 0 files unresolved


More information about the Mercurial-devel mailing list