670
669
def _read_tree_state(self, path, work_tree):
671
670
"""See InventoryEntry._read_tree_state."""
672
self.text_sha1 = work_tree.get_file_sha1(self.file_id, path=path)
673
self.executable = work_tree.is_executable(self.file_id, path=path)
671
self.text_sha1 = work_tree.get_file_sha1(self.file_id)
672
self.executable = work_tree.is_executable(self.file_id)
675
674
def _forget_tree_state(self):
676
675
self.text_sha1 = None
828
827
May also look up by name:
830
829
>>> [x[0] for x in inv.iter_entries()]
832
831
>>> inv = Inventory('TREE_ROOT-12345678-12345678')
833
832
>>> inv.add(InventoryFile('123-123', 'hello.c', ROOT_ID))
834
833
InventoryFile('123-123', 'hello.c', parent_id='TREE_ROOT-12345678-12345678')
881
880
elif isinstance(from_dir, basestring):
882
881
from_dir = self._byid[from_dir]
884
# unrolling the recursive called changed the time from
885
# 440ms/663ms (inline/total) to 116ms/116ms
886
children = from_dir.children.items()
888
children = collections.deque(children)
889
stack = [(u'', children)]
891
from_dir_relpath, children = stack[-1]
894
name, ie = children.popleft()
896
# we know that from_dir_relpath never ends in a slash
897
# and 'f' doesn't begin with one, we can do a string op, rather
898
# than the checks of pathjoin(), though this means that all paths
900
path = from_dir_relpath + '/' + name
904
if ie.kind != 'directory':
907
# But do this child first
908
new_children = ie.children.items()
910
new_children = collections.deque(new_children)
911
stack.append((path, new_children))
912
# Break out of inner loop, so that we start outer loop with child
915
# if we finished all children, pop it off the stack
883
kids = from_dir.children.items()
885
for name, ie in kids:
887
if ie.kind == 'directory':
888
for cn, cie in self.iter_entries(from_dir=ie.file_id):
889
yield pathjoin(name, cn), cie
918
892
def entries(self):
919
893
"""Return list of (path, ie) for all entries except the root.
1022
def add_path(self, relpath, kind, file_id=None, parent_id=None):
996
def add_path(self, relpath, kind, file_id=None):
1023
997
"""Add entry from a path.
1025
999
The immediate parent must already be versioned.
1035
1009
self._byid = {self.root.file_id: self.root}
1013
file_id = bzrlib.workingtree.gen_file_id(parts[-1])
1038
1014
parent_path = parts[:-1]
1039
1015
parent_id = self.path2id(parent_path)
1040
1016
if parent_id == None:
1041
1017
raise NotVersionedError(path=parent_path)
1042
ie = make_entry(kind, parts[-1], parent_id, file_id)
1018
if kind == 'directory':
1019
ie = InventoryDirectory(file_id, parts[-1], parent_id)
1020
elif kind == 'file':
1021
ie = InventoryFile(file_id, parts[-1], parent_id)
1022
elif kind == 'symlink':
1023
ie = InventoryLink(file_id, parts[-1], parent_id)
1025
raise BzrError("unknown kind %r" % kind)
1043
1026
return self.add(ie)
1045
1029
def __delitem__(self, file_id):
1046
1030
"""Remove entry by id.
1143
1127
This returns the entry of the last component in the path,
1144
1128
which may be either a file or a directory.
1146
Returns None IFF the path is not found.
1130
Returns None iff the path is not found.
1148
1132
if isinstance(name, types.StringTypes):
1149
1133
name = splitpath(name)
1151
# mutter("lookup path %r" % name)
1135
mutter("lookup path %r" % name)
1153
1137
parent = self.root
1202
1186
file_ie.parent_id = new_parent_id
1205
def make_entry(kind, name, parent_id, file_id=None):
1206
"""Create an inventory entry.
1208
:param kind: the type of inventory entry to create.
1209
:param name: the basename of the entry.
1210
:param parent_id: the parent_id of the entry.
1211
:param file_id: the file_id to use. if None, one will be created.
1214
file_id = bzrlib.workingtree.gen_file_id(name)
1215
if kind == 'directory':
1216
return InventoryDirectory(file_id, name, parent_id)
1217
elif kind == 'file':
1218
return InventoryFile(file_id, name, parent_id)
1219
elif kind == 'symlink':
1220
return InventoryLink(file_id, name, parent_id)
1222
raise BzrError("unknown kind %r" % kind)
1226
1191
_NAME_RE = None