Pierre-Yves David avatar Pierre-Yves David committed 3b0364f

Do not propagate obsolete changeset

Comments (0)

Files changed (2)

 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
 
 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:
             """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

tests/test-obsolete.t

 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
   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
   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
 
+
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.