~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:
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
import bzrlib.tree
57
58
from bzrlib.workingtree import WorkingTree
58
59
 
59
60
 
361
362
    """Show inventory of the current working copy or a revision.
362
363
 
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.
 
366
 
 
367
    It is also possible to restrict the list of files to a specific
 
368
    set. For example: bzr inventory --show-ids this/file
365
369
    """
366
370
 
367
371
    takes_options = ['revision', 'show-ids', 'kind']
368
 
    
 
372
    takes_args = ['file*']
 
373
 
369
374
    @display_command
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]
374
 
        if revision is None:
375
 
            inv = tree.read_working_inventory()
376
 
        else:
 
378
 
 
379
        work_tree, file_list = tree_files(file_list)
 
380
 
 
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)
382
 
 
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)
 
387
                        
 
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]
 
393
        else:
 
394
            tree = work_tree
 
395
            trees = [tree]
 
396
 
 
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
 
401
            # exist in 'tree'.
 
402
            entries = sorted((tree.id2path(file_id), tree.inventory[file_id])
 
403
                             for file_id in file_ids if file_id in tree)
 
404
        else:
 
405
            entries = tree.inventory.entries()
 
406
 
 
407
        for path, entry in entries:
384
408
            if kind and kind != entry.kind:
385
409
                continue
386
410
            if show_ids:
2002
2026
                test_suite_factory = benchmarks.test_suite
2003
2027
                if verbose is None:
2004
2028
                    verbose = True
 
2029
                # TODO: should possibly lock the history file...
2005
2030
                benchfile = open(".perf_history", "at")
2006
2031
            else:
2007
2032
                test_suite_factory = None
2325
2350
            return 0
2326
2351
 
2327
2352
class cmd_revert(Command):
2328
 
    """Reverse all changes since the last commit.
2329
 
 
2330
 
    Only versioned files are affected.  Specify filenames to revert only 
2331
 
    those files.  By default, any files that are changed will be backed up
2332
 
    first.  Backup files have a '~' appended to their name.
 
2353
    """Revert files to a previous revision.
 
2354
 
 
2355
    Giving a list of files will revert only those files.  Otherwise, all files
 
2356
    will be reverted.  If the revision is not specified with '--revision', the
 
2357
    last committed revision is used.
 
2358
 
 
2359
    To remove only some changes, without reverting to a prior version, use
 
2360
    merge instead.  For example, "merge . --r-2..-3" will remove the changes
 
2361
    introduced by -2, without affecting the changes introduced by -1.  Or
 
2362
    to remove certain changes on a hunk-by-hunk basis, see the Shelf plugin.
 
2363
    
 
2364
    By default, any files that have been manually changed will be backed up
 
2365
    first.  (Files changed only by merge are not backed up.)  Backup files have
 
2366
    '.~#~' appended to their name, where # is a number.
 
2367
 
 
2368
    When you provide files, you can use their current pathname or the pathname
 
2369
    from the target revision.  So you can use revert to "undelete" a file by
 
2370
    name.  If you name a directory, all the contents of that directory will be
 
2371
    reverted.
2333
2372
    """
2334
2373
    takes_options = ['revision', 'no-backup']
2335
2374
    takes_args = ['file*']
2782
2821
 
2783
2822
 
2784
2823
class cmd_serve(Command):
2785
 
    """Run the bzr server.
2786
 
    """
 
2824
    """Run the bzr server."""
 
2825
 
 
2826
    aliases = ['server']
 
2827
 
2787
2828
    takes_options = [
2788
2829
        Option('inet',
2789
2830
               help='serve on stdin/out for use from inetd or sshd'),
2795
2836
        Option('directory',
2796
2837
               help='serve contents of directory',
2797
2838
               type=unicode),
 
2839
        Option('allow-writes',
 
2840
               help='By default the server is a readonly server. Supplying '
 
2841
                    '--allow-writes enables write access to the contents of '
 
2842
                    'the served directory and below. '
 
2843
                ),
2798
2844
        ]
2799
2845
 
2800
 
    def run(self, port=None, inet=False, directory=None):
 
2846
    def run(self, port=None, inet=False, directory=None, allow_writes=False):
2801
2847
        from bzrlib.transport import smart
2802
2848
        from bzrlib.transport import get_transport
2803
2849
        if directory is None:
2804
2850
            directory = os.getcwd()
2805
 
        t = get_transport(directory)
 
2851
        url = urlutils.local_path_to_url(directory)
 
2852
        if not allow_writes:
 
2853
            url = 'readonly+' + url
 
2854
        t = get_transport(url)
2806
2855
        if inet:
2807
2856
            server = smart.SmartStreamServer(sys.stdin, sys.stdout, t)
2808
2857
        elif port is not None:
2892
2941
# we do need to load at least some information about them to know of 
2893
2942
# aliases.  ideally we would avoid loading the implementation until the
2894
2943
# details were needed.
 
2944
from bzrlib.cmd_version_info import cmd_version_info
2895
2945
from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore
2896
2946
from bzrlib.bundle.commands import cmd_bundle_revisions
2897
2947
from bzrlib.sign_my_commits import cmd_sign_my_commits