~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Aaron Bentley
  • Date: 2010-05-10 11:34:20 UTC
  • mfrom: (5218 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5221.
  • Revision ID: aaron@aaronbentley.com-20100510113420-toh2d5yioobb5uq1
Merged bzr.dev into transform-commit-full.

Show diffs side-by-side

added added

removed removed

Lines of Context:
232
232
    return view_info
233
233
 
234
234
 
 
235
def _open_directory_or_containing_tree_or_branch(filename, directory):
 
236
    """Open the tree or branch containing the specified file, unless
 
237
    the --directory option is used to specify a different branch."""
 
238
    if directory is not None:
 
239
        return (None, Branch.open(directory), filename)
 
240
    return bzrdir.BzrDir.open_containing_tree_or_branch(filename)
 
241
 
 
242
 
235
243
# TODO: Make sure no commands unconditionally use the working directory as a
236
244
# branch.  If a filename argument is used, the first of them should be used to
237
245
# specify the branch.  (Perhaps this can be factored out into some kind of
340
348
 
341
349
    hidden = True
342
350
    takes_args = ['revision_id?']
343
 
    takes_options = ['revision']
 
351
    takes_options = ['directory', 'revision']
344
352
    # cat-revision is more for frontends so should be exact
345
353
    encoding = 'strict'
346
354
 
353
361
        self.outf.write(revtext.decode('utf-8'))
354
362
 
355
363
    @display_command
356
 
    def run(self, revision_id=None, revision=None):
 
364
    def run(self, revision_id=None, revision=None, directory=u'.'):
357
365
        if revision_id is not None and revision is not None:
358
366
            raise errors.BzrCommandError('You can only supply one of'
359
367
                                         ' revision_id or --revision')
360
368
        if revision_id is None and revision is None:
361
369
            raise errors.BzrCommandError('You must supply either'
362
370
                                         ' --revision or a revision_id')
363
 
        b = WorkingTree.open_containing(u'.')[0].branch
 
371
        b = WorkingTree.open_containing(directory)[0].branch
364
372
 
365
373
        revisions = b.repository.revisions
366
374
        if revisions is None:
554
562
    takes_args = ['revision_info*']
555
563
    takes_options = [
556
564
        'revision',
557
 
        Option('directory',
 
565
        custom_help('directory',
558
566
            help='Branch to examine, '
559
 
                 'rather than the one containing the working directory.',
560
 
            short_name='d',
561
 
            type=unicode,
562
 
            ),
 
567
                 'rather than the one containing the working directory.'),
563
568
        Option('tree', help='Show revno of working tree'),
564
569
        ]
565
570
 
960
965
    takes_options = ['remember', 'overwrite', 'revision',
961
966
        custom_help('verbose',
962
967
            help='Show logs of pulled revisions.'),
963
 
        Option('directory',
 
968
        custom_help('directory',
964
969
            help='Branch to pull into, '
965
 
                 'rather than the one containing the working directory.',
966
 
            short_name='d',
967
 
            type=unicode,
968
 
            ),
 
970
                 'rather than the one containing the working directory.'),
969
971
        Option('local',
970
972
            help="Perform a local pull in a bound "
971
973
                 "branch.  Local pulls are not applied to "
1088
1090
        Option('create-prefix',
1089
1091
               help='Create the path leading up to the branch '
1090
1092
                    'if it does not already exist.'),
1091
 
        Option('directory',
 
1093
        custom_help('directory',
1092
1094
            help='Branch to push from, '
1093
 
                 'rather than the one containing the working directory.',
1094
 
            short_name='d',
1095
 
            type=unicode,
1096
 
            ),
 
1095
                 'rather than the one containing the working directory.'),
1097
1096
        Option('use-existing-dir',
1098
1097
               help='By default push will fail if the target'
1099
1098
                    ' directory exists, but does not already'
1350
1349
            except errors.NoWorkingTree:
1351
1350
                source.bzrdir.create_workingtree(revision_id)
1352
1351
                return
 
1352
 
 
1353
        if not lightweight:
 
1354
            message = ('Copying history to "%s". '
 
1355
                'To checkout without local history use --lightweight.' % to_location)
 
1356
            ui.ui_factory.show_message(message)
1353
1357
        source.create_checkout(to_location, revision_id, lightweight,
1354
1358
                               accelerator_tree, hardlink)
1355
1359
 
2003
2007
    # level of effort but possibly much less IO.  (Or possibly not,
2004
2008
    # if the directories are very large...)
2005
2009
    _see_also = ['status', 'ls']
2006
 
    takes_options = ['show-ids']
 
2010
    takes_options = ['directory', 'show-ids']
2007
2011
 
2008
2012
    @display_command
2009
 
    def run(self, show_ids=False):
2010
 
        tree = WorkingTree.open_containing(u'.')[0]
 
2013
    def run(self, show_ids=False, directory=u'.'):
 
2014
        tree = WorkingTree.open_containing(directory)[0]
2011
2015
        tree.lock_read()
2012
2016
        self.add_cleanup(tree.unlock)
2013
2017
        old = tree.basis_tree()
2028
2032
 
2029
2033
    hidden = True
2030
2034
    _see_also = ['status', 'ls']
2031
 
    takes_options = [
2032
 
            Option('null',
2033
 
                   help='Write an ascii NUL (\\0) separator '
2034
 
                   'between files rather than a newline.')
2035
 
            ]
 
2035
    takes_options = ['directory', 'null']
2036
2036
 
2037
2037
    @display_command
2038
 
    def run(self, null=False):
2039
 
        tree = WorkingTree.open_containing(u'.')[0]
 
2038
    def run(self, null=False, directory=u'.'):
 
2039
        tree = WorkingTree.open_containing(directory)[0]
2040
2040
        td = tree.changes_from(tree.basis_tree())
2041
2041
        for path, id, kind, text_modified, meta_modified in td.modified:
2042
2042
            if null:
2051
2051
 
2052
2052
    hidden = True
2053
2053
    _see_also = ['status', 'ls']
2054
 
    takes_options = [
2055
 
            Option('null',
2056
 
                   help='Write an ascii NUL (\\0) separator '
2057
 
                   'between files rather than a newline.')
2058
 
            ]
 
2054
    takes_options = ['directory', 'null']
2059
2055
 
2060
2056
    @display_command
2061
 
    def run(self, null=False):
2062
 
        wt = WorkingTree.open_containing(u'.')[0]
 
2057
    def run(self, null=False, directory=u'.'):
 
2058
        wt = WorkingTree.open_containing(directory)[0]
2063
2059
        wt.lock_read()
2064
2060
        self.add_cleanup(wt.unlock)
2065
2061
        basis = wt.basis_tree()
2073
2069
            if inv.is_root(file_id) and len(basis_inv) == 0:
2074
2070
                continue
2075
2071
            path = inv.id2path(file_id)
2076
 
            if not os.access(osutils.abspath(path), os.F_OK):
 
2072
            if not os.access(osutils.pathjoin(wt.basedir, path), os.F_OK):
2077
2073
                continue
2078
2074
            if null:
2079
2075
                self.outf.write(path + '\0')
2279
2275
                   help='Show just the specified revision.'
2280
2276
                   ' See also "help revisionspec".'),
2281
2277
            'log-format',
 
2278
            RegistryOption('authors',
 
2279
                'What names to list as authors - first, all or committer.',
 
2280
                title='Authors',
 
2281
                lazy_registry=('bzrlib.log', 'author_list_registry'),
 
2282
            ),
2282
2283
            Option('levels',
2283
2284
                   short_name='n',
2284
2285
                   help='Number of levels to display - 0 for all, 1 for flat.',
2319
2320
            limit=None,
2320
2321
            show_diff=False,
2321
2322
            include_merges=False,
 
2323
            authors=None,
2322
2324
            exclude_common_ancestry=False,
2323
2325
            ):
2324
2326
        from bzrlib.log import (
2404
2406
                        show_timezone=timezone,
2405
2407
                        delta_format=get_verbosity_level(),
2406
2408
                        levels=levels,
2407
 
                        show_advice=levels is None)
 
2409
                        show_advice=levels is None,
 
2410
                        author_list_handler=authors)
2408
2411
 
2409
2412
        # Choose the algorithm for doing the logging. It's annoying
2410
2413
        # having multiple code paths like this but necessary until
2528
2531
                   help='Recurse into subdirectories.'),
2529
2532
            Option('from-root',
2530
2533
                   help='Print paths relative to the root of the branch.'),
2531
 
            Option('unknown', help='Print unknown files.'),
 
2534
            Option('unknown', short_name='u',
 
2535
                help='Print unknown files.'),
2532
2536
            Option('versioned', help='Print versioned files.',
2533
2537
                   short_name='V'),
2534
 
            Option('ignored', help='Print ignored files.'),
2535
 
            Option('null',
2536
 
                   help='Write an ascii NUL (\\0) separator '
2537
 
                   'between files rather than a newline.'),
2538
 
            Option('kind',
 
2538
            Option('ignored', short_name='i',
 
2539
                help='Print ignored files.'),
 
2540
            Option('kind', short_name='k',
2539
2541
                   help='List entries of a particular kind: file, directory, symlink.',
2540
2542
                   type=unicode),
 
2543
            'null',
2541
2544
            'show-ids',
 
2545
            'directory',
2542
2546
            ]
2543
2547
    @display_command
2544
2548
    def run(self, revision=None, verbose=False,
2545
2549
            recursive=False, from_root=False,
2546
2550
            unknown=False, versioned=False, ignored=False,
2547
 
            null=False, kind=None, show_ids=False, path=None):
 
2551
            null=False, kind=None, show_ids=False, path=None, directory=None):
2548
2552
 
2549
2553
        if kind and kind not in ('file', 'directory', 'symlink'):
2550
2554
            raise errors.BzrCommandError('invalid kind specified')
2562
2566
                raise errors.BzrCommandError('cannot specify both --from-root'
2563
2567
                                             ' and PATH')
2564
2568
            fs_path = path
2565
 
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
2566
 
            fs_path)
 
2569
        tree, branch, relpath = \
 
2570
            _open_directory_or_containing_tree_or_branch(fs_path, directory)
2567
2571
 
2568
2572
        # Calculate the prefix to use
2569
2573
        prefix = None
2638
2642
 
2639
2643
    hidden = True
2640
2644
    _see_also = ['ls']
 
2645
    takes_options = ['directory']
2641
2646
 
2642
2647
    @display_command
2643
 
    def run(self):
2644
 
        for f in WorkingTree.open_containing(u'.')[0].unknowns():
 
2648
    def run(self, directory=u'.'):
 
2649
        for f in WorkingTree.open_containing(directory)[0].unknowns():
2645
2650
            self.outf.write(osutils.quotefn(f) + '\n')
2646
2651
 
2647
2652
 
2712
2717
 
2713
2718
    _see_also = ['status', 'ignored', 'patterns']
2714
2719
    takes_args = ['name_pattern*']
2715
 
    takes_options = [
 
2720
    takes_options = ['directory',
2716
2721
        Option('default-rules',
2717
2722
               help='Display the default ignore rules that bzr uses.')
2718
2723
        ]
2719
2724
 
2720
 
    def run(self, name_pattern_list=None, default_rules=None):
 
2725
    def run(self, name_pattern_list=None, default_rules=None,
 
2726
            directory=u'.'):
2721
2727
        from bzrlib import ignores
2722
2728
        if default_rules is not None:
2723
2729
            # dump the default rules and exit
2734
2740
                (len(name_pattern) > 1 and name_pattern[1] == ':')):
2735
2741
                raise errors.BzrCommandError(
2736
2742
                    "NAME_PATTERN should not be an absolute path")
2737
 
        tree, relpath = WorkingTree.open_containing(u'.')
 
2743
        tree, relpath = WorkingTree.open_containing(directory)
2738
2744
        ignores.tree_ignores_add_patterns(tree, name_pattern_list)
2739
2745
        ignored = globbing.Globster(name_pattern_list)
2740
2746
        matches = []
2766
2772
 
2767
2773
    encoding_type = 'replace'
2768
2774
    _see_also = ['ignore', 'ls']
 
2775
    takes_options = ['directory']
2769
2776
 
2770
2777
    @display_command
2771
 
    def run(self):
2772
 
        tree = WorkingTree.open_containing(u'.')[0]
 
2778
    def run(self, directory=u'.'):
 
2779
        tree = WorkingTree.open_containing(directory)[0]
2773
2780
        tree.lock_read()
2774
2781
        self.add_cleanup(tree.unlock)
2775
2782
        for path, file_class, kind, file_id, entry in tree.list_files():
2788
2795
    """
2789
2796
    hidden = True
2790
2797
    takes_args = ['revno']
 
2798
    takes_options = ['directory']
2791
2799
 
2792
2800
    @display_command
2793
 
    def run(self, revno):
 
2801
    def run(self, revno, directory=u'.'):
2794
2802
        try:
2795
2803
            revno = int(revno)
2796
2804
        except ValueError:
2797
2805
            raise errors.BzrCommandError("not a valid revision-number: %r"
2798
2806
                                         % revno)
2799
 
        revid = WorkingTree.open_containing(u'.')[0].branch.get_rev_id(revno)
 
2807
        revid = WorkingTree.open_containing(directory)[0].branch.get_rev_id(revno)
2800
2808
        self.outf.write("%s\n" % revid)
2801
2809
 
2802
2810
 
2829
2837
      =================       =========================
2830
2838
    """
2831
2839
    takes_args = ['dest', 'branch_or_subdir?']
2832
 
    takes_options = [
 
2840
    takes_options = ['directory',
2833
2841
        Option('format',
2834
2842
               help="Type of file to export to.",
2835
2843
               type=unicode),
2844
2852
                    'revision in which it was changed.'),
2845
2853
        ]
2846
2854
    def run(self, dest, branch_or_subdir=None, revision=None, format=None,
2847
 
        root=None, filters=False, per_file_timestamps=False):
 
2855
        root=None, filters=False, per_file_timestamps=False, directory=u'.'):
2848
2856
        from bzrlib.export import export
2849
2857
 
2850
2858
        if branch_or_subdir is None:
2851
 
            tree = WorkingTree.open_containing(u'.')[0]
 
2859
            tree = WorkingTree.open_containing(directory)[0]
2852
2860
            b = tree.branch
2853
2861
            subdir = None
2854
2862
        else:
2873
2881
    """
2874
2882
 
2875
2883
    _see_also = ['ls']
2876
 
    takes_options = [
 
2884
    takes_options = ['directory',
2877
2885
        Option('name-from-revision', help='The path name in the old tree.'),
2878
2886
        Option('filters', help='Apply content filters to display the '
2879
2887
                'convenience form.'),
2884
2892
 
2885
2893
    @display_command
2886
2894
    def run(self, filename, revision=None, name_from_revision=False,
2887
 
            filters=False):
 
2895
            filters=False, directory=None):
2888
2896
        if revision is not None and len(revision) != 1:
2889
2897
            raise errors.BzrCommandError("bzr cat --revision takes exactly"
2890
2898
                                         " one revision specifier")
2891
2899
        tree, branch, relpath = \
2892
 
            bzrdir.BzrDir.open_containing_tree_or_branch(filename)
 
2900
            _open_directory_or_containing_tree_or_branch(filename, directory)
2893
2901
        branch.lock_read()
2894
2902
        self.add_cleanup(branch.unlock)
2895
2903
        return self._run(tree, branch, relpath, filename, revision,
3380
3388
 
3381
3389
    _see_also = ['info']
3382
3390
    takes_args = ['nickname?']
3383
 
    def run(self, nickname=None):
3384
 
        branch = Branch.open_containing(u'.')[0]
 
3391
    takes_options = ['directory']
 
3392
    def run(self, nickname=None, directory=u'.'):
 
3393
        branch = Branch.open_containing(directory)[0]
3385
3394
        if nickname is None:
3386
3395
            self.printme(branch)
3387
3396
        else:
3793
3802
                ' completely merged into the source, pull from the'
3794
3803
                ' source rather than merging.  When this happens,'
3795
3804
                ' you do not need to commit the result.'),
3796
 
        Option('directory',
 
3805
        custom_help('directory',
3797
3806
               help='Branch to merge into, '
3798
 
                    'rather than the one containing the working directory.',
3799
 
               short_name='d',
3800
 
               type=unicode,
3801
 
               ),
 
3807
                    'rather than the one containing the working directory.'),
3802
3808
        Option('preview', help='Instead of merging, show a diff of the'
3803
3809
               ' merge.'),
3804
3810
        Option('interactive', help='Select changes interactively.',
4578
4584
                     Option('long', help='Show commit date in annotations.'),
4579
4585
                     'revision',
4580
4586
                     'show-ids',
 
4587
                     'directory',
4581
4588
                     ]
4582
4589
    encoding_type = 'exact'
4583
4590
 
4584
4591
    @display_command
4585
4592
    def run(self, filename, all=False, long=False, revision=None,
4586
 
            show_ids=False):
 
4593
            show_ids=False, directory=None):
4587
4594
        from bzrlib.annotate import annotate_file, annotate_file_tree
4588
4595
        wt, branch, relpath = \
4589
 
            bzrdir.BzrDir.open_containing_tree_or_branch(filename)
 
4596
            _open_directory_or_containing_tree_or_branch(filename, directory)
4590
4597
        if wt is not None:
4591
4598
            wt.lock_read()
4592
4599
            self.add_cleanup(wt.unlock)
4619
4626
 
4620
4627
    hidden = True # is this right ?
4621
4628
    takes_args = ['revision_id*']
4622
 
    takes_options = ['revision']
 
4629
    takes_options = ['directory', 'revision']
4623
4630
 
4624
 
    def run(self, revision_id_list=None, revision=None):
 
4631
    def run(self, revision_id_list=None, revision=None, directory=u'.'):
4625
4632
        if revision_id_list is not None and revision is not None:
4626
4633
            raise errors.BzrCommandError('You can only supply one of revision_id or --revision')
4627
4634
        if revision_id_list is None and revision is None:
4628
4635
            raise errors.BzrCommandError('You must supply either --revision or a revision_id')
4629
 
        b = WorkingTree.open_containing(u'.')[0].branch
 
4636
        b = WorkingTree.open_containing(directory)[0].branch
4630
4637
        b.lock_write()
4631
4638
        self.add_cleanup(b.unlock)
4632
4639
        return self._run(b, revision_id_list, revision)
4693
4700
 
4694
4701
    _see_also = ['checkouts', 'unbind']
4695
4702
    takes_args = ['location?']
4696
 
    takes_options = []
 
4703
    takes_options = ['directory']
4697
4704
 
4698
 
    def run(self, location=None):
4699
 
        b, relpath = Branch.open_containing(u'.')
 
4705
    def run(self, location=None, directory=u'.'):
 
4706
        b, relpath = Branch.open_containing(directory)
4700
4707
        if location is None:
4701
4708
            try:
4702
4709
                location = b.get_old_bound_location()
4729
4736
 
4730
4737
    _see_also = ['checkouts', 'bind']
4731
4738
    takes_args = []
4732
 
    takes_options = []
 
4739
    takes_options = ['directory']
4733
4740
 
4734
 
    def run(self):
4735
 
        b, relpath = Branch.open_containing(u'.')
 
4741
    def run(self, directory=u'.'):
 
4742
        b, relpath = Branch.open_containing(directory)
4736
4743
        if not b.unbind():
4737
4744
            raise errors.BzrCommandError('Local branch is not bound')
4738
4745
 
4902
4909
                    'result in a dynamically allocated port.  The default port '
4903
4910
                    'depends on the protocol.',
4904
4911
               type=str),
4905
 
        Option('directory',
4906
 
               help='Serve contents of this directory.',
4907
 
               type=unicode),
 
4912
        custom_help('directory',
 
4913
               help='Serve contents of this directory.'),
4908
4914
        Option('allow-writes',
4909
4915
               help='By default the server is a readonly server.  Supplying '
4910
4916
                    '--allow-writes enables write access to the contents of '
5339
5345
        Option('delete',
5340
5346
            help='Delete this tag rather than placing it.',
5341
5347
            ),
5342
 
        Option('directory',
5343
 
            help='Branch in which to place the tag.',
5344
 
            short_name='d',
5345
 
            type=unicode,
5346
 
            ),
 
5348
        custom_help('directory',
 
5349
            help='Branch in which to place the tag.'),
5347
5350
        Option('force',
5348
5351
            help='Replace existing tags.',
5349
5352
            ),
5392
5395
 
5393
5396
    _see_also = ['tag']
5394
5397
    takes_options = [
5395
 
        Option('directory',
5396
 
            help='Branch whose tags should be displayed.',
5397
 
            short_name='d',
5398
 
            type=unicode,
5399
 
            ),
 
5398
        custom_help('directory',
 
5399
            help='Branch whose tags should be displayed.'),
5400
5400
        RegistryOption.from_kwargs('sort',
5401
5401
            'Sort tags by different criteria.', title='Sorting',
5402
5402
            alpha='Sort tags lexicographically (default).',
5966
5966
 
5967
5967
    To check what clean-tree will do, use --dry-run.
5968
5968
    """
5969
 
    takes_options = [Option('ignored', help='Delete all ignored files.'),
 
5969
    takes_options = ['directory',
 
5970
                     Option('ignored', help='Delete all ignored files.'),
5970
5971
                     Option('detritus', help='Delete conflict files, merge'
5971
5972
                            ' backups, and failed selftest dirs.'),
5972
5973
                     Option('unknown',
5975
5976
                            ' deleting them.'),
5976
5977
                     Option('force', help='Do not prompt before deleting.')]
5977
5978
    def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
5978
 
            force=False):
 
5979
            force=False, directory=u'.'):
5979
5980
        from bzrlib.clean_tree import clean_tree
5980
5981
        if not (unknown or ignored or detritus):
5981
5982
            unknown = True
5982
5983
        if dry_run:
5983
5984
            force = True
5984
 
        clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus,
5985
 
                   dry_run=dry_run, no_prompt=force)
 
5985
        clean_tree(directory, unknown=unknown, ignored=ignored,
 
5986
                   detritus=detritus, dry_run=dry_run, no_prompt=force)
5986
5987
 
5987
5988
 
5988
5989
class cmd_reference(Command):