Rev 488: Keep cache of revnos to reduce number of calls to revision_history(). in file:///data/jelmer/bzr-svn/0.4/

Jelmer Vernooij jelmer at samba.org
Thu Jul 12 09:28:21 BST 2007


At file:///data/jelmer/bzr-svn/0.4/

------------------------------------------------------------
revno: 488
revision-id: jelmer at samba.org-20070618203307-mfa3swlxm30x19uj
parent: jelmer at samba.org-20070617205608-d6n5t6shdq3c77pg
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: main
timestamp: Mon 2007-06-18 22:33:07 +0200
message:
  Keep cache of revnos to reduce number of calls to revision_history().
modified:
  branch.py                      svnbranch.py-20051017135706-11c749eb0dab04a7
  revids.py                      revids.py-20070416220458-36vfa0730cchevp1-1
  tests/test_revids.py           test_revids.py-20070516230044-d7x872cqi7xb4eow-1
=== modified file 'branch.py'
--- a/branch.py	2007-06-17 16:10:27 +0000
+++ b/branch.py	2007-06-18 20:33:07 +0000
@@ -133,6 +133,7 @@
             self._revision_history.append(
                     self.repository.generate_revision_id(rev, branch))
         self._revision_history.reverse()
+        self.repository.revmap.insert_revision_history(self._revision_history)
 
     def get_root_id(self):
         if self.last_revision() is None:
@@ -165,6 +166,9 @@
     def revision_id_to_revno(self, revision_id):
         if revision_id is None:
             return 0
+        revno = self.repository.revmap.lookup_dist_to_origin(revision_id)
+        if revno is not None:
+            return revno
         history = self.revision_history()
         try:
             return history.index(revision_id) + 1
@@ -199,7 +203,7 @@
             return None
 
     def pull(self, source, overwrite=False, stop_revision=None, 
-             _hook_master=None, _run_hooks=True):
+             _hook_master=None, run_hooks=True):
         result = PullResult()
         result.source_branch = source
         result.master_branch = None

=== modified file 'revids.py'
--- a/revids.py	2007-06-17 20:56:08 +0000
+++ b/revids.py	2007-06-18 20:33:07 +0000
@@ -85,8 +85,10 @@
         else:
             self.cachedb = cache_db
         self.cachedb.executescript("""
-        create table if not exists revmap (revid text, path text, min_revnum integer, max_revnum integer, scheme text, dist_to_origin integer);
+        create table if not exists revmap (revid text, path text, min_revnum integer, max_revnum integer, scheme text);
         create index if not exists revid on revmap (revid);
+        create table if not exists revno_cache (revid text, dist_to_origin integer);
+        create unique index if not exists revid on revmap (revid);
         """)
         self.cachedb.commit()
     
@@ -115,13 +117,22 @@
             (revid, branch, min_revnum, max_revnum, scheme))
         if dist_to_origin is not None:
             self.cachedb.execute(
-                "update revmap set dist_to_origin = ?", 
-                (dist_to_origin,))
+                "insert into revno_cache (revid,dist_to_origin) VALUES (?,?)", 
+                (revid, dist_to_origin))
 
     def lookup_dist_to_origin(self, revid):
         revno = self.cachedb.execute(
-                "select dist_to_origin from revmap where revid='%s'" % revid).fetchone()
+                "select dist_to_origin from revno_cache where revid='%s'" % revid).fetchone()
         if revno is not None and revno[0] is not None:
             return int(revno[0])
         return None
 
+    def insert_revision_history(self, revhistory):
+        i = 1
+        for revid in revhistory:
+            self.cachedb.execute(
+                "insert into revno_cache (revid,dist_to_origin) VALUES (?,?)",
+                (revid, i))
+            i += 1
+        self.cachedb.commit()
+

=== modified file 'tests/test_revids.py'
--- a/tests/test_revids.py	2007-06-17 20:56:08 +0000
+++ b/tests/test_revids.py	2007-06-18 20:33:07 +0000
@@ -56,6 +56,16 @@
         self.assertIs(None,
                 revidmap.lookup_dist_to_origin("bloe"))
 
+    def test_insert_revhistory(self):
+        revidmap = RevidMap()
+        revidmap.insert_revision_history(["bla", "bloe", "blo"])
+        self.assertIs(1,
+                revidmap.lookup_dist_to_origin("bla"))
+        self.assertIs(2,
+                revidmap.lookup_dist_to_origin("bloe"))
+        self.assertIs(3,
+                revidmap.lookup_dist_to_origin("blo"))
+
     def test_lookup_dist_notfound(self):
         revidmap = RevidMap()
         self.assertIs(None,




More information about the bazaar-commits mailing list