Add pushkey support for pull and push
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Thu, 08 Sep 2011 12:01:38 +0200
changeset 44 b243c10a5fbe
parent 43 20fca307d9f0
child 45 d89453a10991
Add pushkey support for pull and push
obsolete.py
tests/test-obsolete.t
--- 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)"""
--- a/tests/test-obsolete.t	Thu Sep 08 12:00:39 2011 +0200
+++ b/tests/test-obsolete.t	Thu Sep 08 12:01:38 2011 +0200
@@ -4,13 +4,14 @@
   > allow_push = *
   > [extensions]
   > EOF
-  $ echo "states=$(echo $(dirname $TESTDIR))/obsolete.py" >> $HGRCPATH
+  $ echo "obsolete=$(echo $(dirname $TESTDIR))/obsolete.py" >> $HGRCPATH
   $ mkcommit() {
   >    echo "$1" > "$1"
   >    hg add "$1"
   >    hg ci -m "add $1"
   > }
 
+  $ alias qlog="hg log --template='{rev}\n'"
   $ hg init local
   $ cd local
   $ mkcommit a # 0
@@ -118,3 +119,98 @@
   summary:     add obsol_c
   
 
+Test communication of obsolete relation with a compatible client
+
+  $ hg init ../other-new
+  $ hg push ../other-new
+  pushing to ../other-new
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 6 changesets with 6 changes to 6 files (+2 heads)
+  $ hg -R ../other-new log -r 'obsolete()'
+  changeset:   3:0d3f46688ccc
+  parent:      1:7c3bad9141dc
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     add obsol_c
+  
+  $ hg -R ../other-new log
+  changeset:   5:a7a6f2b5d8a5
+  tag:         tip
+  parent:      3:0d3f46688ccc
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     add d
+  
+  changeset:   4:725c380fe99b
+  parent:      1:7c3bad9141dc
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     add obsol_c'
+  
+  changeset:   3:0d3f46688ccc
+  parent:      1:7c3bad9141dc
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     add obsol_c
+  
+  changeset:   1:7c3bad9141dc
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     add b
+  
+  changeset:   0:1f0dee641bb7
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     add a
+  
+  $ hg up 3 -q
+  $ mkcommit obsol_d # 6
+  created new head
+  $ hg debugobsolete 6 5
+  $ qlog
+  6
+  4
+  3
+  1
+  0
+  $ qlog -r 'obsolete()'
+  3
+  $ hg push ../other-new -f # XXX should not have to use -f
+  pushing to ../other-new
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files (+1 heads)
+  $ qlog -R ../other-new
+  6
+  4
+  3
+  1
+  0
+  $ qlog -R ../other-new -r 'obsolete()'
+  3
+  $ hg up -q .^
+  $ mkcommit "obsol_d'" # 7
+  created new head
+  $ hg debugobsolete 7 6
+  $ hg pull -R ../other-new .
+  pulling from .
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files (+1 heads)
+  (run 'hg heads .' to see heads, 'hg merge' to merge)
+  $ qlog -R ../other-new
+  7
+  4
+  3
+  1
+  0
+
+
+