hgext/obsolete.py
changeset 218 ace5608350b6
parent 217 786eb34d93ea
child 224 f60555898df4
--- a/hgext/obsolete.py	Tue Apr 24 16:30:58 2012 +0200
+++ b/hgext/obsolete.py	Thu Apr 26 16:49:15 2012 +0200
@@ -305,7 +305,12 @@
     return outgoing
 
 def wrapcheckheads(orig, repo, remote, outgoing, *args, **kwargs):
-    """wrap mercurial.discovery.checkheads to prevent unstability to be pushed"""
+    """wrap mercurial.discovery.checkheads
+
+    * prevent unstability to be pushed
+    * patch remote to ignore obsolete heads on remote
+    """
+    # do not push instability
     for h in outgoing.missingheads:
         # checking heads only is enought because any thing base on obsolete
         # changeset is either obsolete or unstable.
@@ -317,7 +322,58 @@
         if ctx.obsolete():
             raise util.Abort(_("Trying to push obsolete changeset: %s!") % ctx,
                              hint=hint)
-    return orig(repo, remote, outgoing, *args, **kwargs)
+    ### patch remote branch map
+    # do not read it this burn eyes
+    try:
+        if 'oldbranchmap' not in vars(remote):
+            remote.oldbranchmap = remote.branchmap
+            def branchmap():
+                newbm = {}
+                oldbm = None
+                if (util.safehasattr(phases, 'visiblebranchmap')
+                    and not util.safehasattr(remote, 'ignorevisiblebranchmap')
+                   ):
+                    remote.ignorevisiblebranchmap = False
+                    remote.branchmap = remote.oldbranchmap
+                    oldbm = phases.visiblebranchmap(remote)
+                    remote.branchmap = remote.newbranchmap
+                    remote.ignorevisiblebranchmap = True
+                if oldbm is None:
+                    oldbm = remote.oldbranchmap()
+                for branch, nodes in oldbm.iteritems():
+                    nodes = list(nodes)
+                    new = set()
+                    while nodes:
+                        n = nodes.pop()
+                        if n in repo._obsobjrels:
+                            newernodes = repo._obsobjrels[n]
+                            for newernode in newernodes:
+                                if newernode is not None:
+                                    nodes.append(newernode)
+                        else:
+                            new.add(n)
+                    if new:
+                        newbm[branch] = list(new)
+                return newbm
+            remote.ignorevisiblebranchmap = True
+            remote.branchmap = branchmap
+            remote.newbranchmap = branchmap
+        return orig(repo, remote, outgoing, *args, **kwargs)
+    finally:
+        remote.__dict__.pop('branchmap', None) # restore class one
+        remote.__dict__.pop('oldbranchmap', None)
+        remote.__dict__.pop('newbranchmap', None)
+        remote.__dict__.pop('ignorevisiblebranchmap', None)
+
+# eye are still burning
+def wrapvisiblebranchmap(orig, repo):
+    ignore = getattr(repo, 'ignorevisiblebranchmap', None)
+    if ignore is None:
+        return orig(repo)
+    elif ignore:
+        return repo.branchmap()
+    else:
+        return None # break recursion
 
 
 ### New commands
@@ -349,6 +405,8 @@
     extensions.wrapcommand(commands.table, "pull", wrapmayobsoletewc)
     extensions.wrapfunction(discovery, 'findcommonoutgoing', wrapfindcommonoutgoing)
     extensions.wrapfunction(discovery, 'checkheads', wrapcheckheads)
+    if util.safehasattr(phases, 'visiblebranchmap'):
+        extensions.wrapfunction(phases, 'visiblebranchmap', wrapvisiblebranchmap)
 
 ### serialisation
 #############################