17
17
"""Repository formats built around versioned files."""
19
from __future__ import absolute_import
22
20
from bzrlib.lazy_import import lazy_import
23
21
lazy_import(globals(), """
200
198
revision_id=self._new_revision_id,
201
199
properties=self._revprops)
202
200
rev.parent_ids = self.parents
203
if self._config_stack.get('create_signatures') == _mod_config.SIGN_ALWAYS:
204
testament = Testament(rev, self.revision_tree())
205
plaintext = testament.as_short_text()
206
self.repository.store_revision_signature(
207
gpg.GPGStrategy(self._config_stack), plaintext,
208
self._new_revision_id)
209
self.repository._add_revision(rev)
201
self.repository.add_revision(self._new_revision_id, rev,
202
self.new_inventory, self._config_stack)
210
203
self._ensure_fallback_inventories()
211
204
self.repository.commit_write_group()
212
205
return self._new_revision_id
604
597
_mod_revision.NULL_REVISION))
605
598
# The basis inventory from a repository
607
basis_tree = revtrees[0]
600
basis_inv = revtrees[0].inventory
609
basis_tree = self.repository.revision_tree(
610
_mod_revision.NULL_REVISION)
611
basis_inv = basis_tree.root_inventory
602
basis_inv = self.repository.revision_tree(
603
_mod_revision.NULL_REVISION).inventory
612
604
if len(self.parents) > 0:
613
605
if basis_revision_id != self.parents[0] and not ghost_basis:
615
607
"arbitrary basis parents not yet supported with merges")
616
608
for revtree in revtrees[1:]:
617
for change in revtree.root_inventory._make_delta(basis_inv):
609
for change in revtree.inventory._make_delta(basis_inv):
618
610
if change[1] is None:
619
611
# Not present in this parent.
1022
1014
# return a new inventory, but as there is no revision tree cache in
1023
1015
# repository this is safe for now - RBC 20081013
1024
1016
if basis_inv is None:
1025
basis_inv = basis_tree.root_inventory
1017
basis_inv = basis_tree.inventory
1026
1018
basis_inv.apply_delta(delta)
1027
1019
basis_inv.revision_id = new_revision_id
1028
1020
return (self.add_inventory(new_revision_id, basis_inv, parents),
1039
1031
self.inventories._access.flush()
1042
def add_revision(self, revision_id, rev, inv=None):
1034
def add_revision(self, revision_id, rev, inv=None, config=None):
1043
1035
"""Add rev to the revision store as revision_id.
1045
1037
:param revision_id: the revision id to use.
1046
1038
:param rev: The revision object.
1047
1039
:param inv: The inventory for the revision. if None, it will be looked
1048
1040
up in the inventory storer
1041
:param config: If None no digital signature will be created.
1042
If supplied its signature_needed method will be used
1043
to determine if a signature should be made.
1050
1045
# TODO: jam 20070210 Shouldn't we check rev.revision_id and
1051
1046
# rev.parent_ids?
1052
1047
_mod_revision.check_not_reserved_id(revision_id)
1048
if (config is not None and
1049
config.get('create_signatures') == _mod_config.SIGN_ALWAYS):
1051
inv = self.get_inventory(revision_id)
1052
tree = InventoryRevisionTree(self, inv, revision_id)
1053
testament = Testament(rev, tree)
1054
plaintext = testament.as_short_text()
1055
self.store_revision_signature(
1056
gpg.GPGStrategy(config), plaintext, revision_id)
1053
1057
# check inventory present
1054
1058
if not self.inventories.get_parent_map([(revision_id,)]):
1055
1059
if inv is None:
1649
1653
inv = inventory_cache[parent_id]
1650
1654
except KeyError:
1651
inv = self.revision_tree(parent_id).root_inventory
1655
inv = self.revision_tree(parent_id).inventory
1652
1656
inventory_cache[parent_id] = inv
1654
1658
parent_entry = inv[text_key[0]]
2442
2446
invs_sent_so_far = set([_mod_revision.NULL_REVISION])
2443
2447
inventory_cache = lru_cache.LRUCache(50)
2444
2448
null_inventory = from_repo.revision_tree(
2445
_mod_revision.NULL_REVISION).root_inventory
2449
_mod_revision.NULL_REVISION).inventory
2446
2450
# XXX: ideally the rich-root/tree-refs flags would be per-revision, not
2447
2451
# per-repo (e.g. streaming a non-rich-root revision out of a rich-root
2448
2452
# repo back into a non-rich-root repo ought to be allowed)
2797
2801
# Generate deltas against each tree, to find the shortest.
2798
# FIXME: Support nested trees
2799
2802
texts_possibly_new_in_tree = set()
2800
2803
for basis_id, basis_tree in possible_trees:
2801
delta = tree.root_inventory._make_delta(basis_tree.root_inventory)
2804
delta = tree.inventory._make_delta(basis_tree.inventory)
2802
2805
for old_path, new_path, file_id, new_entry in delta:
2803
2806
if new_path is None:
2804
2807
# This file_id isn't present in the new rev, so we don't
2841
2844
parents_parents = [key[-1] for key in parents_parents_keys]
2842
2845
basis_id = _mod_revision.NULL_REVISION
2843
2846
basis_tree = self.source.revision_tree(basis_id)
2844
delta = parent_tree.root_inventory._make_delta(
2845
basis_tree.root_inventory)
2847
delta = parent_tree.inventory._make_delta(basis_tree.inventory)
2846
2848
self.target.add_inventory_by_delta(
2847
2849
basis_id, delta, current_revision_id, parents_parents)
2848
2850
cache[current_revision_id] = parent_tree
2907
2909
kind = entry.kind
2908
2910
texts_possibly_new_in_tree.add((file_id, entry.revision))
2909
2911
for basis_id, basis_tree in possible_trees:
2910
basis_inv = basis_tree.root_inventory
2912
basis_inv = basis_tree.inventory
2911
2913
for file_key in list(texts_possibly_new_in_tree):
2912
2914
file_id, file_revision = file_key
3145
3147
parent_trees[p_id] = repository.revision_tree(
3146
3148
_mod_revision.NULL_REVISION)
3148
# FIXME: Support nested trees
3149
inv = revision_tree.root_inventory
3150
inv = revision_tree.inventory
3150
3151
entries = inv.iter_entries()
3151
3152
# backwards compatibility hack: skip the root id.
3152
3153
if not repository.supports_rich_root():