~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Robert Collins
  • Date: 2010-05-06 23:54:05 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506235405-wii4elupfhzl3jvy
Add __str__ to the new helper classes.

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