~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: John Arbash Meinel
  • Date: 2007-02-28 15:44:12 UTC
  • mto: (2255.11.3 dirstate)
  • mto: This revision was merged to the branch mainline in revision 2322.
  • Revision ID: john@arbash-meinel.com-20070228154412-3pwfza0d3839qpsg
Rework cmd_inventory so that it uses paths2ids and locks the trees for read.

Show diffs side-by-side

added added

removed removed

Lines of Context:
430
430
            raise errors.BzrCommandError('invalid kind specified')
431
431
 
432
432
        work_tree, file_list = tree_files(file_list)
433
 
 
434
 
        if revision is not None:
435
 
            if len(revision) > 1:
436
 
                raise errors.BzrCommandError('bzr inventory --revision takes'
437
 
                                             ' exactly one revision identifier')
438
 
            revision_id = revision[0].in_history(work_tree.branch).rev_id
439
 
            tree = work_tree.branch.repository.revision_tree(revision_id)
440
 
                        
441
 
            # We include work_tree as well as 'tree' here
442
 
            # So that doing '-r 10 path/foo' will lookup whatever file
443
 
            # exists now at 'path/foo' even if it has been renamed, as
444
 
            # well as whatever files existed in revision 10 at path/foo
445
 
            trees = [tree, work_tree]
446
 
        else:
447
 
            tree = work_tree
448
 
            trees = [tree]
449
 
 
450
 
        if file_list is not None:
451
 
            file_ids = _mod_tree.find_ids_across_trees(file_list, trees,
452
 
                                                      require_versioned=True)
453
 
            # find_ids_across_trees may include some paths that don't
454
 
            # exist in 'tree'.
455
 
            entries = sorted((tree.id2path(file_id), tree.inventory[file_id])
456
 
                             for file_id in file_ids if file_id in tree)
457
 
        else:
458
 
            entries = tree.inventory.entries()
 
433
        work_tree.lock_read()
 
434
        try:
 
435
            if revision is not None:
 
436
                if len(revision) > 1:
 
437
                    raise errors.BzrCommandError(
 
438
                        'bzr inventory --revision takes exactly one revision'
 
439
                        ' identifier')
 
440
                revision_id = revision[0].in_history(work_tree.branch).rev_id
 
441
                tree = work_tree.branch.repository.revision_tree(revision_id)
 
442
 
 
443
                extra_trees = [work_tree]
 
444
                tree.lock_read()
 
445
            else:
 
446
                tree = work_tree
 
447
                extra_trees = []
 
448
 
 
449
            if file_list is not None:
 
450
                file_ids = tree.paths2ids(file_list, trees=extra_trees,
 
451
                                          require_versioned=True)
 
452
                # find_ids_across_trees may include some paths that don't
 
453
                # exist in 'tree'.
 
454
                entries = sorted((tree.id2path(file_id), tree.inventory[file_id])
 
455
                                 for file_id in file_ids if file_id in tree)
 
456
            else:
 
457
                entries = tree.inventory.entries()
 
458
        finally:
 
459
            tree.unlock()
 
460
            if tree is not work_tree:
 
461
                work_tree.unlock()
459
462
 
460
463
        for path, entry in entries:
461
464
            if kind and kind != entry.kind: