79
80
>>> i.add(InventoryDirectory('123', 'src', ROOT_ID))
80
InventoryDirectory('123', 'src', parent_id='TREE_ROOT')
81
InventoryDirectory('123', 'src', parent_id='TREE_ROOT', revision=None)
81
82
>>> i.add(InventoryFile('2323', 'hello.c', parent_id='123'))
82
InventoryFile('2323', 'hello.c', parent_id='123')
83
InventoryFile('2323', 'hello.c', parent_id='123', sha1=None, len=None)
83
84
>>> shouldbe = {0: 'src', 1: pathjoin('src','hello.c')}
84
85
>>> for ix, j in enumerate(i.iter_entries()):
85
86
... 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'))
88
(True, InventoryDirectory('123', 'src', parent_id='TREE_ROOT', revision=None))
89
(True, InventoryFile('2323', 'hello.c', parent_id='123', sha1=None, len=None))
89
90
>>> i.add(InventoryFile('2323', 'bye.c', '123'))
90
91
Traceback (most recent call last):
92
93
BzrError: inventory already contains entry with id {2323}
93
94
>>> i.add(InventoryFile('2324', 'bye.c', '123'))
94
InventoryFile('2324', 'bye.c', parent_id='123')
95
InventoryFile('2324', 'bye.c', parent_id='123', sha1=None, len=None)
95
96
>>> i.add(InventoryDirectory('2325', 'wibble', '123'))
96
InventoryDirectory('2325', 'wibble', parent_id='123')
97
InventoryDirectory('2325', 'wibble', parent_id='123', revision=None)
97
98
>>> i.path2id('src/wibble')
101
102
>>> i.add(InventoryFile('2326', 'wibble.c', '2325'))
102
InventoryFile('2326', 'wibble.c', parent_id='2325')
103
InventoryFile('2326', 'wibble.c', parent_id='2325', sha1=None, len=None)
104
InventoryFile('2326', 'wibble.c', parent_id='2325')
105
InventoryFile('2326', 'wibble.c', parent_id='2325', sha1=None, len=None)
105
106
>>> for path, entry in i.iter_entries():
107
108
... assert i.path2id(path)
123
124
RENAMED = 'renamed'
124
125
MODIFIED_AND_RENAMED = 'modified and renamed'
126
__slots__ = ['text_sha1', 'text_size', 'file_id', 'name', 'kind',
127
'text_id', 'parent_id', 'children', 'executable',
130
129
def detect_changes(self, old_entry):
131
130
"""Return a (text_modified, meta_modified) from this to old_entry.
397
394
return 'unchanged'
399
396
def __repr__(self):
400
return ("%s(%r, %r, parent_id=%r)"
397
return ("%s(%r, %r, parent_id=%r, revision=%r)"
401
398
% (self.__class__.__name__,
406
404
def snapshot(self, revision, path, previous_entries,
407
405
work_tree, commit_builder):
500
498
class RootEntry(InventoryEntry):
500
__slots__ = ['text_sha1', 'text_size', 'file_id', 'name', 'kind',
501
'text_id', 'parent_id', 'children', 'executable',
502
'revision', 'symlink_target']
502
504
def _check(self, checker, rev_id, tree):
503
505
"""See InventoryEntry._check"""
520
523
class InventoryDirectory(InventoryEntry):
521
524
"""A directory in an inventory."""
526
__slots__ = ['text_sha1', 'text_size', 'file_id', 'name', 'kind',
527
'text_id', 'parent_id', 'children', 'executable',
528
'revision', 'symlink_target']
523
530
def _check(self, checker, rev_id, tree):
524
531
"""See InventoryEntry._check"""
525
if self.text_sha1 != None or self.text_size != None or self.text_id != None:
532
if self.text_sha1 is not None or self.text_size is not None or self.text_id is not None:
526
533
raise BzrCheckError('directory {%s} has text in revision {%s}'
527
534
% (self.file_id, rev_id))
563
570
class InventoryFile(InventoryEntry):
564
571
"""A file in an inventory."""
573
__slots__ = ['text_sha1', 'text_size', 'file_id', 'name', 'kind',
574
'text_id', 'parent_id', 'children', 'executable',
575
'revision', 'symlink_target']
566
577
def _check(self, checker, tree_revision_id, tree):
567
578
"""See InventoryEntry._check"""
568
579
t = (self.file_id, self.revision)
608
619
def detect_changes(self, old_entry):
609
620
"""See InventoryEntry.detect_changes."""
610
assert self.text_sha1 != None
611
assert old_entry.text_sha1 != None
621
assert self.text_sha1 is not None
622
assert old_entry.text_sha1 is not None
612
623
text_modified = (self.text_sha1 != old_entry.text_sha1)
613
624
meta_modified = (self.executable != old_entry.executable)
614
625
return text_modified, meta_modified
671
682
# in _read_tree_state
672
683
self.executable = work_tree.is_executable(self.file_id, path=path)
686
return ("%s(%r, %r, parent_id=%r, sha1=%r, len=%s)"
687
% (self.__class__.__name__,
674
694
def _forget_tree_state(self):
675
695
self.text_sha1 = None
676
self.executable = None
678
697
def _snapshot_text(self, file_parents, work_tree, commit_builder):
679
698
"""See InventoryEntry._snapshot_text."""
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):