Rev 99: Add a column to dotted_revno so we can ensure sort order. in http://bzr.arbash-meinel.com/plugins/history_db

John Arbash Meinel john at arbash-meinel.com
Thu Apr 15 18:12:26 BST 2010


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

------------------------------------------------------------
revno: 99
revision-id: john at arbash-meinel.com-20100415171200-uv5fni1un3yo6y9m
parent: john at arbash-meinel.com-20100415171143-0em7rosrfc3401j3
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: history_db
timestamp: Thu 2010-04-15 12:12:00 -0500
message:
  Add a column to dotted_revno so we can ensure sort order.
-------------- next part --------------
=== modified file 'history_db.py'
--- a/history_db.py	2010-04-14 18:39:12 +0000
+++ b/history_db.py	2010-04-15 17:12:00 +0000
@@ -149,7 +149,7 @@
         revno_entries = []
         to_cache_entry = []
         st = static_tuple.StaticTuple
-        for node in nodes:
+        for dist, node in enumerate(nodes):
             # TODO: Do we need to track the 'end_of_merge' and 'merge_depth'
             #       fields?
             db_id = rev_to_db[node.key[0]]
@@ -157,7 +157,8 @@
                                   db_id,
                                   '.'.join(map(str, node.revno)),
                                   node.end_of_merge,
-                                  node.merge_depth))
+                                  node.merge_depth,
+                                  dist))
             to_cache_entry.append(st(db_id, st(st.from_sequence(node.revno),
                                                node.end_of_merge,
                                                node.merge_depth)))

=== modified file 'schema.py'
--- a/schema.py	2010-04-12 20:58:07 +0000
+++ b/schema.py	2010-04-15 17:12:00 +0000
@@ -77,6 +77,7 @@
     revno TEXT NOT NULL,
     end_of_merge BOOL NOT NULL,
     merge_depth INTEGER NOT NULL,
+    dist INTEGER NOT NULL, -- Offset from tip, so we preserve the order
     CONSTRAINT dotted_revno_key UNIQUE (tip_revision, merged_revision)
 );
 """
@@ -225,30 +226,6 @@
                                [(g,) for g in ghosts])
 
 
-def create_dotted_revno(cursor, tip_revision, merged_revision, revno,
-                        end_of_merge, merge_depth):
-    """Create a dotted revno entry for this info."""
-    # TODO: Consider changing this to a bulk SELECT a bunch which may be
-    #       missing, .executemany() the ones that aren't present
-    existing = cursor.execute('SELECT revno, end_of_merge, merge_depth'
-                              '  FROM dotted_revno'
-                              ' WHERE tip_revision = ?'
-                              '   AND merged_revision = ?',
-                              (tip_revision, merged_revision)).fetchone()
-    if existing is not None:
-        new_value = (revno, end_of_merge, merge_depth)
-        if existing != new_value:
-            raise ValueError('Disagreement in the graph. Wanted to add'
-                ' node %s, but %s already exists'
-                % (new_value, existing))
-        return
-    cursor.execute(
-        'INSERT INTO dotted_revno (tip_revision, merged_revision,'
-        '                          revno, end_of_merge, merge_depth)'
-        ' VALUES (?, ?, ?, ?, ?)',
-        (tip_revision, merged_revision, revno, end_of_merge, merge_depth))
-
-
 def create_dotted_revnos(cursor, revno_entries):
     """Create a dotted revno entry for this info."""
     # # TODO: Consider changing this to a bulk SELECT a bunch which may be
@@ -267,6 +244,6 @@
     #     return
     cursor.executemany(
         'INSERT INTO dotted_revno (tip_revision, merged_revision,'
-        '                          revno, end_of_merge, merge_depth)'
-        ' VALUES (?, ?, ?, ?, ?)',
+        '                          revno, end_of_merge, merge_depth, dist)'
+        ' VALUES (?, ?, ?, ?, ?, ?)',
         revno_entries)



More information about the bazaar-commits mailing list