93
def add_inventory(self, revid, inv, parents):
94
"""Add the inventory inv to the repository as revid.
93
def add_inventory(self, revision_id, inv, parents):
94
"""Add the inventory inv to the repository as revision_id.
96
:param parents: The revision ids of the parents that revid
96
:param parents: The revision ids of the parents that revision_id
97
97
is known to have and are in the repository already.
99
99
returns the sha1 of the serialized inventory.
101
_mod_revision.check_not_reserved_id(revid)
102
assert inv.revision_id is None or inv.revision_id == revid, \
101
revision_id = osutils.safe_revision_id(revision_id)
102
_mod_revision.check_not_reserved_id(revision_id)
103
assert inv.revision_id is None or inv.revision_id == revision_id, \
103
104
"Mismatch between inventory revision" \
104
" id and insertion revid (%r, %r)" % (inv.revision_id, revid)
105
" id and insertion revid (%r, %r)" % (inv.revision_id, revision_id)
105
106
assert inv.root is not None
106
107
inv_text = self.serialise_inventory(inv)
107
108
inv_sha1 = osutils.sha_string(inv_text)
108
109
inv_vf = self.control_weaves.get_weave('inventory',
109
110
self.get_transaction())
110
self._inventory_add_lines(inv_vf, revid, parents, osutils.split_lines(inv_text))
111
self._inventory_add_lines(inv_vf, revision_id, parents,
112
osutils.split_lines(inv_text))
113
def _inventory_add_lines(self, inv_vf, revid, parents, lines):
115
def _inventory_add_lines(self, inv_vf, revision_id, parents, lines):
114
116
final_parents = []
115
117
for parent in parents:
116
118
if parent in inv_vf:
117
119
final_parents.append(parent)
119
inv_vf.add_lines(revid, final_parents, lines)
121
inv_vf.add_lines(revision_id, final_parents, lines)
121
123
@needs_write_lock
122
def add_revision(self, rev_id, rev, inv=None, config=None):
123
"""Add rev to the revision store as rev_id.
124
def add_revision(self, revision_id, rev, inv=None, config=None):
125
"""Add rev to the revision store as revision_id.
125
:param rev_id: the revision id to use.
127
:param revision_id: the revision id to use.
126
128
:param rev: The revision object.
127
129
:param inv: The inventory for the revision. if None, it will be looked
128
130
up in the inventory storer
130
132
If supplied its signature_needed method will be used
131
133
to determine if a signature should be made.
133
_mod_revision.check_not_reserved_id(rev_id)
135
revision_id = osutils.safe_revision_id(revision_id)
136
_mod_revision.check_not_reserved_id(revision_id)
134
137
if config is not None and config.signature_needed():
136
inv = self.get_inventory(rev_id)
139
inv = self.get_inventory(revision_id)
137
140
plaintext = Testament(rev, inv).as_short_text()
138
141
self.store_revision_signature(
139
gpg.GPGStrategy(config), plaintext, rev_id)
140
if not rev_id in self.get_inventory_weave():
142
gpg.GPGStrategy(config), plaintext, revision_id)
143
if not revision_id in self.get_inventory_weave():
142
raise errors.WeaveRevisionNotPresent(rev_id,
145
raise errors.WeaveRevisionNotPresent(revision_id,
143
146
self.get_inventory_weave())
145
148
# yes, this is not suitable for adding with ghosts.
146
self.add_inventory(rev_id, inv, rev.parent_ids)
149
self.add_inventory(revision_id, inv, rev.parent_ids)
147
150
self._revision_store.add_revision(rev, self.get_transaction())
292
295
:param revprops: Optional dictionary of revision properties.
293
296
:param revision_id: Optional revision id.
298
revision_id = osutils.safe_revision_id(revision_id)
295
299
return _CommitBuilder(self, parents, config, timestamp, timezone,
296
300
committer, revprops, revision_id)