2184
2184
if self._new_revision_id is None:
2185
2185
self._new_revision_id = self._gen_revision_id()
2187
def record_entry_contents(self, ie, parent_invs, path, tree):
2188
"""Record the content of ie from tree into the commit if needed.
2190
Side effect: sets ie.revision when unchanged
2192
:param ie: An inventory entry present in the commit.
2187
def _check_root(self, ie, parent_invs, tree):
2188
"""Helper for record_entry_contents.
2190
:param ie: An entry being added.
2193
2191
:param parent_invs: The inventories of the parent revisions of the
2195
:param path: The path the entry is at in the tree.
2196
:param tree: The tree which contains this entry and should be used to
2193
:param tree: The tree that is being committed.
2199
if self.new_inventory.root is None and ie.parent_id is not None:
2195
if ie.parent_id is not None:
2196
# if ie is not root, add a root automatically.
2200
2197
symbol_versioning.warn('Root entry should be supplied to'
2201
2198
' record_entry_contents, as of bzr 0.10.',
2202
2199
DeprecationWarning, stacklevel=2)
2203
2200
self.record_entry_contents(tree.inventory.root.copy(), parent_invs,
2205
self.new_inventory.add(ie)
2207
# ie.revision is always None if the InventoryEntry is considered
2208
# for committing. ie.snapshot will record the correct revision
2209
# which may be the sole parent if it is untouched.
2210
if ie.revision is not None:
2213
# In this revision format, root entries have no knit or weave
2214
if ie is self.new_inventory.root:
2215
# When serializing out to disk and back in
2216
# root.revision is always _new_revision_id
2203
# In this revision format, root entries have no knit or weave When
2204
# serializing out to disk and back in root.revision is always
2217
2206
ie.revision = self._new_revision_id
2208
def record_entry_contents(self, ie, parent_invs, path, tree):
2209
"""Record the content of ie from tree into the commit if needed.
2211
Side effect: sets ie.revision when unchanged
2213
:param ie: An inventory entry present in the commit.
2214
:param parent_invs: The inventories of the parent revisions of the
2216
:param path: The path the entry is at in the tree.
2217
:param tree: The tree which contains this entry and should be used to
2220
if self.new_inventory.root is None:
2221
self._check_root(ie, parent_invs, tree)
2222
self.new_inventory.add(ie)
2224
# ie.revision is always None if the InventoryEntry is considered
2225
# for committing. ie.snapshot will record the correct revision
2226
# which may be the sole parent if it is untouched.
2227
if ie.revision is not None:
2219
previous_entries = ie.find_previous_heads(
2221
self.repository.weave_store,
2222
self.repository.get_transaction())
2223
# we are creating a new revision for ie in the history store
2230
parent_candiate_entries = ie.parent_candidates(parent_invs)
2231
heads = self.repository.get_graph().heads(parent_candiate_entries.keys())
2232
# XXX: Note that this is unordered - and this is tolerable because
2233
# the previous code was also unordered.
2234
previous_entries = dict((head, parent_candiate_entries[head]) for head
2236
# we are creating a new revision for ie in the history store and
2225
2238
ie.snapshot(self._new_revision_id, path, previous_entries, tree, self)
2227
2240
def modified_directory(self, file_id, file_parents):
2260
2273
and text_sha1 == file_parents.values()[0].text_sha1
2261
2274
and text_size == file_parents.values()[0].text_size):
2262
2275
previous_ie = file_parents.values()[0]
2263
versionedfile = self.repository.weave_store.get_weave(file_id,
2276
versionedfile = self.repository.weave_store.get_weave(file_id,
2264
2277
self.repository.get_transaction())
2265
versionedfile.clone_text(self._new_revision_id,
2278
versionedfile.clone_text(self._new_revision_id,
2266
2279
previous_ie.revision, file_parents.keys())
2267
2280
return text_sha1, text_size
2269
2282
new_lines = get_content_byte_lines()
2270
# TODO: Rather than invoking sha_strings here, _add_text_to_weave
2271
# should return the SHA1 and size
2272
self._add_text_to_weave(file_id, new_lines, file_parents.keys())
2273
return osutils.sha_strings(new_lines), \
2274
sum(map(len, new_lines))
2283
return self._add_text_to_weave(file_id, new_lines,
2284
file_parents.keys())
2276
2286
def modified_link(self, file_id, file_parents, link_target):
2277
2287
"""Record the presence of a symbolic link.
2285
2295
def _add_text_to_weave(self, file_id, new_lines, parents):
2286
2296
versionedfile = self.repository.weave_store.get_weave_or_empty(
2287
2297
file_id, self.repository.get_transaction())
2288
versionedfile.add_lines(self._new_revision_id, parents, new_lines)
2298
result = versionedfile.add_lines(
2299
self._new_revision_id, parents, new_lines)[0:2]
2289
2300
versionedfile.clear_cache()
2292
2304
class _CommitBuilder(CommitBuilder):
2304
2316
record_root_entry = True
2306
def record_entry_contents(self, ie, parent_invs, path, tree):
2307
"""Record the content of ie from tree into the commit if needed.
2309
Side effect: sets ie.revision when unchanged
2311
:param ie: An inventory entry present in the commit.
2318
def _check_root(self, ie, parent_invs, tree):
2319
"""Helper for record_entry_contents.
2321
:param ie: An entry being added.
2312
2322
:param parent_invs: The inventories of the parent revisions of the
2314
:param path: The path the entry is at in the tree.
2315
:param tree: The tree which contains this entry and should be used to
2324
:param tree: The tree that is being committed.
2318
assert self.new_inventory.root is not None or ie.parent_id is None
2319
self.new_inventory.add(ie)
2321
# ie.revision is always None if the InventoryEntry is considered
2322
# for committing. ie.snapshot will record the correct revision
2323
# which may be the sole parent if it is untouched.
2324
if ie.revision is not None:
2327
previous_entries = ie.find_previous_heads(
2329
self.repository.weave_store,
2330
self.repository.get_transaction())
2331
# we are creating a new revision for ie in the history store
2333
ie.snapshot(self._new_revision_id, path, previous_entries, tree, self)
2326
# ie must be root for this builder
2327
assert ie.parent_id is None
2336
2330
_unescape_map = {