34
34
with_lock = util.with_lock('_lock', 'ChangeCache')
36
SQLITE_INTERFACE = os.environ.get('SQLITE_INTERFACE', 'sqlite3')
38
if SQLITE_INTERFACE == 'sqlite3':
39
37
from sqlite3 import dbapi2
42
_select_stmt = ("select data from revisiondata where revid = ?"
43
).replace('?', _param_marker)
44
_insert_stmt = ("insert into revisiondata (revid, data) "
45
"values (?, ?)").replace('?', _param_marker)
39
from pysqlite2 import dbapi2
50
42
class FakeShelf(object):
51
44
def __init__(self, filename):
52
45
create_table = not os.path.exists(filename)
53
46
self.connection = dbapi2.connect(filename)
54
47
self.cursor = self.connection.cursor()
56
49
self._create_table()
57
51
def _create_table(self):
58
52
self.cursor.execute(
59
53
"create table RevisionData "
60
54
"(revid binary primary key, data binary)")
61
55
self.connection.commit()
62
57
def _serialize(self, obj):
63
58
r = dbapi2.Binary(cPickle.dumps(obj, protocol=2))
65
61
def _unserialize(self, data):
66
62
return cPickle.loads(str(data))
67
64
def get(self, revid):
68
self.cursor.execute(_select_stmt, (revid,))
66
"select data from revisiondata where revid = ?", (revid, ))
69
67
filechange = self.cursor.fetchone()
70
68
if filechange is None:
73
71
return self._unserialize(filechange[0])
74
73
def add(self, revid_obj_pairs):
75
for (r, d) in revid_obj_pairs:
76
self.cursor.execute(_insert_stmt, (r, self._serialize(d)))
74
for (r, d) in revid_obj_pairs:
76
"insert into revisiondata (revid, data) values (?, ?)",
77
(r, self._serialize(d)))
77
78
self.connection.commit()
80
81
class FileChangeCache(object):
81
83
def __init__(self, history, cache_path):
82
84
self.history = history
105
107
missing_entry_indices.append(len(out))
107
109
if missing_entries:
108
missing_changes = self.history.get_file_changes_uncached(missing_entries)
110
missing_changes = self.history.get_file_changes_uncached(
109
112
revid_changes_pairs = []
110
113
for i, entry, changes in zip(
111
114
missing_entry_indices, missing_entries, missing_changes):