79
79
>>> i.add(InventoryDirectory('123', 'src', ROOT_ID))
80
InventoryDirectory('123', 'src', parent_id='TREE_ROOT')
80
InventoryDirectory('123', 'src', parent_id='TREE_ROOT', revision=None)
81
81
>>> i.add(InventoryFile('2323', 'hello.c', parent_id='123'))
82
InventoryFile('2323', 'hello.c', parent_id='123')
82
InventoryFile('2323', 'hello.c', parent_id='123', sha1=None, len=None)
83
83
>>> shouldbe = {0: 'src', 1: pathjoin('src','hello.c')}
84
84
>>> for ix, j in enumerate(i.iter_entries()):
85
85
... print (j[0] == shouldbe[ix], j[1])
87
(True, InventoryDirectory('123', 'src', parent_id='TREE_ROOT'))
88
(True, InventoryFile('2323', 'hello.c', parent_id='123'))
87
(True, InventoryDirectory('123', 'src', parent_id='TREE_ROOT', revision=None))
88
(True, InventoryFile('2323', 'hello.c', parent_id='123', sha1=None, len=None))
89
89
>>> i.add(InventoryFile('2323', 'bye.c', '123'))
90
90
Traceback (most recent call last):
92
92
BzrError: inventory already contains entry with id {2323}
93
93
>>> i.add(InventoryFile('2324', 'bye.c', '123'))
94
InventoryFile('2324', 'bye.c', parent_id='123')
94
InventoryFile('2324', 'bye.c', parent_id='123', sha1=None, len=None)
95
95
>>> i.add(InventoryDirectory('2325', 'wibble', '123'))
96
InventoryDirectory('2325', 'wibble', parent_id='123')
96
InventoryDirectory('2325', 'wibble', parent_id='123', revision=None)
97
97
>>> i.path2id('src/wibble')
101
101
>>> i.add(InventoryFile('2326', 'wibble.c', '2325'))
102
InventoryFile('2326', 'wibble.c', parent_id='2325')
102
InventoryFile('2326', 'wibble.c', parent_id='2325', sha1=None, len=None)
104
InventoryFile('2326', 'wibble.c', parent_id='2325')
104
InventoryFile('2326', 'wibble.c', parent_id='2325', sha1=None, len=None)
105
105
>>> for path, entry in i.iter_entries():
107
107
... assert i.path2id(path)
123
123
RENAMED = 'renamed'
124
124
MODIFIED_AND_RENAMED = 'modified and renamed'
126
__slots__ = ['text_sha1', 'text_size', 'file_id', 'name', 'kind',
127
'text_id', 'parent_id', 'children', 'executable',
130
128
def detect_changes(self, old_entry):
131
129
"""Return a (text_modified, meta_modified) from this to old_entry.
397
393
return 'unchanged'
399
395
def __repr__(self):
400
return ("%s(%r, %r, parent_id=%r)"
396
return ("%s(%r, %r, parent_id=%r, revision=%r)"
401
397
% (self.__class__.__name__,
406
403
def snapshot(self, revision, path, previous_entries,
407
404
work_tree, commit_builder):
500
497
class RootEntry(InventoryEntry):
499
__slots__ = ['text_sha1', 'text_size', 'file_id', 'name', 'kind',
500
'text_id', 'parent_id', 'children', 'executable',
501
'revision', 'symlink_target']
502
503
def _check(self, checker, rev_id, tree):
503
504
"""See InventoryEntry._check"""
520
522
class InventoryDirectory(InventoryEntry):
521
523
"""A directory in an inventory."""
525
__slots__ = ['text_sha1', 'text_size', 'file_id', 'name', 'kind',
526
'text_id', 'parent_id', 'children', 'executable',
527
'revision', 'symlink_target']
523
529
def _check(self, checker, rev_id, tree):
524
530
"""See InventoryEntry._check"""
525
if self.text_sha1 != None or self.text_size != None or self.text_id != None:
531
if self.text_sha1 is not None or self.text_size is not None or self.text_id is not None:
526
532
raise BzrCheckError('directory {%s} has text in revision {%s}'
527
533
% (self.file_id, rev_id))
563
569
class InventoryFile(InventoryEntry):
564
570
"""A file in an inventory."""
572
__slots__ = ['text_sha1', 'text_size', 'file_id', 'name', 'kind',
573
'text_id', 'parent_id', 'children', 'executable',
574
'revision', 'symlink_target']
566
576
def _check(self, checker, tree_revision_id, tree):
567
577
"""See InventoryEntry._check"""
568
578
t = (self.file_id, self.revision)
608
618
def detect_changes(self, old_entry):
609
619
"""See InventoryEntry.detect_changes."""
610
assert self.text_sha1 != None
611
assert old_entry.text_sha1 != None
620
assert self.text_sha1 is not None
621
assert old_entry.text_sha1 is not None
612
622
text_modified = (self.text_sha1 != old_entry.text_sha1)
613
623
meta_modified = (self.executable != old_entry.executable)
614
624
return text_modified, meta_modified
699
718
class InventoryLink(InventoryEntry):
700
719
"""A file in an inventory."""
702
__slots__ = ['symlink_target']
721
__slots__ = ['text_sha1', 'text_size', 'file_id', 'name', 'kind',
722
'text_id', 'parent_id', 'children', 'executable',
723
'revision', 'symlink_target']
704
725
def _check(self, checker, rev_id, tree):
705
726
"""See InventoryEntry._check"""
706
if self.text_sha1 != None or self.text_size != None or self.text_id != None:
727
if self.text_sha1 is not None or self.text_size is not None or self.text_id is not None:
707
728
raise BzrCheckError('symlink {%s} has text in revision {%s}'
708
729
% (self.file_id, rev_id))
709
730
if self.symlink_target is None:
823
844
>>> inv = Inventory('TREE_ROOT-12345678-12345678')
824
845
>>> inv.add(InventoryFile('123-123', 'hello.c', ROOT_ID))
825
InventoryFile('123-123', 'hello.c', parent_id='TREE_ROOT-12345678-12345678')
846
InventoryFile('123-123', 'hello.c', parent_id='TREE_ROOT-12345678-12345678', sha1=None, len=None)
827
848
def __init__(self, root_id=ROOT_ID, revision_id=None):
828
849
"""Create or read an inventory.
1086
1109
>>> i1.add(InventoryFile('123', 'foo', ROOT_ID))
1087
InventoryFile('123', 'foo', parent_id='TREE_ROOT')
1110
InventoryFile('123', 'foo', parent_id='TREE_ROOT', sha1=None, len=None)
1090
1113
>>> i2.add(InventoryFile('123', 'foo', ROOT_ID))
1091
InventoryFile('123', 'foo', parent_id='TREE_ROOT')
1114
InventoryFile('123', 'foo', parent_id='TREE_ROOT', sha1=None, len=None)
1095
1118
if not isinstance(other, Inventory):
1096
1119
return NotImplemented
1098
if len(self._byid) != len(other._byid):
1099
# shortcut: obviously not the same
1102
1121
return self._byid == other._byid
1104
1123
def __ne__(self, other):