54
54
from bzrlib.revisionspec import RevisionSpec
55
55
from bzrlib.trace import mutter, note, log_error, warning, is_quiet, info
56
56
from bzrlib.transport.local import LocalTransport
57
58
from bzrlib.workingtree import WorkingTree
361
362
"""Show inventory of the current working copy or a revision.
363
364
It is possible to limit the output to a particular entry
364
type using the --kind option. For example; --kind file.
365
type using the --kind option. For example: --kind file.
367
It is also possible to restrict the list of files to a specific
368
set. For example: bzr inventory --show-ids this/file
367
371
takes_options = ['revision', 'show-ids', 'kind']
372
takes_args = ['file*']
370
def run(self, revision=None, show_ids=False, kind=None):
375
def run(self, revision=None, show_ids=False, kind=None, file_list=None):
371
376
if kind and kind not in ['file', 'directory', 'symlink']:
372
377
raise BzrCommandError('invalid kind specified')
373
tree = WorkingTree.open_containing(u'.')[0]
375
inv = tree.read_working_inventory()
379
work_tree, file_list = tree_files(file_list)
381
if revision is not None:
377
382
if len(revision) > 1:
378
383
raise BzrCommandError('bzr inventory --revision takes'
379
' exactly one revision identifier')
380
inv = tree.branch.repository.get_revision_inventory(
381
revision[0].in_history(tree.branch).rev_id)
383
for path, entry in inv.entries():
384
' exactly one revision identifier')
385
revision_id = revision[0].in_history(work_tree.branch).rev_id
386
tree = work_tree.branch.repository.revision_tree(revision_id)
388
# We include work_tree as well as 'tree' here
389
# So that doing '-r 10 path/foo' will lookup whatever file
390
# exists now at 'path/foo' even if it has been renamed, as
391
# well as whatever files existed in revision 10 at path/foo
392
trees = [tree, work_tree]
397
if file_list is not None:
398
file_ids = bzrlib.tree.find_ids_across_trees(file_list, trees,
399
require_versioned=True)
400
# find_ids_across_trees may include some paths that don't
402
entries = sorted((tree.id2path(file_id), tree.inventory[file_id])
403
for file_id in file_ids if file_id in tree)
405
entries = tree.inventory.entries()
407
for path, entry in entries:
384
408
if kind and kind != entry.kind: