173
173
versioned = inv.has_filename(rf.raw_path)
176
added.extend(__add_one(tree, inv, None, rf, kind, action))
176
added.extend(__add_one_and_parent(tree, inv, None, rf, kind, action))
179
179
# no need to walk any directories at all.
196
196
# directory is tree-relative
197
197
abspath = tree.abspath(directory.raw_path)
199
# get the contents of this directory.
199
201
# find the kind of the path being added.
200
202
kind = bzrlib.osutils.file_kind(abspath)
231
233
mutter("%r is a nested bzr tree", abspath)
233
added.extend(__add_one(tree, inv, parent_ie, directory, kind, action))
235
__add_one(tree, inv, parent_ie, directory, kind, action)
236
added.append(directory.raw_path)
235
238
if kind == 'directory' and not sub_tree:
236
239
if parent_ie is not None:
277
280
return added, ignored
280
def __add_one(tree, inv, parent_ie, path, kind, action):
283
def __add_one_and_parent(tree, inv, parent_ie, path, kind, action):
281
284
"""Add a new entry to the inventory and automatically add unversioned parents.
283
Actual adding of the entry is delegated to the action callback.
285
286
:param inv: Inventory which will receive the new entry.
286
287
:param parent_ie: Parent inventory entry if known, or None. If
287
288
None, the parent is looked up by name and used if present, otherwise
290
291
:param action: callback(inv, parent_ie, path, kind); return ignored.
291
292
:returns: A list of paths which have been added.
294
294
# Nothing to do if path is already versioned.
295
295
# This is safe from infinite recursion because the tree root is
296
296
# always versioned.
305
305
# note that the dirname use leads to some extra str copying etc but as
306
306
# there are a limited number of dirs we can be nested under, it should
307
307
# generally find it very fast and not recurse after that.
308
added = __add_one(tree, inv, None, FastPath(dirname(path.raw_path)), 'directory', action)
308
added = __add_one_and_parent(tree, inv, None, FastPath(dirname(path.raw_path)), 'directory', action)
309
309
parent_id = inv.path2id(dirname(path.raw_path))
310
310
if parent_id is None:
311
311
parent_ie = inv[inv.path2id(dirname(path.raw_path))]
313
313
parent_ie = inv[parent_id]
314
__add_one(tree, inv, parent_ie, path, kind, action)
315
return added + [path.raw_path]
318
def __add_one(tree, inv, parent_ie, path, kind, action):
319
"""Add a new entry to the inventory.
321
:param inv: Inventory which will receive the new entry.
322
:param parent_ie: Parent inventory entry.
323
:param kind: Kind of new entry (file, directory, etc)
324
:param action: callback(inv, parent_ie, path, kind); return ignored.
314
327
action(inv, parent_ie, path, kind)
315
#if parent_ie is not None:
316
entry = bzrlib.inventory.make_entry(
317
kind, bzrlib.osutils.basename(path.raw_path), parent_ie.file_id)
328
entry = bzrlib.inventory.make_entry(kind, path.base_path, parent_ie.file_id)
320
# entry = inv.add_path(path.raw_path, kind=kind)
323
return added + [path.raw_path]