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