66
63
def _put(self, file_id, f):
67
64
return self._transport.put(self.filename(file_id), f)
69
def get_weave(self, file_id):
71
if file_id in self._cache:
72
mutter("cache hit in %s for %s", self, file_id)
73
return self._cache[file_id]
66
def get_weave(self, file_id, transaction):
67
weave = transaction.map.find_weave(file_id)
69
mutter("cache hit in %s for %s", self, file_id)
74
71
w = read_weave(self._get(file_id))
76
self._cache[file_id] = w
72
transaction.map.add_weave(file_id, w)
73
transaction.register_clean(w)
80
def get_lines(self, file_id, rev_id):
77
def get_lines(self, file_id, rev_id, transaction):
81
78
"""Return text from a particular version of a weave.
83
80
Returned as a list of lines."""
84
w = self.get_weave(file_id)
81
w = self.get_weave(file_id, transaction)
85
82
return w.get(w.lookup(rev_id))
88
def get_weave_or_empty(self, file_id):
84
def get_weave_or_empty(self, file_id, transaction):
89
85
"""Return a weave, or an empty one if it doesn't exist."""
91
inf = self._get(file_id)
87
return self.get_weave(file_id, transaction)
93
return Weave(weave_name=file_id)
95
return read_weave(inf)
89
weave = Weave(weave_name=file_id)
90
transaction.map.add_weave(file_id, weave)
91
transaction.register_clean(weave)
98
def put_weave(self, file_id, weave):
94
def put_weave(self, file_id, weave, transaction):
99
95
"""Write back a modified weave"""
100
if self.enable_cache:
101
self._cache[file_id] = weave
96
transaction.register_dirty(weave)
97
# TODO FOR WRITE TRANSACTIONS: this should be done in a callback
98
# from the transaction, when it decides to save.
104
100
write_weave_v5(weave, sio)
107
103
self._put(file_id, sio)
110
def add_text(self, file_id, rev_id, new_lines, parents):
111
w = self.get_weave_or_empty(file_id)
106
def add_text(self, file_id, rev_id, new_lines, parents, transaction):
107
w = self.get_weave_or_empty(file_id, transaction)
112
108
parent_idxs = map(w.lookup, parents)
113
109
w.add(rev_id, parent_idxs, new_lines)
114
self.put_weave(file_id, w)
110
self.put_weave(file_id, w, transaction)
116
def add_identical_text(self, file_id, old_rev_id, new_rev_id, parents):
117
w = self.get_weave_or_empty(file_id)
112
def add_identical_text(self, file_id, old_rev_id, new_rev_id, parents,
114
w = self.get_weave_or_empty(file_id, transaction)
118
115
parent_idxs = map(w.lookup, parents)
119
116
w.add_identical(old_rev_id, new_rev_id, parent_idxs)
120
self.put_weave(file_id, w)
117
self.put_weave(file_id, w, transaction)
122
119
def copy_multi(self, from_store, file_ids):
123
120
assert isinstance(from_store, WeaveStore)