335
336
yield (old_name, new_name)
339
def find_ids_across_trees(filenames, trees, require_versioned=True):
340
"""Find the ids corresponding to specified filenames.
342
All matches in all trees will be used, and all children of matched
343
directories will be used.
345
:param filenames: The filenames to find file_ids for
346
:param trees: The trees to find file_ids within
347
:param require_versioned: if true, all specified filenames must occur in
349
:return: a set of file ids for the specified filenames and their children.
353
specified_ids = _find_filename_ids_across_trees(filenames, trees,
355
return _find_children_across_trees(specified_ids, trees)
358
def _find_filename_ids_across_trees(filenames, trees, require_versioned):
359
"""Find the ids corresponding to specified filenames.
361
All matches in all trees will be used.
363
:param filenames: The filenames to find file_ids for
364
:param trees: The trees to find file_ids within
365
:param require_versioned: if true, all specified filenames must occur in
367
:return: a set of file ids for the specified filenames
370
interesting_ids = set()
371
for tree_path in filenames:
374
file_id = tree.inventory.path2id(tree_path)
375
if file_id is not None:
376
interesting_ids.add(file_id)
379
not_versioned.append(tree_path)
380
if len(not_versioned) > 0 and require_versioned:
381
raise errors.PathsNotVersionedError(not_versioned)
382
return interesting_ids
385
def _find_children_across_trees(specified_ids, trees):
386
"""Return a set including specified ids and their children
388
All matches in all trees will be used.
390
:param trees: The trees to find file_ids within
391
:return: a set containing all specified ids and their children
393
interesting_ids = set(specified_ids)
394
pending = interesting_ids
395
# now handle children of interesting ids
396
# we loop so that we handle all children of each id in both trees
397
while len(pending) > 0:
399
for file_id in pending:
401
if file_id not in tree:
403
entry = tree.inventory[file_id]
404
for child in getattr(entry, 'children', {}).itervalues():
405
if child.file_id not in interesting_ids:
406
new_pending.add(child.file_id)
407
interesting_ids.update(new_pending)
408
pending = new_pending
409
return interesting_ids