~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

[merge] fixes for ls

Show diffs side-by-side

added added

removed removed

Lines of Context:
829
829
    """
830
830
    # TODO: Take a revision or remote path and list that tree instead.
831
831
    hidden = True
 
832
    takes_options = ['verbose', 'revision',
 
833
                     Option('non-recursive',
 
834
                            help='don\'t recurse into sub-directories'),
 
835
                     Option('from-root',
 
836
                            help='Print all paths from the root of the branch.'),
 
837
                     Option('unknown', help='Print unknown files'),
 
838
                     Option('versioned', help='Print versioned files'),
 
839
                     Option('ignored', help='Print ignored files'),
 
840
 
 
841
                     Option('null', help='Null separate the files'),
 
842
                    ]
832
843
    @display_command
833
 
    def run(self, revision=None, verbose=False):
834
 
        b, relpath = Branch.open_containing('.')[0]
 
844
    def run(self, revision=None, verbose=False, 
 
845
            non_recursive=False, from_root=False,
 
846
            unknown=False, versioned=False, ignored=False,
 
847
            null=False):
 
848
 
 
849
        if verbose and null:
 
850
            raise BzrCommandError('Cannot set both --verbose and --null')
 
851
        all = not (unknown or versioned or ignored)
 
852
 
 
853
        selection = {'I':ignored, '?':unknown, 'V':versioned}
 
854
 
 
855
        b, relpath = Branch.open_containing('.')
 
856
        if from_root:
 
857
            relpath = ''
 
858
        elif relpath:
 
859
            relpath += '/'
835
860
        if revision == None:
836
861
            tree = b.working_tree()
837
862
        else:
838
 
            tree = b.revision_tree(revision.in_history(b).rev_id)
 
863
            tree = b.revision_tree(revision[0].in_history(b).rev_id)
839
864
        for fp, fc, kind, fid, entry in tree.list_files():
840
 
            if verbose:
841
 
                kindch = entry.kind_character()
842
 
                print '%-8s %s%s' % (fc, fp, kindch)
843
 
            else:
844
 
                print fp
 
865
            if fp.startswith(relpath):
 
866
                fp = fp[len(relpath):]
 
867
                if non_recursive and '/' in fp:
 
868
                    continue
 
869
                if not all and not selection[fc]:
 
870
                    continue
 
871
                if verbose:
 
872
                    kindch = entry.kind_character()
 
873
                    print '%-8s %s%s' % (fc, fp, kindch)
 
874
                elif null:
 
875
                    sys.stdout.write(fp)
 
876
                    sys.stdout.write('\0')
 
877
                    sys.stdout.flush()
 
878
                else:
 
879
                    print fp
845
880
 
846
881
 
847
882