/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: Robert Collins
  • Date: 2010-05-11 08:36:16 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100511083616-b8fjb19zomwupid0
Make all lock methods return Result objects, rather than lock_read returning self, as per John's review.

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'
1986
1987
    # level of effort but possibly much less IO.  (Or possibly not,
1987
1988
    # if the directories are very large...)
1988
1989
    _see_also = ['status', 'ls']
1989
 
    takes_options = ['directory', 'show-ids']
 
1990
    takes_options = ['show-ids']
1990
1991
 
1991
1992
    @display_command
1992
 
    def run(self, show_ids=False, directory=u'.'):
1993
 
        tree = WorkingTree.open_containing(directory)[0]
 
1993
    def run(self, show_ids=False):
 
1994
        tree = WorkingTree.open_containing(u'.')[0]
1994
1995
        self.add_cleanup(tree.lock_read().unlock)
1995
1996
        old = tree.basis_tree()
1996
1997
        self.add_cleanup(old.lock_read().unlock)
2009
2010
 
2010
2011
    hidden = True
2011
2012
    _see_also = ['status', 'ls']
2012
 
    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
            ]
2013
2018
 
2014
2019
    @display_command
2015
 
    def run(self, null=False, directory=u'.'):
2016
 
        tree = WorkingTree.open_containing(directory)[0]
 
2020
    def run(self, null=False):
 
2021
        tree = WorkingTree.open_containing(u'.')[0]
2017
2022
        td = tree.changes_from(tree.basis_tree())
2018
2023
        for path, id, kind, text_modified, meta_modified in td.modified:
2019
2024
            if null:
2028
2033
 
2029
2034
    hidden = True
2030
2035
    _see_also = ['status', 'ls']
2031
 
    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
            ]
2032
2041
 
2033
2042
    @display_command
2034
 
    def run(self, null=False, directory=u'.'):
2035
 
        wt = WorkingTree.open_containing(directory)[0]
 
2043
    def run(self, null=False):
 
2044
        wt = WorkingTree.open_containing(u'.')[0]
2036
2045
        self.add_cleanup(wt.lock_read().unlock)
2037
2046
        basis = wt.basis_tree()
2038
2047
        self.add_cleanup(basis.lock_read().unlock)
2044
2053
            if inv.is_root(file_id) and len(basis_inv) == 0:
2045
2054
                continue
2046
2055
            path = inv.id2path(file_id)
2047
 
            if not os.access(osutils.pathjoin(wt.basedir, path), os.F_OK):
 
2056
            if not os.access(osutils.abspath(path), os.F_OK):
2048
2057
                continue
2049
2058
            if null:
2050
2059
                self.outf.write(path + '\0')
2250
2259
                   help='Show just the specified revision.'
2251
2260
                   ' See also "help revisionspec".'),
2252
2261
            'log-format',
2253
 
            RegistryOption('authors',
2254
 
                'What names to list as authors - first, all or committer.',
2255
 
                title='Authors',
2256
 
                lazy_registry=('bzrlib.log', 'author_list_registry'),
2257
 
            ),
2258
2262
            Option('levels',
2259
2263
                   short_name='n',
2260
2264
                   help='Number of levels to display - 0 for all, 1 for flat.',
2295
2299
            limit=None,
2296
2300
            show_diff=False,
2297
2301
            include_merges=False,
2298
 
            authors=None,
2299
2302
            exclude_common_ancestry=False,
2300
2303
            ):
2301
2304
        from bzrlib.log import (
2379
2382
                        show_timezone=timezone,
2380
2383
                        delta_format=get_verbosity_level(),
2381
2384
                        levels=levels,
2382
 
                        show_advice=levels is None,
2383
 
                        author_list_handler=authors)
 
2385
                        show_advice=levels is None)
2384
2386
 
2385
2387
        # Choose the algorithm for doing the logging. It's annoying
2386
2388
        # having multiple code paths like this but necessary until
2503
2505
                   help='Recurse into subdirectories.'),
2504
2506
            Option('from-root',
2505
2507
                   help='Print paths relative to the root of the branch.'),
2506
 
            Option('unknown', short_name='u',
2507
 
                help='Print unknown files.'),
 
2508
            Option('unknown', help='Print unknown files.'),
2508
2509
            Option('versioned', help='Print versioned files.',
2509
2510
                   short_name='V'),
2510
 
            Option('ignored', short_name='i',
2511
 
                help='Print ignored files.'),
2512
 
            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',
2513
2516
                   help='List entries of a particular kind: file, directory, symlink.',
2514
2517
                   type=unicode),
2515
 
            'null',
2516
2518
            'show-ids',
2517
 
            'directory',
2518
2519
            ]
2519
2520
    @display_command
2520
2521
    def run(self, revision=None, verbose=False,
2521
2522
            recursive=False, from_root=False,
2522
2523
            unknown=False, versioned=False, ignored=False,
2523
 
            null=False, kind=None, show_ids=False, path=None, directory=None):
 
2524
            null=False, kind=None, show_ids=False, path=None):
2524
2525
 
2525
2526
        if kind and kind not in ('file', 'directory', 'symlink'):
2526
2527
            raise errors.BzrCommandError('invalid kind specified')
2538
2539
                raise errors.BzrCommandError('cannot specify both --from-root'
2539
2540
                                             ' and PATH')
2540
2541
            fs_path = path
2541
 
        tree, branch, relpath = \
2542
 
            _open_directory_or_containing_tree_or_branch(fs_path, directory)
 
2542
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
 
2543
            fs_path)
2543
2544
 
2544
2545
        # Calculate the prefix to use
2545
2546
        prefix = None
2613
2614
 
2614
2615
    hidden = True
2615
2616
    _see_also = ['ls']
2616
 
    takes_options = ['directory']
2617
2617
 
2618
2618
    @display_command
2619
 
    def run(self, directory=u'.'):
2620
 
        for f in WorkingTree.open_containing(directory)[0].unknowns():
 
2619
    def run(self):
 
2620
        for f in WorkingTree.open_containing(u'.')[0].unknowns():
2621
2621
            self.outf.write(osutils.quotefn(f) + '\n')
2622
2622
 
2623
2623
 
2688
2688
 
2689
2689
    _see_also = ['status', 'ignored', 'patterns']
2690
2690
    takes_args = ['name_pattern*']
2691
 
    takes_options = ['directory',
 
2691
    takes_options = [
2692
2692
        Option('default-rules',
2693
2693
               help='Display the default ignore rules that bzr uses.')
2694
2694
        ]
2695
2695
 
2696
 
    def run(self, name_pattern_list=None, default_rules=None,
2697
 
            directory=u'.'):
 
2696
    def run(self, name_pattern_list=None, default_rules=None):
2698
2697
        from bzrlib import ignores
2699
2698
        if default_rules is not None:
2700
2699
            # dump the default rules and exit
2711
2710
                (len(name_pattern) > 1 and name_pattern[1] == ':')):
2712
2711
                raise errors.BzrCommandError(
2713
2712
                    "NAME_PATTERN should not be an absolute path")
2714
 
        tree, relpath = WorkingTree.open_containing(directory)
 
2713
        tree, relpath = WorkingTree.open_containing(u'.')
2715
2714
        ignores.tree_ignores_add_patterns(tree, name_pattern_list)
2716
2715
        ignored = globbing.Globster(name_pattern_list)
2717
2716
        matches = []
2743
2742
 
2744
2743
    encoding_type = 'replace'
2745
2744
    _see_also = ['ignore', 'ls']
2746
 
    takes_options = ['directory']
2747
2745
 
2748
2746
    @display_command
2749
 
    def run(self, directory=u'.'):
2750
 
        tree = WorkingTree.open_containing(directory)[0]
 
2747
    def run(self):
 
2748
        tree = WorkingTree.open_containing(u'.')[0]
2751
2749
        self.add_cleanup(tree.lock_read().unlock)
2752
2750
        for path, file_class, kind, file_id, entry in tree.list_files():
2753
2751
            if file_class != 'I':
2765
2763
    """
2766
2764
    hidden = True
2767
2765
    takes_args = ['revno']
2768
 
    takes_options = ['directory']
2769
2766
 
2770
2767
    @display_command
2771
 
    def run(self, revno, directory=u'.'):
 
2768
    def run(self, revno):
2772
2769
        try:
2773
2770
            revno = int(revno)
2774
2771
        except ValueError:
2775
2772
            raise errors.BzrCommandError("not a valid revision-number: %r"
2776
2773
                                         % revno)
2777
 
        revid = WorkingTree.open_containing(directory)[0].branch.get_rev_id(revno)
 
2774
        revid = WorkingTree.open_containing(u'.')[0].branch.get_rev_id(revno)
2778
2775
        self.outf.write("%s\n" % revid)
2779
2776
 
2780
2777
 
2807
2804
      =================       =========================
2808
2805
    """
2809
2806
    takes_args = ['dest', 'branch_or_subdir?']
2810
 
    takes_options = ['directory',
 
2807
    takes_options = [
2811
2808
        Option('format',
2812
2809
               help="Type of file to export to.",
2813
2810
               type=unicode),
2822
2819
                    'revision in which it was changed.'),
2823
2820
        ]
2824
2821
    def run(self, dest, branch_or_subdir=None, revision=None, format=None,
2825
 
        root=None, filters=False, per_file_timestamps=False, directory=u'.'):
 
2822
        root=None, filters=False, per_file_timestamps=False):
2826
2823
        from bzrlib.export import export
2827
2824
 
2828
2825
        if branch_or_subdir is None:
2829
 
            tree = WorkingTree.open_containing(directory)[0]
 
2826
            tree = WorkingTree.open_containing(u'.')[0]
2830
2827
            b = tree.branch
2831
2828
            subdir = None
2832
2829
        else:
2851
2848
    """
2852
2849
 
2853
2850
    _see_also = ['ls']
2854
 
    takes_options = ['directory',
 
2851
    takes_options = [
2855
2852
        Option('name-from-revision', help='The path name in the old tree.'),
2856
2853
        Option('filters', help='Apply content filters to display the '
2857
2854
                'convenience form.'),
2862
2859
 
2863
2860
    @display_command
2864
2861
    def run(self, filename, revision=None, name_from_revision=False,
2865
 
            filters=False, directory=None):
 
2862
            filters=False):
2866
2863
        if revision is not None and len(revision) != 1:
2867
2864
            raise errors.BzrCommandError("bzr cat --revision takes exactly"
2868
2865
                                         " one revision specifier")
2869
2866
        tree, branch, relpath = \
2870
 
            _open_directory_or_containing_tree_or_branch(filename, directory)
 
2867
            bzrdir.BzrDir.open_containing_tree_or_branch(filename)
2871
2868
        self.add_cleanup(branch.lock_read().unlock)
2872
2869
        return self._run(tree, branch, relpath, filename, revision,
2873
2870
                         name_from_revision, filters)
3145
3142
        def get_message(commit_obj):
3146
3143
            """Callback to get commit message"""
3147
3144
            if file:
3148
 
                f = codecs.open(file, 'rt', osutils.get_user_encoding())
3149
 
                try:
3150
 
                    my_message = f.read()
3151
 
                finally:
3152
 
                    f.close()
 
3145
                my_message = codecs.open(
 
3146
                    file, 'rt', osutils.get_user_encoding()).read()
3153
3147
            elif message is not None:
3154
3148
                my_message = message
3155
3149
            else:
3359
3353
 
3360
3354
    _see_also = ['info']
3361
3355
    takes_args = ['nickname?']
3362
 
    takes_options = ['directory']
3363
 
    def run(self, nickname=None, directory=u'.'):
3364
 
        branch = Branch.open_containing(directory)[0]
 
3356
    def run(self, nickname=None):
 
3357
        branch = Branch.open_containing(u'.')[0]
3365
3358
        if nickname is None:
3366
3359
            self.printme(branch)
3367
3360
        else:
3592
3585
            self.additional_selftest_args['runner_class'] = SubUnitBzrRunner
3593
3586
            # On Windows, disable automatic conversion of '\n' to '\r\n' in
3594
3587
            # stdout, which would corrupt the subunit stream. 
3595
 
            # FIXME: This has been fixed in subunit trunk (>0.0.5) so the
3596
 
            # following code can be deleted when it's sufficiently deployed
3597
 
            # -- vila/mgz 20100514
3598
 
            if (sys.platform == "win32"
3599
 
                and getattr(sys.stdout, 'fileno', None) is not None):
 
3588
            if sys.platform == "win32" and sys.stdout.fileno() >= 0:
3600
3589
                import msvcrt
3601
3590
                msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
3602
3591
        if parallel:
3775
3764
                ' completely merged into the source, pull from the'
3776
3765
                ' source rather than merging.  When this happens,'
3777
3766
                ' you do not need to commit the result.'),
3778
 
        custom_help('directory',
 
3767
        Option('directory',
3779
3768
               help='Branch to merge into, '
3780
 
                    '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
               ),
3781
3773
        Option('preview', help='Instead of merging, show a diff of the'
3782
3774
               ' merge.'),
3783
3775
        Option('interactive', help='Select changes interactively.',
4550
4542
                     Option('long', help='Show commit date in annotations.'),
4551
4543
                     'revision',
4552
4544
                     'show-ids',
4553
 
                     'directory',
4554
4545
                     ]
4555
4546
    encoding_type = 'exact'
4556
4547
 
4557
4548
    @display_command
4558
4549
    def run(self, filename, all=False, long=False, revision=None,
4559
 
            show_ids=False, directory=None):
 
4550
            show_ids=False):
4560
4551
        from bzrlib.annotate import annotate_file, annotate_file_tree
4561
4552
        wt, branch, relpath = \
4562
 
            _open_directory_or_containing_tree_or_branch(filename, directory)
 
4553
            bzrdir.BzrDir.open_containing_tree_or_branch(filename)
4563
4554
        if wt is not None:
4564
4555
            self.add_cleanup(wt.lock_read().unlock)
4565
4556
        else:
4589
4580
 
4590
4581
    hidden = True # is this right ?
4591
4582
    takes_args = ['revision_id*']
4592
 
    takes_options = ['directory', 'revision']
 
4583
    takes_options = ['revision']
4593
4584
 
4594
 
    def run(self, revision_id_list=None, revision=None, directory=u'.'):
 
4585
    def run(self, revision_id_list=None, revision=None):
4595
4586
        if revision_id_list is not None and revision is not None:
4596
4587
            raise errors.BzrCommandError('You can only supply one of revision_id or --revision')
4597
4588
        if revision_id_list is None and revision is None:
4598
4589
            raise errors.BzrCommandError('You must supply either --revision or a revision_id')
4599
 
        b = WorkingTree.open_containing(directory)[0].branch
 
4590
        b = WorkingTree.open_containing(u'.')[0].branch
4600
4591
        self.add_cleanup(b.lock_write().unlock)
4601
4592
        return self._run(b, revision_id_list, revision)
4602
4593
 
4662
4653
 
4663
4654
    _see_also = ['checkouts', 'unbind']
4664
4655
    takes_args = ['location?']
4665
 
    takes_options = ['directory']
 
4656
    takes_options = []
4666
4657
 
4667
 
    def run(self, location=None, directory=u'.'):
4668
 
        b, relpath = Branch.open_containing(directory)
 
4658
    def run(self, location=None):
 
4659
        b, relpath = Branch.open_containing(u'.')
4669
4660
        if location is None:
4670
4661
            try:
4671
4662
                location = b.get_old_bound_location()
4698
4689
 
4699
4690
    _see_also = ['checkouts', 'bind']
4700
4691
    takes_args = []
4701
 
    takes_options = ['directory']
 
4692
    takes_options = []
4702
4693
 
4703
 
    def run(self, directory=u'.'):
4704
 
        b, relpath = Branch.open_containing(directory)
 
4694
    def run(self):
 
4695
        b, relpath = Branch.open_containing(u'.')
4705
4696
        if not b.unbind():
4706
4697
            raise errors.BzrCommandError('Local branch is not bound')
4707
4698
 
4869
4860
                    'result in a dynamically allocated port.  The default port '
4870
4861
                    'depends on the protocol.',
4871
4862
               type=str),
4872
 
        custom_help('directory',
4873
 
               help='Serve contents of this directory.'),
 
4863
        Option('directory',
 
4864
               help='Serve contents of this directory.',
 
4865
               type=unicode),
4874
4866
        Option('allow-writes',
4875
4867
               help='By default the server is a readonly server.  Supplying '
4876
4868
                    '--allow-writes enables write access to the contents of '
5128
5120
    given, in which case it is sent to a file.
5129
5121
 
5130
5122
    Mail is sent using your preferred mail program.  This should be transparent
5131
 
    on Windows (it uses MAPI).  On Unix, it requires the xdg-email utility.
 
5123
    on Windows (it uses MAPI).  On Linux, it requires the xdg-email utility.
5132
5124
    If the preferred client can't be found (or used), your editor will be used.
5133
5125
 
5134
5126
    To use a specific mail program, set the mail_client configuration option.
5305
5297
        Option('delete',
5306
5298
            help='Delete this tag rather than placing it.',
5307
5299
            ),
5308
 
        custom_help('directory',
5309
 
            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
            ),
5310
5305
        Option('force',
5311
5306
            help='Replace existing tags.',
5312
5307
            ),
5354
5349
 
5355
5350
    _see_also = ['tag']
5356
5351
    takes_options = [
5357
 
        custom_help('directory',
5358
 
            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
            ),
5359
5357
        RegistryOption.from_kwargs('sort',
5360
5358
            'Sort tags by different criteria.', title='Sorting',
5361
5359
            alpha='Sort tags lexicographically (default).',
5923
5921
 
5924
5922
    To check what clean-tree will do, use --dry-run.
5925
5923
    """
5926
 
    takes_options = ['directory',
5927
 
                     Option('ignored', help='Delete all ignored files.'),
 
5924
    takes_options = [Option('ignored', help='Delete all ignored files.'),
5928
5925
                     Option('detritus', help='Delete conflict files, merge'
5929
5926
                            ' backups, and failed selftest dirs.'),
5930
5927
                     Option('unknown',
5933
5930
                            ' deleting them.'),
5934
5931
                     Option('force', help='Do not prompt before deleting.')]
5935
5932
    def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
5936
 
            force=False, directory=u'.'):
 
5933
            force=False):
5937
5934
        from bzrlib.clean_tree import clean_tree
5938
5935
        if not (unknown or ignored or detritus):
5939
5936
            unknown = True
5940
5937
        if dry_run:
5941
5938
            force = True
5942
 
        clean_tree(directory, unknown=unknown, ignored=ignored,
5943
 
                   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)
5944
5941
 
5945
5942
 
5946
5943
class cmd_reference(Command):