Do not propagate obsolete changeset
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Thu, 08 Sep 2011 16:46:58 +0200
changeset 46 3b0364fc822f
parent 45 d89453a10991
child 47 b73b3e3c9560
Do not propagate obsolete changeset
obsolete.py
tests/test-obsolete.t
--- a/obsolete.py	Thu Sep 08 14:02:29 2011 +0200
+++ b/obsolete.py	Thu Sep 08 16:46:58 2011 +0200
@@ -12,6 +12,8 @@
 from mercurial import scmutil
 from mercurial import extensions
 from mercurial import pushkey
+from mercurial import discovery
+from mercurial import error
 from mercurial.node import hex, bin
 
 # Patch changectx
@@ -47,6 +49,29 @@
 
 def extsetup(ui):
     revset.symbols["obsolete"] = revsetobsolete
+
+    def filterobsoleteout(orig, repo, remote, *args,**kwargs):
+        common, heads = orig(repo, remote, *args, **kwargs)
+
+        # filter obsolete
+        heads = set(map(repo.changelog.rev, heads))
+        obsoletes = set()
+        for obj in repo._obsobjrels:
+            try:
+                obsoletes.add(repo.changelog.rev(obj))
+            except error.LookupError:
+                pass # we don't have this node locally
+
+        outgoing = set(repo.changelog.ancestors(*heads))
+        outgoing.update(heads)
+
+        selected = outgoing - obsoletes
+        heads = sorted(map(repo.changelog.node, selected))
+
+        return common, heads
+
+    extensions.wrapfunction(discovery, 'findcommonoutgoing', filterobsoleteout)
+    
     try:
         rebase = extensions.find('rebase')
         if rebase:
@@ -183,7 +208,10 @@
             """Add a relation marking that node <sub> is a new version of <obj>"""
             self._obssubrels.setdefault(sub, set()).add(obj)
             self._obsobjrels.setdefault(obj, set()).add(sub)
-            self.changelog.hiddenrevs.add(repo[obj].rev())
+            try:
+                self.changelog.hiddenrevs.add(repo[obj].rev())
+            except error.RepoLookupError:
+                pass #unknow revision (but keep propagating the data
             self._writeobsrels()
 
     repo.__class__ = obsoletingrepo
--- a/tests/test-obsolete.t	Thu Sep 08 14:02:29 2011 +0200
+++ b/tests/test-obsolete.t	Thu Sep 08 16:46:58 2011 +0200
@@ -58,19 +58,19 @@
 Test communication of obsolete relation with a compatible client
 
   $ hg init ../other-new
-  $ hg push ../other-new
+  $ hg push --traceback ../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)
+  added 5 changesets with 5 changes to 5 files (+1 heads)
   $ qlog -R ../other-new -r 'obsolete()'
-  3 0d3f46688ccc
+  2 0d3f46688ccc
   $ qlog -R ../other-new
-  5 a7a6f2b5d8a5
-  4 725c380fe99b
-  3 0d3f46688ccc
+  4 a7a6f2b5d8a5
+  3 725c380fe99b
+  2 0d3f46688ccc
   1 7c3bad9141dc
   0 1f0dee641bb7
   $ hg up 3 -q
@@ -93,13 +93,13 @@
   adding file changes
   added 1 changesets with 1 changes to 1 files (+1 heads)
   $ qlog -R ../other-new
-  6 95de7fc6918d
-  4 725c380fe99b
-  3 0d3f46688ccc
+  5 95de7fc6918d
+  3 725c380fe99b
+  2 0d3f46688ccc
   1 7c3bad9141dc
   0 1f0dee641bb7
   $ qlog -R ../other-new -r 'obsolete()'
-  3 0d3f46688ccc
+  2 0d3f46688ccc
   $ hg up -q .^
   $ mkcommit "obsol_d'" # 7
   created new head
@@ -110,12 +110,31 @@
   adding changesets
   adding manifests
   adding file changes
-  added 1 changesets with 1 changes to 1 files (+1 heads)
+  added 2 changesets with 2 changes to 2 files (+2 heads)
   (run 'hg heads .' to see heads, 'hg merge' to merge)
   $ qlog -R ../other-new
   7 909a0fb57e5d
-  4 725c380fe99b
-  3 0d3f46688ccc
+  3 725c380fe99b
+  2 0d3f46688ccc
+  1 7c3bad9141dc
+  0 1f0dee641bb7
+
+pushing to stuff that doesn't support obsolete
+
+  $ hg init ../other-old
+  $ echo '[extensions]'  > ../other-old/.hg/hgrc
+  $ echo "obsolete=!$(echo $(dirname $TESTDIR))/obsolete.py" >> ../other-old/.hg/hgrc
+  $ hg push ../other-old
+  pushing to ../other-old
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 5 changesets with 5 changes to 5 files (+1 heads)
+  $ qlog -R ../other-old
+  4 909a0fb57e5d
+  3 725c380fe99b
+  2 0d3f46688ccc
   1 7c3bad9141dc
   0 1f0dee641bb7