~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Robert Collins
  • Date: 2010-05-11 08:44:59 UTC
  • mfrom: (5221 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100511084459-pb0uinna9zs3wu59
Merge trunk - resolve conflicts.

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:
552
560
    takes_args = ['revision_info*']
553
561
    takes_options = [
554
562
        'revision',
555
 
        Option('directory',
 
563
        custom_help('directory',
556
564
            help='Branch to examine, '
557
 
                 'rather than the one containing the working directory.',
558
 
            short_name='d',
559
 
            type=unicode,
560
 
            ),
 
565
                 'rather than the one containing the working directory.'),
561
566
        Option('tree', help='Show revno of working tree'),
562
567
        ]
563
568
 
951
956
    takes_options = ['remember', 'overwrite', 'revision',
952
957
        custom_help('verbose',
953
958
            help='Show logs of pulled revisions.'),
954
 
        Option('directory',
 
959
        custom_help('directory',
955
960
            help='Branch to pull into, '
956
 
                 'rather than the one containing the working directory.',
957
 
            short_name='d',
958
 
            type=unicode,
959
 
            ),
 
961
                 'rather than the one containing the working directory.'),
960
962
        Option('local',
961
963
            help="Perform a local pull in a bound "
962
964
                 "branch.  Local pulls are not applied to "
1076
1078
        Option('create-prefix',
1077
1079
               help='Create the path leading up to the branch '
1078
1080
                    'if it does not already exist.'),
1079
 
        Option('directory',
 
1081
        custom_help('directory',
1080
1082
            help='Branch to push from, '
1081
 
                 'rather than the one containing the working directory.',
1082
 
            short_name='d',
1083
 
            type=unicode,
1084
 
            ),
 
1083
                 'rather than the one containing the working directory.'),
1085
1084
        Option('use-existing-dir',
1086
1085
               help='By default push will fail if the target'
1087
1086
                    ' directory exists, but does not already'
1337
1336
            except errors.NoWorkingTree:
1338
1337
                source.bzrdir.create_workingtree(revision_id)
1339
1338
                return
 
1339
 
 
1340
        if not lightweight:
 
1341
            message = ('Copying history to "%s". '
 
1342
                'To checkout without local history use --lightweight.' % to_location)
 
1343
            ui.ui_factory.show_message(message)
1340
1344
        source.create_checkout(to_location, revision_id, lightweight,
1341
1345
                               accelerator_tree, hardlink)
1342
1346
 
1987
1991
    # level of effort but possibly much less IO.  (Or possibly not,
1988
1992
    # if the directories are very large...)
1989
1993
    _see_also = ['status', 'ls']
1990
 
    takes_options = ['show-ids']
 
1994
    takes_options = ['directory', 'show-ids']
1991
1995
 
1992
1996
    @display_command
1993
 
    def run(self, show_ids=False):
1994
 
        tree = WorkingTree.open_containing(u'.')[0]
 
1997
    def run(self, show_ids=False, directory=u'.'):
 
1998
        tree = WorkingTree.open_containing(directory)[0]
1995
1999
        self.add_cleanup(tree.lock_read().unlock)
1996
2000
        old = tree.basis_tree()
1997
2001
        self.add_cleanup(old.lock_read().unlock)
2010
2014
 
2011
2015
    hidden = True
2012
2016
    _see_also = ['status', 'ls']
2013
 
    takes_options = [
2014
 
            Option('null',
2015
 
                   help='Write an ascii NUL (\\0) separator '
2016
 
                   'between files rather than a newline.')
2017
 
            ]
 
2017
    takes_options = ['directory', 'null']
2018
2018
 
2019
2019
    @display_command
2020
 
    def run(self, null=False):
2021
 
        tree = WorkingTree.open_containing(u'.')[0]
 
2020
    def run(self, null=False, directory=u'.'):
 
2021
        tree = WorkingTree.open_containing(directory)[0]
2022
2022
        td = tree.changes_from(tree.basis_tree())
2023
2023
        for path, id, kind, text_modified, meta_modified in td.modified:
2024
2024
            if null:
2033
2033
 
2034
2034
    hidden = True
2035
2035
    _see_also = ['status', 'ls']
2036
 
    takes_options = [
2037
 
            Option('null',
2038
 
                   help='Write an ascii NUL (\\0) separator '
2039
 
                   'between files rather than a newline.')
2040
 
            ]
 
2036
    takes_options = ['directory', 'null']
2041
2037
 
2042
2038
    @display_command
2043
 
    def run(self, null=False):
2044
 
        wt = WorkingTree.open_containing(u'.')[0]
 
2039
    def run(self, null=False, directory=u'.'):
 
2040
        wt = WorkingTree.open_containing(directory)[0]
2045
2041
        self.add_cleanup(wt.lock_read().unlock)
2046
2042
        basis = wt.basis_tree()
2047
2043
        self.add_cleanup(basis.lock_read().unlock)
2053
2049
            if inv.is_root(file_id) and len(basis_inv) == 0:
2054
2050
                continue
2055
2051
            path = inv.id2path(file_id)
2056
 
            if not os.access(osutils.abspath(path), os.F_OK):
 
2052
            if not os.access(osutils.pathjoin(wt.basedir, path), os.F_OK):
2057
2053
                continue
2058
2054
            if null:
2059
2055
                self.outf.write(path + '\0')
2259
2255
                   help='Show just the specified revision.'
2260
2256
                   ' See also "help revisionspec".'),
2261
2257
            'log-format',
 
2258
            RegistryOption('authors',
 
2259
                'What names to list as authors - first, all or committer.',
 
2260
                title='Authors',
 
2261
                lazy_registry=('bzrlib.log', 'author_list_registry'),
 
2262
            ),
2262
2263
            Option('levels',
2263
2264
                   short_name='n',
2264
2265
                   help='Number of levels to display - 0 for all, 1 for flat.',
2299
2300
            limit=None,
2300
2301
            show_diff=False,
2301
2302
            include_merges=False,
 
2303
            authors=None,
2302
2304
            exclude_common_ancestry=False,
2303
2305
            ):
2304
2306
        from bzrlib.log import (
2382
2384
                        show_timezone=timezone,
2383
2385
                        delta_format=get_verbosity_level(),
2384
2386
                        levels=levels,
2385
 
                        show_advice=levels is None)
 
2387
                        show_advice=levels is None,
 
2388
                        author_list_handler=authors)
2386
2389
 
2387
2390
        # Choose the algorithm for doing the logging. It's annoying
2388
2391
        # having multiple code paths like this but necessary until
2505
2508
                   help='Recurse into subdirectories.'),
2506
2509
            Option('from-root',
2507
2510
                   help='Print paths relative to the root of the branch.'),
2508
 
            Option('unknown', help='Print unknown files.'),
 
2511
            Option('unknown', short_name='u',
 
2512
                help='Print unknown files.'),
2509
2513
            Option('versioned', help='Print versioned files.',
2510
2514
                   short_name='V'),
2511
 
            Option('ignored', help='Print ignored files.'),
2512
 
            Option('null',
2513
 
                   help='Write an ascii NUL (\\0) separator '
2514
 
                   'between files rather than a newline.'),
2515
 
            Option('kind',
 
2515
            Option('ignored', short_name='i',
 
2516
                help='Print ignored files.'),
 
2517
            Option('kind', short_name='k',
2516
2518
                   help='List entries of a particular kind: file, directory, symlink.',
2517
2519
                   type=unicode),
 
2520
            'null',
2518
2521
            'show-ids',
 
2522
            'directory',
2519
2523
            ]
2520
2524
    @display_command
2521
2525
    def run(self, revision=None, verbose=False,
2522
2526
            recursive=False, from_root=False,
2523
2527
            unknown=False, versioned=False, ignored=False,
2524
 
            null=False, kind=None, show_ids=False, path=None):
 
2528
            null=False, kind=None, show_ids=False, path=None, directory=None):
2525
2529
 
2526
2530
        if kind and kind not in ('file', 'directory', 'symlink'):
2527
2531
            raise errors.BzrCommandError('invalid kind specified')
2539
2543
                raise errors.BzrCommandError('cannot specify both --from-root'
2540
2544
                                             ' and PATH')
2541
2545
            fs_path = path
2542
 
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
2543
 
            fs_path)
 
2546
        tree, branch, relpath = \
 
2547
            _open_directory_or_containing_tree_or_branch(fs_path, directory)
2544
2548
 
2545
2549
        # Calculate the prefix to use
2546
2550
        prefix = None
2614
2618
 
2615
2619
    hidden = True
2616
2620
    _see_also = ['ls']
 
2621
    takes_options = ['directory']
2617
2622
 
2618
2623
    @display_command
2619
 
    def run(self):
2620
 
        for f in WorkingTree.open_containing(u'.')[0].unknowns():
 
2624
    def run(self, directory=u'.'):
 
2625
        for f in WorkingTree.open_containing(directory)[0].unknowns():
2621
2626
            self.outf.write(osutils.quotefn(f) + '\n')
2622
2627
 
2623
2628
 
2688
2693
 
2689
2694
    _see_also = ['status', 'ignored', 'patterns']
2690
2695
    takes_args = ['name_pattern*']
2691
 
    takes_options = [
 
2696
    takes_options = ['directory',
2692
2697
        Option('default-rules',
2693
2698
               help='Display the default ignore rules that bzr uses.')
2694
2699
        ]
2695
2700
 
2696
 
    def run(self, name_pattern_list=None, default_rules=None):
 
2701
    def run(self, name_pattern_list=None, default_rules=None,
 
2702
            directory=u'.'):
2697
2703
        from bzrlib import ignores
2698
2704
        if default_rules is not None:
2699
2705
            # dump the default rules and exit
2710
2716
                (len(name_pattern) > 1 and name_pattern[1] == ':')):
2711
2717
                raise errors.BzrCommandError(
2712
2718
                    "NAME_PATTERN should not be an absolute path")
2713
 
        tree, relpath = WorkingTree.open_containing(u'.')
 
2719
        tree, relpath = WorkingTree.open_containing(directory)
2714
2720
        ignores.tree_ignores_add_patterns(tree, name_pattern_list)
2715
2721
        ignored = globbing.Globster(name_pattern_list)
2716
2722
        matches = []
2742
2748
 
2743
2749
    encoding_type = 'replace'
2744
2750
    _see_also = ['ignore', 'ls']
 
2751
    takes_options = ['directory']
2745
2752
 
2746
2753
    @display_command
2747
 
    def run(self):
2748
 
        tree = WorkingTree.open_containing(u'.')[0]
 
2754
    def run(self, directory=u'.'):
 
2755
        tree = WorkingTree.open_containing(directory)[0]
2749
2756
        self.add_cleanup(tree.lock_read().unlock)
2750
2757
        for path, file_class, kind, file_id, entry in tree.list_files():
2751
2758
            if file_class != 'I':
2763
2770
    """
2764
2771
    hidden = True
2765
2772
    takes_args = ['revno']
 
2773
    takes_options = ['directory']
2766
2774
 
2767
2775
    @display_command
2768
 
    def run(self, revno):
 
2776
    def run(self, revno, directory=u'.'):
2769
2777
        try:
2770
2778
            revno = int(revno)
2771
2779
        except ValueError:
2772
2780
            raise errors.BzrCommandError("not a valid revision-number: %r"
2773
2781
                                         % revno)
2774
 
        revid = WorkingTree.open_containing(u'.')[0].branch.get_rev_id(revno)
 
2782
        revid = WorkingTree.open_containing(directory)[0].branch.get_rev_id(revno)
2775
2783
        self.outf.write("%s\n" % revid)
2776
2784
 
2777
2785
 
2804
2812
      =================       =========================
2805
2813
    """
2806
2814
    takes_args = ['dest', 'branch_or_subdir?']
2807
 
    takes_options = [
 
2815
    takes_options = ['directory',
2808
2816
        Option('format',
2809
2817
               help="Type of file to export to.",
2810
2818
               type=unicode),
2819
2827
                    'revision in which it was changed.'),
2820
2828
        ]
2821
2829
    def run(self, dest, branch_or_subdir=None, revision=None, format=None,
2822
 
        root=None, filters=False, per_file_timestamps=False):
 
2830
        root=None, filters=False, per_file_timestamps=False, directory=u'.'):
2823
2831
        from bzrlib.export import export
2824
2832
 
2825
2833
        if branch_or_subdir is None:
2826
 
            tree = WorkingTree.open_containing(u'.')[0]
 
2834
            tree = WorkingTree.open_containing(directory)[0]
2827
2835
            b = tree.branch
2828
2836
            subdir = None
2829
2837
        else:
2848
2856
    """
2849
2857
 
2850
2858
    _see_also = ['ls']
2851
 
    takes_options = [
 
2859
    takes_options = ['directory',
2852
2860
        Option('name-from-revision', help='The path name in the old tree.'),
2853
2861
        Option('filters', help='Apply content filters to display the '
2854
2862
                'convenience form.'),
2859
2867
 
2860
2868
    @display_command
2861
2869
    def run(self, filename, revision=None, name_from_revision=False,
2862
 
            filters=False):
 
2870
            filters=False, directory=None):
2863
2871
        if revision is not None and len(revision) != 1:
2864
2872
            raise errors.BzrCommandError("bzr cat --revision takes exactly"
2865
2873
                                         " one revision specifier")
2866
2874
        tree, branch, relpath = \
2867
 
            bzrdir.BzrDir.open_containing_tree_or_branch(filename)
 
2875
            _open_directory_or_containing_tree_or_branch(filename, directory)
2868
2876
        self.add_cleanup(branch.lock_read().unlock)
2869
2877
        return self._run(tree, branch, relpath, filename, revision,
2870
2878
                         name_from_revision, filters)
3353
3361
 
3354
3362
    _see_also = ['info']
3355
3363
    takes_args = ['nickname?']
3356
 
    def run(self, nickname=None):
3357
 
        branch = Branch.open_containing(u'.')[0]
 
3364
    takes_options = ['directory']
 
3365
    def run(self, nickname=None, directory=u'.'):
 
3366
        branch = Branch.open_containing(directory)[0]
3358
3367
        if nickname is None:
3359
3368
            self.printme(branch)
3360
3369
        else:
3764
3773
                ' completely merged into the source, pull from the'
3765
3774
                ' source rather than merging.  When this happens,'
3766
3775
                ' you do not need to commit the result.'),
3767
 
        Option('directory',
 
3776
        custom_help('directory',
3768
3777
               help='Branch to merge into, '
3769
 
                    'rather than the one containing the working directory.',
3770
 
               short_name='d',
3771
 
               type=unicode,
3772
 
               ),
 
3778
                    'rather than the one containing the working directory.'),
3773
3779
        Option('preview', help='Instead of merging, show a diff of the'
3774
3780
               ' merge.'),
3775
3781
        Option('interactive', help='Select changes interactively.',
4542
4548
                     Option('long', help='Show commit date in annotations.'),
4543
4549
                     'revision',
4544
4550
                     'show-ids',
 
4551
                     'directory',
4545
4552
                     ]
4546
4553
    encoding_type = 'exact'
4547
4554
 
4548
4555
    @display_command
4549
4556
    def run(self, filename, all=False, long=False, revision=None,
4550
 
            show_ids=False):
 
4557
            show_ids=False, directory=None):
4551
4558
        from bzrlib.annotate import annotate_file, annotate_file_tree
4552
4559
        wt, branch, relpath = \
4553
 
            bzrdir.BzrDir.open_containing_tree_or_branch(filename)
 
4560
            _open_directory_or_containing_tree_or_branch(filename, directory)
4554
4561
        if wt is not None:
4555
4562
            self.add_cleanup(wt.lock_read().unlock)
4556
4563
        else:
4580
4587
 
4581
4588
    hidden = True # is this right ?
4582
4589
    takes_args = ['revision_id*']
4583
 
    takes_options = ['revision']
 
4590
    takes_options = ['directory', 'revision']
4584
4591
 
4585
 
    def run(self, revision_id_list=None, revision=None):
 
4592
    def run(self, revision_id_list=None, revision=None, directory=u'.'):
4586
4593
        if revision_id_list is not None and revision is not None:
4587
4594
            raise errors.BzrCommandError('You can only supply one of revision_id or --revision')
4588
4595
        if revision_id_list is None and revision is None:
4589
4596
            raise errors.BzrCommandError('You must supply either --revision or a revision_id')
4590
 
        b = WorkingTree.open_containing(u'.')[0].branch
 
4597
        b = WorkingTree.open_containing(directory)[0].branch
4591
4598
        self.add_cleanup(b.lock_write().unlock)
4592
4599
        return self._run(b, revision_id_list, revision)
4593
4600
 
4653
4660
 
4654
4661
    _see_also = ['checkouts', 'unbind']
4655
4662
    takes_args = ['location?']
4656
 
    takes_options = []
 
4663
    takes_options = ['directory']
4657
4664
 
4658
 
    def run(self, location=None):
4659
 
        b, relpath = Branch.open_containing(u'.')
 
4665
    def run(self, location=None, directory=u'.'):
 
4666
        b, relpath = Branch.open_containing(directory)
4660
4667
        if location is None:
4661
4668
            try:
4662
4669
                location = b.get_old_bound_location()
4689
4696
 
4690
4697
    _see_also = ['checkouts', 'bind']
4691
4698
    takes_args = []
4692
 
    takes_options = []
 
4699
    takes_options = ['directory']
4693
4700
 
4694
 
    def run(self):
4695
 
        b, relpath = Branch.open_containing(u'.')
 
4701
    def run(self, directory=u'.'):
 
4702
        b, relpath = Branch.open_containing(directory)
4696
4703
        if not b.unbind():
4697
4704
            raise errors.BzrCommandError('Local branch is not bound')
4698
4705
 
4860
4867
                    'result in a dynamically allocated port.  The default port '
4861
4868
                    'depends on the protocol.',
4862
4869
               type=str),
4863
 
        Option('directory',
4864
 
               help='Serve contents of this directory.',
4865
 
               type=unicode),
 
4870
        custom_help('directory',
 
4871
               help='Serve contents of this directory.'),
4866
4872
        Option('allow-writes',
4867
4873
               help='By default the server is a readonly server.  Supplying '
4868
4874
                    '--allow-writes enables write access to the contents of '
5297
5303
        Option('delete',
5298
5304
            help='Delete this tag rather than placing it.',
5299
5305
            ),
5300
 
        Option('directory',
5301
 
            help='Branch in which to place the tag.',
5302
 
            short_name='d',
5303
 
            type=unicode,
5304
 
            ),
 
5306
        custom_help('directory',
 
5307
            help='Branch in which to place the tag.'),
5305
5308
        Option('force',
5306
5309
            help='Replace existing tags.',
5307
5310
            ),
5349
5352
 
5350
5353
    _see_also = ['tag']
5351
5354
    takes_options = [
5352
 
        Option('directory',
5353
 
            help='Branch whose tags should be displayed.',
5354
 
            short_name='d',
5355
 
            type=unicode,
5356
 
            ),
 
5355
        custom_help('directory',
 
5356
            help='Branch whose tags should be displayed.'),
5357
5357
        RegistryOption.from_kwargs('sort',
5358
5358
            'Sort tags by different criteria.', title='Sorting',
5359
5359
            alpha='Sort tags lexicographically (default).',
5921
5921
 
5922
5922
    To check what clean-tree will do, use --dry-run.
5923
5923
    """
5924
 
    takes_options = [Option('ignored', help='Delete all ignored files.'),
 
5924
    takes_options = ['directory',
 
5925
                     Option('ignored', help='Delete all ignored files.'),
5925
5926
                     Option('detritus', help='Delete conflict files, merge'
5926
5927
                            ' backups, and failed selftest dirs.'),
5927
5928
                     Option('unknown',
5930
5931
                            ' deleting them.'),
5931
5932
                     Option('force', help='Do not prompt before deleting.')]
5932
5933
    def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
5933
 
            force=False):
 
5934
            force=False, directory=u'.'):
5934
5935
        from bzrlib.clean_tree import clean_tree
5935
5936
        if not (unknown or ignored or detritus):
5936
5937
            unknown = True
5937
5938
        if dry_run:
5938
5939
            force = True
5939
 
        clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus,
5940
 
                   dry_run=dry_run, no_prompt=force)
 
5940
        clean_tree(directory, unknown=unknown, ignored=ignored,
 
5941
                   detritus=detritus, dry_run=dry_run, no_prompt=force)
5941
5942
 
5942
5943
 
5943
5944
class cmd_reference(Command):