958
958
descend(self.root, u'')
961
def path2id(self, name):
961
def path2id(self, relpath):
962
962
"""Walk down through directories to return entry of last component.
964
names may be either a list of path components, or a single
965
string, in which case it is automatically split.
964
:param relpath: may be either a list of path components, or a single
965
string, in which case it is automatically split.
967
967
This returns the entry of the last component in the path,
968
968
which may be either a file or a directory.
970
970
Returns None IFF the path is not found.
972
if isinstance(name, basestring):
973
name = osutils.splitpath(name)
975
# mutter("lookup path %r" % name)
972
if isinstance(relpath, basestring):
973
names = osutils.splitpath(relpath)
978
978
parent = self.root
2170
2170
delta.append((old_path, new_path, file_id, entry))
2173
def path2id(self, name):
2173
def path2id(self, relpath):
2174
2174
"""See CommonInventory.path2id()."""
2175
2175
# TODO: perhaps support negative hits?
2176
result = self._path_to_fileid_cache.get(name, None)
2176
result = self._path_to_fileid_cache.get(relpath, None)
2177
2177
if result is not None:
2179
if isinstance(name, basestring):
2180
names = osutils.splitpath(name)
2179
if isinstance(relpath, basestring):
2180
names = osutils.splitpath(relpath)
2183
2183
current_id = self.root_id
2184
2184
if current_id is None:
2186
2186
parent_id_index = self.parent_id_basename_to_file_id
2187
2188
for basename in names:
2188
# TODO: Cache each path we figure out in this function.
2189
if cur_path is None:
2192
cur_path = cur_path + '/' + basename
2189
2193
basename_utf8 = basename.encode('utf8')
2190
key_filter = [(current_id, basename_utf8)]
2192
for (parent_id, name_utf8), file_id in parent_id_index.iteritems(
2193
key_filter=key_filter):
2194
if parent_id != current_id or name_utf8 != basename_utf8:
2195
raise errors.BzrError("corrupt inventory lookup! "
2196
"%r %r %r %r" % (parent_id, current_id, name_utf8,
2194
file_id = self._path_to_fileid_cache.get(cur_path, None)
2198
2195
if file_id is None:
2196
key_filter = [(current_id, basename_utf8)]
2197
items = parent_id_index.iteritems(key_filter)
2198
for (parent_id, name_utf8), file_id in items:
2199
if parent_id != current_id or name_utf8 != basename_utf8:
2200
raise errors.BzrError("corrupt inventory lookup! "
2201
"%r %r %r %r" % (parent_id, current_id, name_utf8,
2206
self._path_to_fileid_cache[cur_path] = file_id
2200
2207
current_id = file_id
2201
self._path_to_fileid_cache[name] = current_id
2202
2208
return current_id
2204
2210
def to_lines(self):