290
290
' Unable validate %d hashes' % len(missing))
291
291
mutter('Verified %d sha hashes for the changeset.' % count)
293
def _create_inventory(self, tree):
294
"""Build up the inventory entry for the ChangesetTree.
296
TODO: This sort of thing should probably end up part of
297
ChangesetTree, but since it doesn't handle meta-information
298
yet, we need to do it here. (We need the ChangesetInfo,
299
specifically the text_ids)
301
from os.path import dirname, basename
302
from bzrlib.inventory import Inventory, InventoryEntry, ROOT_ID
304
# TODO: deal with trees having a unique ROOT_ID
308
if file_id == root_id:
310
path = tree.id2path(file_id)
311
parent_path = dirname(path)
315
parent_id = tree.path2id(parent_path)
317
if self.info.text_ids.has_key(file_id):
318
text_id = self.info.text_ids[file_id]
320
# If we don't have the text_id in the local map
321
# that means the file didn't exist in the changeset
322
# so we just use the old text_id.
323
text_id = tree.base_tree.inventory[file_id].text_id
324
name = basename(path)
325
kind = tree.get_kind(file_id)
326
ie = InventoryEntry(file_id, name, kind, parent_id, text_id=text_id)
327
ie.text_size, ie.text_sha1 = tree.get_size_and_sha1(file_id)
328
if (ie.text_size is None) and (kind != 'directory'):
329
raise BzrError('Got a text_size of None for file_id %r' % file_id)
333
293
def _validate_inventory(self, inv):
334
294
"""At this point we should have generated the ChangesetTree,
335
295
so build up an inventory, and make sure the hashes match.
348
308
# Target revision is the last entry in the real_revisions list
349
309
rev = self.info.real_revisions[-1]
350
310
if sha1 != rev.inventory_sha1:
311
open(',,bogus-inv', 'wb').write(sio.getvalue())
351
312
raise BzrError('Inventory sha hash mismatch.')
354
def get_info_tree_inv(self, branch):
315
def get_changeset(self, branch):
355
316
"""Return the meta information, and a Changeset tree which can
356
317
be used to populate the local stores and working tree, respectively.
489
450
if self._next_line is None or self._next_line[:1] == '#':
490
451
return None, [], False
492
line = self._next().next()
493
if line[:3] != '***':
494
raise MalformedPatches('The first line of all patches'
495
' should be a bzr meta line "***"'
499
if self._next_line is None or self._next_line[:1] == '#':
500
return action, [], False
502
455
for line in self._next():
457
if line[:3] != '***':
458
raise MalformedPatches('The first line of all patches'
459
' should be a bzr meta line "***"'
505
462
if self._next_line is not None and self._next_line[:3] == '***':
506
463
return action, lines, True
507
464
elif self._next_line is None or self._next_line[:1] == '#':
508
465
return action, lines, False
509
472
return action, lines, False
511
474
def _read_patches(self):
620
583
file_id = decode(info[1][8:])
623
text_id = get_text_id(info[2], file_id, kind)
625
text_id = get_text_id(None, file_id, kind)
626
585
tree.note_id(file_id, path, kind)
586
if kind == 'directory':
589
text_id = get_text_id(info[2], file_id, kind)
591
text_id = get_text_id(None, file_id, kind)
627
592
tree.note_patch(path, ''.join(lines))
629
594
def modified(kind, extra, lines):
677
642
won't know about until after the changeset is parsed.)
679
644
cr = ChangesetReader(from_file)
680
return cr.get_info_tree_inv(branch)
645
return cr.get_changeset(branch)
682
647
class ChangesetTree(Tree):
683
648
def __init__(self, base_tree):
886
851
inv = Inventory()
888
853
def add_entry(file_id):
891
854
path = self.id2path(file_id)
894
857
parent_path = dirname(path)
858
if parent_path == '':
896
859
parent_id = root_id
898
861
parent_id = self.path2id(parent_path)
900
if parent_id not in inv:
903
text_id = self.get_text_id(file_id)
905
name = basename(path)
906
863
kind = self.get_kind(file_id)
864
if kind == 'directory':
867
text_id = self.get_text_id(file_id)
869
name = basename(path)
907
870
ie = InventoryEntry(file_id, name, kind, parent_id, text_id=text_id)
908
ie.text_size, ie.text_sha1 = self.get_size_and_sha1(file_id)
871
if kind == 'directory':
872
ie.text_size, ie.text_sha1 = None, None
874
ie.text_size, ie.text_sha1 = self.get_size_and_sha1(file_id)
909
875
if (ie.text_size is None) and (kind != 'directory'):
910
876
raise BzrError('Got a text_size of None for file_id %r' % file_id)
913
879
for path, ie in base_inv.iter_entries():
914
880
add_entry(ie.file_id)
915
881
for file_id in self._new_id_r.iterkeys():
884
path = self.id2path(file_id)
885
parent_path = dirname(path)
886
if parent_path != '':
887
parent_id = self.path2id(parent_path)
888
if parent_id not in inv:
916
891
add_entry(file_id)