1 # Copyright (C) 2005-2007 Jelmer Vernooij <jelmer@samba.org>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 from bzrlib.plugins.svn.cache import CacheTable
18 class SqliteCachingParentsProvider(object):
19 def __init__(self, actual, cachedb=None):
20 self.cache = ParentsCache(cachedb)
23 def get_parent_map(self, keys):
27 parents = self.cache.lookup_parents(k)
33 ret.update(self.actual.get_parent_map(todo))
37 class ParentsCache(CacheTable):
38 def _create_table(self):
39 self.cachedb.executescript("""
40 create table if not exists parent (revision text, parent text);
41 create index if not exists parent_revision on parent (revision);
44 def insert_parents(self, revid, parents):
45 self.mutter('insert parents: %r -> %r', revid, parents)
46 for parent in parents:
47 self.cachedb.execute("insert into parent (revision, parent) VALUES (?, ?)", (revid, parent))
49 def lookup_parents(self, revid):
50 self.mutter('lookup parents: %r', revid)
52 for row in self.cachedb.execute("select parent from parent where revision = ?", (revid,)).fetchall():