Patchwork [14,of,16] ancestor: add a way to add to bases of a missing ancestor object

login
register
mail settings
Submitter Siddharth Agarwal
Date Nov. 16, 2014, 9:17 a.m.
Message ID <336b35538d436cffe1a3.1416129436@devbig136.prn2.facebook.com>
Download mbox | patch
Permalink /patch/6759/
State Accepted
Commit bcc3012f8477811b01e5c07b0a55c073a59ca20d
Headers show

Comments

Siddharth Agarwal - Nov. 16, 2014, 9:17 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1416014460 28800
#      Fri Nov 14 17:21:00 2014 -0800
# Node ID 336b35538d436cffe1a3aadea25f75b83b24f134
# Parent  124d0f634a52d89c5ca2780a9c052ae785b32f7c
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.

Patch

diff --git a/mercurial/ancestor.py b/mercurial/ancestor.py
--- a/mercurial/ancestor.py
+++ b/mercurial/ancestor.py
@@ -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
 
diff --git a/tests/test-ancestor.py b/tests/test-ancestor.py
--- a/tests/test-ancestor.py
+++ b/tests/test-ancestor.py
@@ -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)