Rev 45: Start working on translating the revno information into what we need in http://bzr.arbash-meinel.com/plugins/history_db

John Arbash Meinel john at arbash-meinel.com
Mon Apr 5 23:01:08 BST 2010


At http://bzr.arbash-meinel.com/plugins/history_db

------------------------------------------------------------
revno: 45
revision-id: john at arbash-meinel.com-20100405220103-06nl05iyk31uf5cq
parent: john at arbash-meinel.com-20100405213117-gwgw91apsbn366z9
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: history_db
timestamp: Mon 2010-04-05 17:01:03 -0500
message:
  Start working on translating the revno information into what we need
  to build new merge_sorted info.
-------------- next part --------------
=== modified file 'history_db.py'
--- a/history_db.py	2010-04-05 21:31:17 +0000
+++ b/history_db.py	2010-04-05 22:01:03 +0000
@@ -448,6 +448,10 @@
         # Revisions that we are walking, to see if they are interesting, or
         # already imported.
         self._search_tips = None
+        # mainline revno => number of child branches
+        self._revno_to_branch_count = {}
+        # (revno, branch_num) => oldest seen child
+        self._branch_to_child_count = {}
 
     def _find_needed_mainline(self):
         """Find mainline revisions that need to be filled out.
@@ -601,7 +605,9 @@
             "SELECT merged_revision, revno, end_of_merge, merge_depth"
             "  FROM dotted_revno WHERE tip_revision = ?",
             [self._imported_mainline_id]).fetchall()
-        self._imported_dotted_revno.update([(r[0], r[1:]) for r in res])
+        self._imported_dotted_revno.update(
+            [(r[0], (tuple(map(int, r[1].split('.'))), r[2], r[3]))
+             for r in res])
         # TODO: We could remove search tips that show up as newly merged
         #       though that can wait until the next
         #       _split_search_tips_by_gdfo
@@ -672,9 +678,24 @@
         # Also all of the new pending revisions should be in
         # self._interesting_ancestor_ids
 
+    def _update_info_from_dotted_revno(self):
+        """Update info like 'child_seen' from the dotted_revno info."""
+        iterator = self._imported_dotted_revno.iteritems()
+        for db_id, (revno, eom, depth) in iterator:
+            if len(revno) > 1: # dotted revno, make sure branch count is right
+                base_revno = revno[0]
+                if (base_revno not in self._revno_to_branch_count
+                    or revno[1] > self._revno_to_branch_count[base_revno]):
+                    self._revno_to_branch_count[base_revno] = revno[1]
+                branch_key = revno[:2]
+                if (branch_key not in self._branch_to_child_count
+                    or revno[2] > self._branch_to_child_count[branch_key]):
+                    self._branch_to_child_count[branch_key] = revno[2]
+
     def do_import(self):
         self._find_interesting_ancestry()
 
+
 class Querier(object):
     """Perform queries on an existing history db."""
 

=== modified file 'test_importer.py'
--- a/test_importer.py	2010-04-05 21:31:17 +0000
+++ b/test_importer.py	2010-04-05 22:01:03 +0000
@@ -292,8 +292,8 @@
         self.assertEqual(self.A_id, inc_importer._imported_mainline_id)
         self.assertEqual(1, inc_importer._imported_gdfo)
         self.C_id = importer._rev_id_to_db_id['C']
-        self.assertEqual({self.D_id: ('2', 0, 0), self.C_id: ('1.1.2', 0, 1),
-                          self.B_id: ('1.1.1', 1, 1),
+        self.assertEqual({self.D_id: ((2,), 0, 0), self.C_id: ((1,1,2), 0, 1),
+                          self.B_id: ((1,1,1), 1, 1),
                          }, inc_importer._imported_dotted_revno)
         # Search tips is not yet changed
         self.assertEqual(set([self.B_id]), inc_importer._search_tips)
@@ -301,6 +301,9 @@
         # search_tips, because it sees it in _imported_dotted_revno
         self.assertEqual([], inc_importer._split_search_tips_by_gdfo([self.B_id]))
         self.assertEqual(set([]), inc_importer._search_tips)
+        inc_importer._update_info_from_dotted_revno()
+        self.assertEqual({1: 1}, inc_importer._revno_to_branch_count)
+        self.assertEqual({(1, 1): 2}, inc_importer._branch_to_child_count)
 
     def test__incremental_find_interesting_ancestry(self):
         b = self.make_interesting_branch()
@@ -323,6 +326,6 @@
                               self.M_id, self.N_id]),
                          inc_importer._interesting_ancestor_ids)
         self.assertEqual(set([]), inc_importer._search_tips)
-        self.assertEqual({self.D_id: ('2', 0, 0), self.C_id: ('1.1.2', 0, 1),
-                          self.B_id: ('1.1.1', 1, 1),
+        self.assertEqual({self.D_id: ((2,), 0, 0), self.C_id: ((1,1,2), 0, 1),
+                          self.B_id: ((1,1,1), 1, 1),
                          }, inc_importer._imported_dotted_revno)



More information about the bazaar-commits mailing list