obsolete.py
changeset 44 b243c10a5fbe
parent 43 20fca307d9f0
child 46 3b0364fc822f
--- a/obsolete.py	Thu Sep 08 12:00:39 2011 +0200
+++ b/obsolete.py	Thu Sep 08 12:01:38 2011 +0200
@@ -11,6 +11,7 @@
 from mercurial import revset
 from mercurial import scmutil
 from mercurial import extensions
+from mercurial import pushkey
 from mercurial.node import hex, bin
 
 # Patch changectx
@@ -53,6 +54,24 @@
     except KeyError:
         pass # rebase not found
 
+# Pushkey mechanism for mutable
+#########################################
+
+def pushobsolete(repo, key, old, relations):
+    assert key == "relations"
+    w = repo.wlock()
+    try:
+        for sub, objs in relations.iteritems():
+            for obj in objs:
+                repo.addobsolete(sub, obj)
+    finally:
+        w.release()
+
+def listobsolete(repo):
+    return {'relations': repo._obssubrels}
+
+pushkey.register('obsolete', pushobsolete, listobsolete)
+
 # New commands
 #############################
 
@@ -70,6 +89,9 @@
 
 def reposetup(ui, repo):
 
+    opull = repo.pull
+    opush = repo.push
+
     class obsoletingrepo(repo.__class__):
 
 
@@ -128,6 +150,26 @@
             finally:
                 f.close()
 
+        ### pull // push support
+
+        def pull(self, remote, *args, **kwargs):
+            obskey = remote.listkeys('obsolete')
+            obsrels = obskey.get('relations', {})
+            result = opull(remote, *args, **kwargs)
+            for sub, objs in obsrels.iteritems():
+                for obj in objs:
+                    self.addobsolete(sub, obj)
+            return result
+
+        def push(self, remote, *args, **opts):
+            obskey = remote.listkeys('obsolete')
+            obssupport = 'relations' in obskey
+            result = opush(remote, *args, **opts)
+            if obssupport:
+                remote.pushkey('obsolete', 'relations', {}, self._obssubrels)
+            return result
+
+
         ### Public method
         def obsoletedby(self, node):
             """return the set of node that make <node> obsolete (obj)"""