22
22
from unittest import TestSuite
24
from bzrlib import bzrdir, check, delta, gpg, errors, xml5, ui, transactions, osutils
25
36
from bzrlib.decorators import needs_read_lock, needs_write_lock
26
37
from bzrlib.errors import InvalidRevisionId
27
38
from bzrlib.graph import Graph
75
86
"Mismatch between inventory revision" \
76
87
" id and insertion revid (%r, %r)" % (inv.revision_id, revid)
77
88
assert inv.root is not None
78
inv_text = xml5.serializer_v5.write_inventory_to_string(inv)
89
inv_text = self.serialise_inventory(inv)
79
90
inv_sha1 = osutils.sha_string(inv_text)
80
91
inv_vf = self.control_weaves.get_weave('inventory',
81
92
self.get_transaction())
451
462
result.root.revision = revision_id
465
def serialise_inventory(self, inv):
466
return xml5.serializer_v5.write_inventory_to_string(inv)
455
469
def get_inventory_xml(self, revision_id):
456
470
"""Get inventory XML as a file object."""
986
1000
return self._get_revision_vf().get_parents(revision_id)
1003
class KnitRepository2(KnitRepository):
1006
def deserialise_inventory(self, revision_id, xml):
1007
"""Transform the xml into an inventory object.
1009
:param revision_id: The expected revision id of the inventory.
1010
:param xml: A serialised inventory.
1012
result = xml6.serializer_v6.read_inventory_from_string(xml)
1013
assert result.root.revision is not None
1016
def serialise_inventory(self, inv):
1017
"""Transform the inventory object into XML text.
1019
:param revision_id: The expected revision id of the inventory.
1020
:param xml: A serialised inventory.
1022
assert inv.root.revision is not None
1023
return xml6.serializer_v6.write_inventory_to_string(inv)
1025
def get_commit_builder(self, branch, parents, config, timestamp=None,
1026
timezone=None, committer=None, revprops=None,
1028
"""Obtain a CommitBuilder for this repository.
1030
:param branch: Branch to commit to.
1031
:param parents: Revision ids of the parents of the new revision.
1032
:param config: Configuration to use.
1033
:param timestamp: Optional timestamp recorded for commit.
1034
:param timezone: Optional timezone for timestamp.
1035
:param committer: Optional committer to set for commit.
1036
:param revprops: Optional dictionary of revision properties.
1037
:param revision_id: Optional revision id.
1039
return RootCommitBuilder(self, parents, config, timestamp, timezone,
1040
committer, revprops, revision_id)
989
1042
class RepositoryFormat(object):
990
1043
"""A repository format.
1631
1684
raise errors.BadConversionTarget(
1632
1685
'Does not support rich root data.', target_format)
1687
def open(self, a_bzrdir, _found=False, _override_transport=None):
1688
"""See RepositoryFormat.open().
1690
:param _override_transport: INTERNAL USE ONLY. Allows opening the
1691
repository at a slightly different url
1692
than normal. I.e. during 'upgrade'.
1695
format = RepositoryFormat.find_format(a_bzrdir)
1696
assert format.__class__ == self.__class__
1697
if _override_transport is not None:
1698
repo_transport = _override_transport
1700
repo_transport = a_bzrdir.get_repository_transport(None)
1701
control_files = LockableFiles(repo_transport, 'lock', LockDir)
1702
text_store = self._get_text_store(repo_transport, control_files)
1703
control_store = self._get_control_store(repo_transport, control_files)
1704
_revision_store = self._get_revision_store(repo_transport, control_files)
1705
return KnitRepository2(_format=self,
1707
control_files=control_files,
1708
_revision_store=_revision_store,
1709
control_store=control_store,
1710
text_store=text_store)
1635
1714
# formats which have no format string are not discoverable
1636
1715
# and not independently creatable, so are not registered.
2314
2393
record_root_entry = True
2396
class RootCommitBuilder(CommitBuilder):
2397
"""This commitbuilder actually records the root id"""
2399
record_root_entry = True
2401
def record_entry_contents(self, ie, parent_invs, path, tree):
2402
"""Record the content of ie from tree into the commit if needed.
2404
Side effect: sets ie.revision when unchanged
2406
:param ie: An inventory entry present in the commit.
2407
:param parent_invs: The inventories of the parent revisions of the
2409
:param path: The path the entry is at in the tree.
2410
:param tree: The tree which contains this entry and should be used to
2413
assert self.new_inventory.root is not None or ie.parent_id is None
2414
self.new_inventory.add(ie)
2416
# ie.revision is always None if the InventoryEntry is considered
2417
# for committing. ie.snapshot will record the correct revision
2418
# which may be the sole parent if it is untouched.
2419
if ie.revision is not None:
2422
previous_entries = ie.find_previous_heads(
2424
self.repository.weave_store,
2425
self.repository.get_transaction())
2426
# we are creating a new revision for ie in the history store
2428
ie.snapshot(self._new_revision_id, path, previous_entries, tree, self)
2317
2431
_unescape_map = {