# HG changeset patch # User Laurent Charignon # Date 1427921481 25200 # Node ID e1347ce2f954fb5a8e8f98f454ac96a3ee8e313a # Parent 8a06b32061cede376679e19935992835e8f0973d inhibit: don't leave any obsolete commit visible after closing transaction We add a callback to wrap the transaction closure to identify commits that are obsolete and visible. We inhibit them to prevent the user to see instability in the UI. diff -r 8a06b32061ce -r e1347ce2f954 hgext/inhibit.py --- a/hgext/inhibit.py Thu Apr 02 18:33:44 2015 -0700 +++ b/hgext/inhibit.py Wed Apr 01 13:51:21 2015 -0700 @@ -47,6 +47,10 @@ obsinhibit.add(raw[i:i+20]) return obsinhibit + # Wrapping this to inhibit obsolete revs resulting from a transaction + extensions.wrapfunction(localrepo.localrepository, + 'transaction', transactioncallback) + repo.__class__ = obsinhibitedrepo repo._explicitaccess = set() @@ -136,6 +140,19 @@ finally: tr.release() + +def transactioncallback(orig, repo, *args, **kwargs): + """ Wrap localrepo.transaction to inhibit new obsolete changes """ + def inhibitposttransaction(transaction): + # At the end of the transaction we catch all the new visible and + # obsolete commit to inhibit them + visibleobsolete = repo.revs('(not hidden()) and obsolete()') + if visibleobsolete: + _inhibitmarkers(repo, [repo[r].node() for r in visibleobsolete]) + transaction = orig(repo, *args, **kwargs) + transaction.addpostclose('inhibitposttransaction', inhibitposttransaction) + return transaction + def extsetup(ui): # lets wrap the computation of the obsolete set # We apply inhibition there diff -r 8a06b32061ce -r e1347ce2f954 tests/test-inhibit.t --- a/tests/test-inhibit.t Thu Apr 02 18:33:44 2015 -0700 +++ b/tests/test-inhibit.t Wed Apr 01 13:51:21 2015 -0700 @@ -377,27 +377,99 @@ $ hg rebase -r ad78ff7d621f -r 53a94305e133 -d 2db36d8066ff rebasing 10:ad78ff7d621f "add cK" rebasing 11:53a94305e133 "add cL" - 2 new unstable changesets $ hg log -G o 13:2f7b7704d714 add cL | o 12:fe1634cbe235 add cK | - | @ 9:55c73a90e4b4 add cJ + | o 11:53a94305e133 add cL | | - | | o 7:18214586bf78 add cJ - | |/ - | o 6:cf5c4f4554ce add cH - | | - | o 5:5419eb264a33 add cG + | o 10:ad78ff7d621f add cK | | - | o 4:98065434e5c6 add cE - | | - x | 3:2db36d8066ff add cD + | | @ 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 | 3:2db36d8066ff add cD | | - x | 2:7df62a38b9bf add cC + o | 2:7df62a38b9bf add cC | | - x | 1:02bcbc3f6e56 add cB + o | 1:02bcbc3f6e56 add cB |/ o 0:54ccbc537fc2 add cA +Check that amending in the middle of a stack does not show obsolete revs + + $ hg prune 1:: + 5 changesets pruned + $ hg prune 10:: + 2 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 + + $ hg up 7 + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ mkcommit cL + $ mkcommit cM + $ mkcommit cN + $ hg log -G + @ 16:a438c045eb37 add cN + | + o 15:2d66e189f5b5 add cM + | + o 14:d66ccb8c5871 add cL + | + | 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 + | + o 0:54ccbc537fc2 add cA + + $ hg up 15 + 0 files updated, 0 files merged, 1 files removed, 0 files unresolved + $ echo "mmm" >> cM + $ hg amend + $ hg log -G + @ 18:210589181b14 add cM + | + | o 16:a438c045eb37 add cN + | | + | o 15:2d66e189f5b5 add cM + |/ + o 14:d66ccb8c5871 add cL + | + | 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 + | + o 0:54ccbc537fc2 add cA + +