Patchwork [5,of,6,evolve-ext,for-the-record] inhibit: ensure that no obsolete changesets are visible after a bookmark change

login
register
mail settings
Submitter Pierre-Yves David
Date April 1, 2015, 11:50 p.m.
Message ID <c15d4677f2ba946c6238.1427932212@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/8435/
State Accepted
Headers show

Comments

Pierre-Yves David - April 1, 2015, 11:50 p.m.
# HG changeset patch
# User Laurent Charignon <lcharignon@fb.com>
# Date 1427747469 25200
#      Mon Mar 30 13:31:09 2015 -0700
# Node ID c15d4677f2ba946c62387fe1ec27d383aa3274a9
# Parent  63ee05dd557aca27e17ade54987e95886d5574fb
inhibit: ensure that no obsolete changesets are visible after a bookmark change

When creating a bookmark, we could reveal obsolete changesets. We are
inhibiting the obsolete changesets resulting from a bookmark change.
There are two ways to record bookmark changes to disk and we wrap both.

Patch

diff --git a/hgext/inhibit.py b/hgext/inhibit.py
--- a/hgext/inhibit.py
+++ b/hgext/inhibit.py
@@ -27,10 +27,11 @@  from mercurial import cmdutil
 from mercurial import scmutil
 from mercurial import repoview
 from mercurial import revset
 from mercurial import error
 from mercurial import commands
+from mercurial import bookmarks
 
 cmdtable = {}
 command = cmdutil.command(cmdtable)
 
 def reposetup(ui, repo):
@@ -59,10 +60,16 @@  def _update(orig, ui, repo, *args, **kwa
     res = orig(ui, repo, *args, **kwargs)
     newhead = repo['.'].node()
     _inhibitmarkers(repo, [newhead])
     return res
 
+def _bookmarkchanged(orig, bkmstoreinst, *args, **kwargs):
+    """ Add inhibition markers to every obsolete bookmarks """
+    repo = bkmstoreinst._repo
+    bkmstorenodes = [repo[v].node() for v in bkmstoreinst.values()]
+    _inhibitmarkers(repo, bkmstorenodes)
+    return orig(bkmstoreinst, *args, **kwargs)
 
 # obsolescence inhibitor
 ########################
 
 def _schedulewrite(tr, obsinhibit):
@@ -152,10 +159,15 @@  def extsetup(ui):
     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)
+    # There are two ways to save bookmark changes during a transation, we
+    # wrap both to add inhibition markers.
+    extensions.wrapfunction(bookmarks.bmstore, 'recordchange', _bookmarkchanged)
+    extensions.wrapfunction(bookmarks.bmstore, 'write', _bookmarkchanged)
+
 
 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
@@ -228,10 +228,46 @@  Update should inhibit all related unstab
   |
   o  4:98065434e5c6 add cE
   |
   o  0:54ccbc537fc2 add cA
   
+
+Bookmark should inhibit all related unstable commits
+  $ hg bookmark -r 2 book1  --hidden
+  $ 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 bookmark -d book1
+  $ 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