Patchwork [2,of,3,evolve-ext-V2] inhibit: don't leave any obsolete commit visible after closing transaction

login
register
mail settings
Submitter Laurent Charignon
Date April 4, 2015, 12:26 a.m.
Message ID <8065190d4c129e5be0eb.1428107188@lcharignon-mbp.dhcp.thefacebook.com>
Download mbox | patch
Permalink /patch/8494/
State Accepted
Headers show

Comments

Laurent Charignon - April 4, 2015, 12:26 a.m.
# HG changeset patch
# User Laurent Charignon <lcharignon@fb.com>
# Date 1427921481 25200
#      Wed Apr 01 13:51:21 2015 -0700
# Node ID 8065190d4c129e5be0ebc062d1305efdae0d8ecb
# Parent  6b58c422fe226cd9a3b7e7362fd3da394ceaa1c1
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.

Patch

diff --git a/hgext/inhibit.py b/hgext/inhibit.py
--- a/hgext/inhibit.py
+++ b/hgext/inhibit.py
@@ -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 --git a/tests/test-inhibit.t b/tests/test-inhibit.t
--- a/tests/test-inhibit.t
+++ b/tests/test-inhibit.t
@@ -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  10:ad78ff7d621f add cK
+  | |
+  | | @  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  6:cf5c4f4554ce add cH
+  o |  3:2db36d8066ff add cD
   | |
-  | o  5:5419eb264a33 add cG
+  o |  2:7df62a38b9bf add cC
   | |
-  | o  4:98065434e5c6 add cE
-  | |
-  x |  3:2db36d8066ff add cD
-  | |
-  x |  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
+  
+