~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

[merge] bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
import bzrlib.errors as errors
31
31
from bzrlib.errors import (BzrError, BzrCheckError, BzrCommandError, 
32
32
                           NotBranchError, DivergedBranches, NotConflicted,
33
 
                           NoSuchFile, NoWorkingTree)
 
33
                           NoSuchFile, NoWorkingTree, FileInWrongBranch)
34
34
from bzrlib.option import Option
35
35
from bzrlib.revisionspec import RevisionSpec
36
36
import bzrlib.trace
41
41
def branch_files(file_list, default_branch='.'):
42
42
    try:
43
43
        return inner_branch_files(file_list, default_branch)
44
 
    except NotBranchError:
 
44
    except FileInWrongBranch, e:
45
45
        raise BzrCommandError("%s is not in the same branch as %s" %
46
 
                             (filename, file_list[0]))
 
46
                             (e.path, file_list[0]))
47
47
 
48
48
def inner_branch_files(file_list, default_branch='.'):
49
49
    """\
62
62
    tree = WorkingTree(b.base, b)
63
63
    new_list = []
64
64
    for filename in file_list:
65
 
        new_list.append(tree.relpath(filename))
 
65
        try:
 
66
            new_list.append(tree.relpath(filename))
 
67
        except NotBranchError:
 
68
            raise FileInWrongBranch(b, filename)
66
69
    return b, new_list
67
70
 
68
71
 
257
260
 
258
261
 
259
262
class cmd_inventory(Command):
260
 
    """Show inventory of the current working copy or a revision."""
261
 
    takes_options = ['revision', 'show-ids']
 
263
    """Show inventory of the current working copy or a revision.
 
264
 
 
265
    It is possible to limit the output to a particular entry
 
266
    type using the --kind option.  For example; --kind file.
 
267
    """
 
268
    takes_options = ['revision', 'show-ids', 'kind']
262
269
    
263
270
    @display_command
264
 
    def run(self, revision=None, show_ids=False):
 
271
    def run(self, revision=None, show_ids=False, kind=None):
 
272
        if kind and kind not in ['file', 'directory', 'symlink']:
 
273
            raise BzrCommandError('invalid kind specified')
265
274
        b = Branch.open_containing('.')[0]
266
275
        if revision is None:
267
276
            inv = b.working_tree().read_working_inventory()
272
281
            inv = b.get_revision_inventory(revision[0].in_history(b).rev_id)
273
282
 
274
283
        for path, entry in inv.entries():
 
284
            if kind and kind != entry.kind:
 
285
                continue
275
286
            if show_ids:
276
287
                print '%-50s %s' % (path, entry.file_id)
277
288
            else:
668
679
            print revision_id
669
680
 
670
681
 
671
 
class cmd_directories(Command):
672
 
    """Display list of versioned directories in this branch."""
673
 
    @display_command
674
 
    def run(self):
675
 
        for name, ie in (Branch.open_containing('.')[0].working_tree().
676
 
                         read_working_inventory().directories()):
677
 
            if name == '':
678
 
                print '.'
679
 
            else:
680
 
                print name
681
 
 
682
 
 
683
682
class cmd_init(Command):
684
683
    """Make a directory into a versioned branch.
685
684
 
744
743
        try:
745
744
            b, file_list = inner_branch_files(file_list)
746
745
            b2 = None
747
 
        except NotBranchError:
 
746
        except FileInWrongBranch:
748
747
            if len(file_list) != 2:
749
748
                raise BzrCommandError("Files are in different branches")
750
749
 
902
901
        else:
903
902
            raise BzrCommandError('bzr log --revision takes one or two values.')
904
903
 
905
 
        if rev1 == 0:
906
 
            rev1 = None
907
 
        if rev2 == 0:
908
 
            rev2 = None
 
904
        # By this point, the revision numbers are converted to the +ve
 
905
        # form if they were supplied in the -ve form, so we can do
 
906
        # this comparison in relative safety
 
907
        if rev1 > rev2:
 
908
            (rev2, rev1) = (rev1, rev2)
909
909
 
910
910
        mutter('encoding log as %r', bzrlib.user_encoding)
911
911