13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
"""Read in a bundle stream, and process it into a BundleReader object."""
28
28
import bzrlib.errors
29
29
from bzrlib.bundle import apply_bundle
30
from bzrlib.errors import (TestamentMismatch, BzrError,
30
from bzrlib.errors import (TestamentMismatch, BzrError,
31
31
MalformedHeader, MalformedPatches, NotABundle)
32
32
from bzrlib.inventory import (Inventory, InventoryEntry,
33
33
InventoryDirectory, InventoryFile,
159
159
def get_base(self, revision):
160
160
revision_info = self.get_revision_info(revision.revision_id)
161
161
if revision_info.base_id is not None:
162
return revision_info.base_id
162
if revision_info.base_id == NULL_REVISION:
165
return revision_info.base_id
163
166
if len(revision.parent_ids) == 0:
164
167
# There is no base listed, and
165
168
# the lowest revision doesn't have a parent
166
169
# so this is probably against the empty tree
167
# and thus base truly is NULL_REVISION
170
# and thus base truly is None
170
173
return revision.parent_ids[-1]
200
203
self._validate_references_from_repository(repository)
201
204
revision_info = self.get_revision_info(revision_id)
202
205
inventory_revision_id = revision_id
203
bundle_tree = BundleTree(repository.revision_tree(base),
206
bundle_tree = BundleTree(repository.revision_tree(base),
204
207
inventory_revision_id)
205
208
self._update_tree(bundle_tree, revision_id)
239
242
for rev_info in self.revisions:
240
243
checked[rev_info.revision_id] = True
241
244
add_sha(rev_to_sha, rev_info.revision_id, rev_info.sha1)
243
246
for (rev, rev_info) in zip(self.real_revisions, self.revisions):
244
247
add_sha(inv_to_sha, rev_info.revision_id, rev_info.inventory_sha1)
248
251
for revision_id, sha1 in rev_to_sha.iteritems():
249
252
if repository.has_revision(revision_id):
250
testament = StrictTestament.from_revision(repository,
253
testament = StrictTestament.from_revision(repository,
252
255
local_sha1 = self._testament_sha1_from_revision(repository,
254
257
if sha1 != local_sha1:
255
raise BzrError('sha1 mismatch. For revision id {%s}'
258
raise BzrError('sha1 mismatch. For revision id {%s}'
256
259
'local: %s, bundle: %s' % (revision_id, local_sha1, sha1))
259
262
elif revision_id not in checked:
260
263
missing[revision_id] = sha1
265
for inv_id, sha1 in inv_to_sha.iteritems():
266
if repository.has_revision(inv_id):
267
# Note: branch.get_inventory_sha1() just returns the value that
268
# is stored in the revision text, and that value may be out
269
# of date. This is bogus, because that means we aren't
270
# validating the actual text, just that we wrote and read the
271
# string. But for now, what the hell.
272
local_sha1 = repository.get_inventory_sha1(inv_id)
273
if sha1 != local_sha1:
274
raise BzrError('sha1 mismatch. For inventory id {%s}'
275
'local: %s, bundle: %s' %
276
(inv_id, local_sha1, sha1))
262
280
if len(missing) > 0:
263
281
# I don't know if this is an error yet
264
282
warning('Not all revision hashes could be validated.'
606
624
new_path = self.id2path(file_id)
607
625
return self.base_tree.path2id(new_path)
609
627
def get_file(self, file_id):
610
628
"""Return a file-like object containing the new contents of the
611
629
file given by file_id.
622
640
patch_original = None
623
641
file_patch = self.patches.get(self.id2path(file_id))
624
642
if file_patch is None:
625
if (patch_original is None and
643
if (patch_original is None and
626
644
self.get_kind(file_id) == 'directory'):
627
645
return StringIO()
628
646
if patch_original is None: