changeset 23341:bcc3012f8477

ancestor: add a way to add to bases of a missing ancestor object This will be useful for setdiscovery, since with that we incrementally add to our knowledge of common nodes.
author Siddharth Agarwal <sid0@fb.com>
date Fri, 14 Nov 2014 17:21:00 -0800
parents 83225aff0265
children f710644e1ce9
files mercurial/ancestor.py tests/test-ancestor.py
diffstat 2 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/ancestor.py	Sun Nov 16 00:39:29 2014 -0800
+++ b/mercurial/ancestor.py	Fri Nov 14 17:21:00 2014 -0800
@@ -150,6 +150,10 @@
         '''whether the common set has any non-trivial bases'''
         return self.bases and self.bases != set([nullrev])
 
+    def addbases(self, newbases):
+        '''grow the ancestor set by adding new bases'''
+        self.bases.update(newbases)
+
     def missingancestors(self, revs):
         '''return all the ancestors of revs that are not ancestors of self.bases
 
--- a/tests/test-ancestor.py	Sun Nov 16 00:39:29 2014 -0800
+++ b/tests/test-ancestor.py	Fri Nov 14 17:21:00 2014 -0800
@@ -45,6 +45,8 @@
     def __init__(self, ancs, bases):
         self.ancs = ancs
         self.bases = set(bases)
+    def addbases(self, newbases):
+        self.bases.update(newbases)
     def missingancestors(self, revs):
         res = set()
         for rev in revs:
@@ -97,6 +99,11 @@
             naiveinc = naiveincrementalmissingancestors(ancs, bases)
             seq = []
             for _ in xrange(inccount):
+                if rng.random() < 0.2:
+                    newbases = samplerevs(graphnodes)
+                    seq.append(('addbases', newbases))
+                    inc.addbases(newbases)
+                    naiveinc.addbases(newbases)
                 revs = samplerevs(graphnodes)
                 seq.append(('missingancestors', revs))
                 h = inc.missingancestors(revs)