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

login
register
mail settings
Submitter Laurent Charignon
Date April 3, 2015, 2:09 a.m.
Message ID <efcfb550ae9a38972af9.1428026997@lcharignon-mbp.dhcp.thefacebook.com>
Download mbox | patch
Permalink /patch/8466/
State Changes Requested
Headers show

Comments

Laurent Charignon - April 3, 2015, 2:09 a.m.
# HG changeset patch
# User Laurent Charignon <lcharignon@fb.com>
# Date 1427921481 25200
#      Wed Apr 01 13:51:21 2015 -0700
# Node ID efcfb550ae9a38972af97d25c841b1d1d132f499
# Parent  89b46ecc6bcfec588667eec38e6ce85ea002b82b
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.
Pierre-Yves David - April 3, 2015, 6:48 p.m.
On 04/02/2015 07:09 PM, Laurent Charignon wrote:
> # HG changeset patch
> # User Laurent Charignon <lcharignon@fb.com>
> # Date 1427921481 25200
> #      Wed Apr 01 13:51:21 2015 -0700
> # Node ID efcfb550ae9a38972af97d25c841b1d1d132f499
> # Parent  89b46ecc6bcfec588667eec38e6ce85ea002b82b
> 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 --git a/hgext/inhibit.py b/hgext/inhibit.py
> --- a/hgext/inhibit.py
> +++ b/hgext/inhibit.py
> @@ -21,6 +21,7 @@
>   to XXX.
>   """
>   from mercurial import localrepo
> +from mercurial import transaction

unused import ?

>   from mercurial import obsolete
>   from mercurial import extensions
>   from mercurial import cmdutil
> @@ -47,6 +48,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 +141,20 @@
>       finally:
>           tr.release()
>
> +
> +def transactioncallback(orig, repo, *args, **kwargs):
> +    """ This wraps localrepo.transaction to inhibit any obsolete changes
> +    resulting from any transaction """

small nits: python docstring are usually in the form

   short summary

   Longer explanation
   on multiple line

(just like commit message actually ;-) )

> +    def callback(transaction):

Small nits: callback is going to be a terrible name in a traceback. 
Using something more informative will give more clue to the poor soul 
that will get to debug something in there.
(no need to change it, just pointing that out for next time)

> +        """ 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', callback)

I though you had some specific needs in terms of ordering?

Patch

diff --git a/hgext/inhibit.py b/hgext/inhibit.py
--- a/hgext/inhibit.py
+++ b/hgext/inhibit.py
@@ -21,6 +21,7 @@ 
 to XXX.
 """
 from mercurial import localrepo
+from mercurial import transaction
 from mercurial import obsolete
 from mercurial import extensions
 from mercurial import cmdutil
@@ -47,6 +48,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 +141,20 @@ 
     finally:
         tr.release()
 
+
+def transactioncallback(orig, repo, *args, **kwargs):
+    """ This wraps localrepo.transaction to inhibit any obsolete changes 
+    resulting from any transaction """
+    def callback(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', callback)
+    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
@@ -366,27 +366,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
+  
+