/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Ian Clatworthy
  • Date: 2009-05-18 07:48:02 UTC
  • mto: (4456.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4457.
  • Revision ID: ian.clatworthy@canonical.com-20090518074802-dbx8ats78vl134y6
refactor ls command to use new APIs

Show diffs side-by-side

added added

removed removed

Lines of Context:
2353
2353
            recursive=False, from_root=False,
2354
2354
            unknown=False, versioned=False, ignored=False,
2355
2355
            null=False, kind=None, show_ids=False, path=None):
2356
 
 
 
2356
        # Validate the command line options
2357
2357
        if kind and kind not in ('file', 'directory', 'symlink'):
2358
2358
            raise errors.BzrCommandError('invalid kind specified')
2359
 
 
2360
2359
        if verbose and null:
2361
2360
            raise errors.BzrCommandError('Cannot set both --verbose and --null')
2362
 
        all = not (unknown or versioned or ignored)
2363
 
 
2364
 
        selection = {'I':ignored, '?':unknown, 'V':versioned}
2365
 
 
2366
2361
        if path is None:
2367
 
            fs_path = '.'
2368
 
            prefix = ''
2369
 
        else:
2370
 
            if from_root:
2371
 
                raise errors.BzrCommandError('cannot specify both --from-root'
2372
 
                                             ' and PATH')
2373
 
            fs_path = path
2374
 
            prefix = path
2375
 
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
2376
 
            fs_path)
2377
 
        if from_root:
2378
 
            relpath = u''
2379
 
        elif relpath:
2380
 
            relpath += '/'
 
2362
            path = '.'
 
2363
        elif from_root:
 
2364
            raise errors.BzrCommandError('cannot specify both --from-root'
 
2365
                                         ' and PATH')
 
2366
 
 
2367
        # Get the tree
 
2368
        tree, branch, dir = bzrdir.BzrDir.open_containing_tree_or_branch(path)
 
2369
        mutter("ls dir is %s", dir)
2381
2370
        if revision is not None or tree is None:
2382
2371
            tree = _get_one_revision_tree('ls', revision, branch=branch)
2383
2372
 
2384
 
        apply_view = False
2385
 
        if isinstance(tree, WorkingTree) and tree.supports_views():
2386
 
            view_files = tree.views.lookup_view()
2387
 
            if view_files:
2388
 
                apply_view = True
2389
 
                view_str = views.view_display_str(view_files)
2390
 
                note("Ignoring files outside view. View is %s" % view_str)
 
2373
        # Calculate the prefix to use
 
2374
        prefix = None
 
2375
        if from_root:
 
2376
            if dir:
 
2377
                prefix = dir + '/'
 
2378
        elif path != '.':
 
2379
            prefix = path + '/'
2391
2380
 
2392
 
        tree.lock_read()
2393
 
        try:
2394
 
            for fp, fc, fkind, fid, entry in tree.list_files(include_root=False):
2395
 
                if fp.startswith(relpath):
2396
 
                    rp = fp[len(relpath):]
2397
 
                    fp = osutils.pathjoin(prefix, rp)
2398
 
                    if not recursive and '/' in rp:
2399
 
                        continue
2400
 
                    if not all and not selection[fc]:
2401
 
                        continue
2402
 
                    if kind is not None and fkind != kind:
2403
 
                        continue
2404
 
                    if apply_view:
2405
 
                        try:
2406
 
                            views.check_path_in_view(tree, fp)
2407
 
                        except errors.FileOutsideView:
2408
 
                            continue
2409
 
                    kindch = entry.kind_character()
2410
 
                    outstring = fp + kindch
2411
 
                    if verbose:
2412
 
                        outstring = '%-8s %s' % (fc, outstring)
2413
 
                        if show_ids and fid is not None:
2414
 
                            outstring = "%-50s %s" % (outstring, fid)
2415
 
                        self.outf.write(outstring + '\n')
2416
 
                    elif null:
2417
 
                        self.outf.write(fp + '\0')
2418
 
                        if show_ids:
2419
 
                            if fid is not None:
2420
 
                                self.outf.write(fid)
2421
 
                            self.outf.write('\0')
2422
 
                        self.outf.flush()
2423
 
                    else:
2424
 
                        if fid is not None:
2425
 
                            my_id = fid
2426
 
                        else:
2427
 
                            my_id = ''
2428
 
                        if show_ids:
2429
 
                            self.outf.write('%-50s %s\n' % (outstring, my_id))
2430
 
                        else:
2431
 
                            self.outf.write(outstring + '\n')
2432
 
        finally:
2433
 
            tree.unlock()
 
2381
        # Display the files
 
2382
        from bzrlib import ls
 
2383
        ls.ls(tree, self.outf, from_dir=dir, recursive=recursive,
 
2384
            kind=kind, unknown=unknown, versioned=versioned, ignored=ignored,
 
2385
            verbose=verbose, null=null, show_ids=show_ids, prefix=prefix)
2434
2386
 
2435
2387
 
2436
2388
class cmd_unknowns(Command):