obsolete: drop successors sets which are subset of another one
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Sat, 10 Nov 2012 01:56:59 +0100
changeset 18069 f84e731cbd20
parent 18068 4bec77e62c00
child 18070 af632936d3d9
obsolete: drop successors sets which are subset of another one If both "(B,)" and "(B, C)" are successors set of "A", "(B,)" is dropped. We won't be interrested in detection such divergence scenario.
mercurial/obsolete.py
tests/test-obsolete-divergent.t
--- a/mercurial/obsolete.py	Thu Dec 13 15:38:43 2012 +0100
+++ b/mercurial/obsolete.py	Sat Nov 10 01:56:59 2012 +0100
@@ -558,11 +558,16 @@
                 # sets. In such a case, the marker will contribute multiple
                 # divergent successors sets. If multiple successors have
                 # divergents successors sets, a cartesian product is used.
+                #
+                # At the end we post-process successors sets to remove
+                # duplicated entry and successors set that are strict subset of
+                # another one.
                 succssets = []
                 for mark in succmarkers[current]:
                     # successors sets contributed by this marker
                     markss = [[]]
                     for suc in mark[1]:
+                        # cardinal product with previous successors
                         productresult = []
                         for prefix in markss:
                             for suffix in cache[suc]:
@@ -575,7 +580,20 @@
                                 productresult.append(newss)
                         markss = productresult
                     succssets.extend(markss)
-                cache[current] = list(set(tuple(r) for r in succssets if r))
+                # remove duplicated and subset
+                seen = []
+                final = []
+                candidate = sorted(((set(s), s) for s in succssets if s),
+                                   key=lambda x: len(x[1]), reverse=True)
+                for setversion, listversion in candidate:
+                    for seenset in seen:
+                        if setversion.issubset(seenset):
+                            break
+                    else:
+                        final.append(listversion)
+                        seen.append(setversion)
+                final.reverse() # put small successors set first
+                cache[current] = final
     return cache[initialnode]
 
 def _knownrevs(repo, nodes):
--- a/tests/test-obsolete-divergent.t	Thu Dec 13 15:38:43 2012 +0100
+++ b/tests/test-obsolete-divergent.t	Sat Nov 10 01:56:59 2012 +0100
@@ -75,8 +75,8 @@
   d20a80d4def3
       d20a80d4def3
   007dc284c1f8
+      392fd25390da
       82623d38b9ba
-      392fd25390da
   82623d38b9ba
       82623d38b9ba
   392fd25390da
@@ -139,8 +139,8 @@
   d20a80d4def3
       d20a80d4def3
   007dc284c1f8
+      392fd25390da
       82623d38b9ba
-      392fd25390da
   82623d38b9ba
       82623d38b9ba
   392fd25390da
@@ -396,3 +396,18 @@
 
   $ cd ..
 
+
+Subset does not diverge
+------------------------------
+
+Do not report divergent successors-set if it is a subset of another
+successors-set. (report [A,B] not [A] + [A,B])
+
+  $ newcase subset
+  $ hg debugobsolete `getid A_0` `getid A_2`
+  $ hg debugobsolete `getid A_0` `getid A_1` `getid A_2`
+  $ hg debugsuccessorssets 'desc('A_0')'
+  007dc284c1f8
+      82623d38b9ba 392fd25390da
+
+  $ cd ..