/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-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

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:
562
554
    takes_args = ['revision_info*']
563
555
    takes_options = [
564
556
        'revision',
565
 
        custom_help('directory',
 
557
        Option('directory',
566
558
            help='Branch to examine, '
567
 
                 'rather than the one containing the working directory.'),
 
559
                 'rather than the one containing the working directory.',
 
560
            short_name='d',
 
561
            type=unicode,
 
562
            ),
568
563
        Option('tree', help='Show revno of working tree'),
569
564
        ]
570
565
 
965
960
    takes_options = ['remember', 'overwrite', 'revision',
966
961
        custom_help('verbose',
967
962
            help='Show logs of pulled revisions.'),
968
 
        custom_help('directory',
 
963
        Option('directory',
969
964
            help='Branch to pull into, '
970
 
                 'rather than the one containing the working directory.'),
 
965
                 'rather than the one containing the working directory.',
 
966
            short_name='d',
 
967
            type=unicode,
 
968
            ),
971
969
        Option('local',
972
970
            help="Perform a local pull in a bound "
973
971
                 "branch.  Local pulls are not applied to "
1090
1088
        Option('create-prefix',
1091
1089
               help='Create the path leading up to the branch '
1092
1090
                    'if it does not already exist.'),
1093
 
        custom_help('directory',
 
1091
        Option('directory',
1094
1092
            help='Branch to push from, '
1095
 
                 'rather than the one containing the working directory.'),
 
1093
                 'rather than the one containing the working directory.',
 
1094
            short_name='d',
 
1095
            type=unicode,
 
1096
            ),
1096
1097
        Option('use-existing-dir',
1097
1098
               help='By default push will fail if the target'
1098
1099
                    ' directory exists, but does not already'
2002
2003
    # level of effort but possibly much less IO.  (Or possibly not,
2003
2004
    # if the directories are very large...)
2004
2005
    _see_also = ['status', 'ls']
2005
 
    takes_options = ['directory', 'show-ids']
 
2006
    takes_options = ['show-ids']
2006
2007
 
2007
2008
    @display_command
2008
 
    def run(self, show_ids=False, directory=u'.'):
2009
 
        tree = WorkingTree.open_containing(directory)[0]
 
2009
    def run(self, show_ids=False):
 
2010
        tree = WorkingTree.open_containing(u'.')[0]
2010
2011
        tree.lock_read()
2011
2012
        self.add_cleanup(tree.unlock)
2012
2013
        old = tree.basis_tree()
2027
2028
 
2028
2029
    hidden = True
2029
2030
    _see_also = ['status', 'ls']
2030
 
    takes_options = ['directory', 'null']
 
2031
    takes_options = [
 
2032
            Option('null',
 
2033
                   help='Write an ascii NUL (\\0) separator '
 
2034
                   'between files rather than a newline.')
 
2035
            ]
2031
2036
 
2032
2037
    @display_command
2033
 
    def run(self, null=False, directory=u'.'):
2034
 
        tree = WorkingTree.open_containing(directory)[0]
 
2038
    def run(self, null=False):
 
2039
        tree = WorkingTree.open_containing(u'.')[0]
2035
2040
        td = tree.changes_from(tree.basis_tree())
2036
2041
        for path, id, kind, text_modified, meta_modified in td.modified:
2037
2042
            if null:
2046
2051
 
2047
2052
    hidden = True
2048
2053
    _see_also = ['status', 'ls']
2049
 
    takes_options = ['directory', 'null']
 
2054
    takes_options = [
 
2055
            Option('null',
 
2056
                   help='Write an ascii NUL (\\0) separator '
 
2057
                   'between files rather than a newline.')
 
2058
            ]
2050
2059
 
2051
2060
    @display_command
2052
 
    def run(self, null=False, directory=u'.'):
2053
 
        wt = WorkingTree.open_containing(directory)[0]
 
2061
    def run(self, null=False):
 
2062
        wt = WorkingTree.open_containing(u'.')[0]
2054
2063
        wt.lock_read()
2055
2064
        self.add_cleanup(wt.unlock)
2056
2065
        basis = wt.basis_tree()
2064
2073
            if inv.is_root(file_id) and len(basis_inv) == 0:
2065
2074
                continue
2066
2075
            path = inv.id2path(file_id)
2067
 
            if not os.access(osutils.pathjoin(wt.basedir, path), os.F_OK):
 
2076
            if not os.access(osutils.abspath(path), os.F_OK):
2068
2077
                continue
2069
2078
            if null:
2070
2079
                self.outf.write(path + '\0')
2519
2528
                   help='Recurse into subdirectories.'),
2520
2529
            Option('from-root',
2521
2530
                   help='Print paths relative to the root of the branch.'),
2522
 
            Option('unknown', short_name='u',
2523
 
                help='Print unknown files.'),
 
2531
            Option('unknown', help='Print unknown files.'),
2524
2532
            Option('versioned', help='Print versioned files.',
2525
2533
                   short_name='V'),
2526
 
            Option('ignored', short_name='i',
2527
 
                help='Print ignored files.'),
2528
 
            Option('kind', short_name='k',
 
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',
2529
2539
                   help='List entries of a particular kind: file, directory, symlink.',
2530
2540
                   type=unicode),
2531
 
            'null',
2532
2541
            'show-ids',
2533
 
            'directory',
2534
2542
            ]
2535
2543
    @display_command
2536
2544
    def run(self, revision=None, verbose=False,
2537
2545
            recursive=False, from_root=False,
2538
2546
            unknown=False, versioned=False, ignored=False,
2539
 
            null=False, kind=None, show_ids=False, path=None, directory=None):
 
2547
            null=False, kind=None, show_ids=False, path=None):
2540
2548
 
2541
2549
        if kind and kind not in ('file', 'directory', 'symlink'):
2542
2550
            raise errors.BzrCommandError('invalid kind specified')
2554
2562
                raise errors.BzrCommandError('cannot specify both --from-root'
2555
2563
                                             ' and PATH')
2556
2564
            fs_path = path
2557
 
        tree, branch, relpath = \
2558
 
            _open_directory_or_containing_tree_or_branch(fs_path, directory)
 
2565
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
 
2566
            fs_path)
2559
2567
 
2560
2568
        # Calculate the prefix to use
2561
2569
        prefix = None
2630
2638
 
2631
2639
    hidden = True
2632
2640
    _see_also = ['ls']
2633
 
    takes_options = ['directory']
2634
2641
 
2635
2642
    @display_command
2636
 
    def run(self, directory=u'.'):
2637
 
        for f in WorkingTree.open_containing(directory)[0].unknowns():
 
2643
    def run(self):
 
2644
        for f in WorkingTree.open_containing(u'.')[0].unknowns():
2638
2645
            self.outf.write(osutils.quotefn(f) + '\n')
2639
2646
 
2640
2647
 
2705
2712
 
2706
2713
    _see_also = ['status', 'ignored', 'patterns']
2707
2714
    takes_args = ['name_pattern*']
2708
 
    takes_options = ['directory',
 
2715
    takes_options = [
2709
2716
        Option('default-rules',
2710
2717
               help='Display the default ignore rules that bzr uses.')
2711
2718
        ]
2712
2719
 
2713
 
    def run(self, name_pattern_list=None, default_rules=None,
2714
 
            directory=u'.'):
 
2720
    def run(self, name_pattern_list=None, default_rules=None):
2715
2721
        from bzrlib import ignores
2716
2722
        if default_rules is not None:
2717
2723
            # dump the default rules and exit
2728
2734
                (len(name_pattern) > 1 and name_pattern[1] == ':')):
2729
2735
                raise errors.BzrCommandError(
2730
2736
                    "NAME_PATTERN should not be an absolute path")
2731
 
        tree, relpath = WorkingTree.open_containing(directory)
 
2737
        tree, relpath = WorkingTree.open_containing(u'.')
2732
2738
        ignores.tree_ignores_add_patterns(tree, name_pattern_list)
2733
2739
        ignored = globbing.Globster(name_pattern_list)
2734
2740
        matches = []
2760
2766
 
2761
2767
    encoding_type = 'replace'
2762
2768
    _see_also = ['ignore', 'ls']
2763
 
    takes_options = ['directory']
2764
2769
 
2765
2770
    @display_command
2766
 
    def run(self, directory=u'.'):
2767
 
        tree = WorkingTree.open_containing(directory)[0]
 
2771
    def run(self):
 
2772
        tree = WorkingTree.open_containing(u'.')[0]
2768
2773
        tree.lock_read()
2769
2774
        self.add_cleanup(tree.unlock)
2770
2775
        for path, file_class, kind, file_id, entry in tree.list_files():
2783
2788
    """
2784
2789
    hidden = True
2785
2790
    takes_args = ['revno']
2786
 
    takes_options = ['directory']
2787
2791
 
2788
2792
    @display_command
2789
 
    def run(self, revno, directory=u'.'):
 
2793
    def run(self, revno):
2790
2794
        try:
2791
2795
            revno = int(revno)
2792
2796
        except ValueError:
2793
2797
            raise errors.BzrCommandError("not a valid revision-number: %r"
2794
2798
                                         % revno)
2795
 
        revid = WorkingTree.open_containing(directory)[0].branch.get_rev_id(revno)
 
2799
        revid = WorkingTree.open_containing(u'.')[0].branch.get_rev_id(revno)
2796
2800
        self.outf.write("%s\n" % revid)
2797
2801
 
2798
2802
 
2825
2829
      =================       =========================
2826
2830
    """
2827
2831
    takes_args = ['dest', 'branch_or_subdir?']
2828
 
    takes_options = ['directory',
 
2832
    takes_options = [
2829
2833
        Option('format',
2830
2834
               help="Type of file to export to.",
2831
2835
               type=unicode),
2840
2844
                    'revision in which it was changed.'),
2841
2845
        ]
2842
2846
    def run(self, dest, branch_or_subdir=None, revision=None, format=None,
2843
 
        root=None, filters=False, per_file_timestamps=False, directory=u'.'):
 
2847
        root=None, filters=False, per_file_timestamps=False):
2844
2848
        from bzrlib.export import export
2845
2849
 
2846
2850
        if branch_or_subdir is None:
2847
 
            tree = WorkingTree.open_containing(directory)[0]
 
2851
            tree = WorkingTree.open_containing(u'.')[0]
2848
2852
            b = tree.branch
2849
2853
            subdir = None
2850
2854
        else:
2869
2873
    """
2870
2874
 
2871
2875
    _see_also = ['ls']
2872
 
    takes_options = ['directory',
 
2876
    takes_options = [
2873
2877
        Option('name-from-revision', help='The path name in the old tree.'),
2874
2878
        Option('filters', help='Apply content filters to display the '
2875
2879
                'convenience form.'),
2880
2884
 
2881
2885
    @display_command
2882
2886
    def run(self, filename, revision=None, name_from_revision=False,
2883
 
            filters=False, directory=None):
 
2887
            filters=False):
2884
2888
        if revision is not None and len(revision) != 1:
2885
2889
            raise errors.BzrCommandError("bzr cat --revision takes exactly"
2886
2890
                                         " one revision specifier")
2887
2891
        tree, branch, relpath = \
2888
 
            _open_directory_or_containing_tree_or_branch(filename, directory)
 
2892
            bzrdir.BzrDir.open_containing_tree_or_branch(filename)
2889
2893
        branch.lock_read()
2890
2894
        self.add_cleanup(branch.unlock)
2891
2895
        return self._run(tree, branch, relpath, filename, revision,
3376
3380
 
3377
3381
    _see_also = ['info']
3378
3382
    takes_args = ['nickname?']
3379
 
    takes_options = ['directory']
3380
 
    def run(self, nickname=None, directory=u'.'):
3381
 
        branch = Branch.open_containing(directory)[0]
 
3383
    def run(self, nickname=None):
 
3384
        branch = Branch.open_containing(u'.')[0]
3382
3385
        if nickname is None:
3383
3386
            self.printme(branch)
3384
3387
        else:
3790
3793
                ' completely merged into the source, pull from the'
3791
3794
                ' source rather than merging.  When this happens,'
3792
3795
                ' you do not need to commit the result.'),
3793
 
        custom_help('directory',
 
3796
        Option('directory',
3794
3797
               help='Branch to merge into, '
3795
 
                    'rather than the one containing the working directory.'),
 
3798
                    'rather than the one containing the working directory.',
 
3799
               short_name='d',
 
3800
               type=unicode,
 
3801
               ),
3796
3802
        Option('preview', help='Instead of merging, show a diff of the'
3797
3803
               ' merge.'),
3798
3804
        Option('interactive', help='Select changes interactively.',
4572
4578
                     Option('long', help='Show commit date in annotations.'),
4573
4579
                     'revision',
4574
4580
                     'show-ids',
4575
 
                     'directory',
4576
4581
                     ]
4577
4582
    encoding_type = 'exact'
4578
4583
 
4579
4584
    @display_command
4580
4585
    def run(self, filename, all=False, long=False, revision=None,
4581
 
            show_ids=False, directory=None):
 
4586
            show_ids=False):
4582
4587
        from bzrlib.annotate import annotate_file, annotate_file_tree
4583
4588
        wt, branch, relpath = \
4584
 
            _open_directory_or_containing_tree_or_branch(filename, directory)
 
4589
            bzrdir.BzrDir.open_containing_tree_or_branch(filename)
4585
4590
        if wt is not None:
4586
4591
            wt.lock_read()
4587
4592
            self.add_cleanup(wt.unlock)
4614
4619
 
4615
4620
    hidden = True # is this right ?
4616
4621
    takes_args = ['revision_id*']
4617
 
    takes_options = ['directory', 'revision']
 
4622
    takes_options = ['revision']
4618
4623
 
4619
 
    def run(self, revision_id_list=None, revision=None, directory=u'.'):
 
4624
    def run(self, revision_id_list=None, revision=None):
4620
4625
        if revision_id_list is not None and revision is not None:
4621
4626
            raise errors.BzrCommandError('You can only supply one of revision_id or --revision')
4622
4627
        if revision_id_list is None and revision is None:
4623
4628
            raise errors.BzrCommandError('You must supply either --revision or a revision_id')
4624
 
        b = WorkingTree.open_containing(directory)[0].branch
 
4629
        b = WorkingTree.open_containing(u'.')[0].branch
4625
4630
        b.lock_write()
4626
4631
        self.add_cleanup(b.unlock)
4627
4632
        return self._run(b, revision_id_list, revision)
4688
4693
 
4689
4694
    _see_also = ['checkouts', 'unbind']
4690
4695
    takes_args = ['location?']
4691
 
    takes_options = ['directory']
 
4696
    takes_options = []
4692
4697
 
4693
 
    def run(self, location=None, directory=u'.'):
4694
 
        b, relpath = Branch.open_containing(directory)
 
4698
    def run(self, location=None):
 
4699
        b, relpath = Branch.open_containing(u'.')
4695
4700
        if location is None:
4696
4701
            try:
4697
4702
                location = b.get_old_bound_location()
4724
4729
 
4725
4730
    _see_also = ['checkouts', 'bind']
4726
4731
    takes_args = []
4727
 
    takes_options = ['directory']
 
4732
    takes_options = []
4728
4733
 
4729
 
    def run(self, directory=u'.'):
4730
 
        b, relpath = Branch.open_containing(directory)
 
4734
    def run(self):
 
4735
        b, relpath = Branch.open_containing(u'.')
4731
4736
        if not b.unbind():
4732
4737
            raise errors.BzrCommandError('Local branch is not bound')
4733
4738
 
4897
4902
                    'result in a dynamically allocated port.  The default port '
4898
4903
                    'depends on the protocol.',
4899
4904
               type=str),
4900
 
        custom_help('directory',
4901
 
               help='Serve contents of this directory.'),
 
4905
        Option('directory',
 
4906
               help='Serve contents of this directory.',
 
4907
               type=unicode),
4902
4908
        Option('allow-writes',
4903
4909
               help='By default the server is a readonly server.  Supplying '
4904
4910
                    '--allow-writes enables write access to the contents of '
5333
5339
        Option('delete',
5334
5340
            help='Delete this tag rather than placing it.',
5335
5341
            ),
5336
 
        custom_help('directory',
5337
 
            help='Branch in which to place the tag.'),
 
5342
        Option('directory',
 
5343
            help='Branch in which to place the tag.',
 
5344
            short_name='d',
 
5345
            type=unicode,
 
5346
            ),
5338
5347
        Option('force',
5339
5348
            help='Replace existing tags.',
5340
5349
            ),
5383
5392
 
5384
5393
    _see_also = ['tag']
5385
5394
    takes_options = [
5386
 
        custom_help('directory',
5387
 
            help='Branch whose tags should be displayed.'),
 
5395
        Option('directory',
 
5396
            help='Branch whose tags should be displayed.',
 
5397
            short_name='d',
 
5398
            type=unicode,
 
5399
            ),
5388
5400
        RegistryOption.from_kwargs('sort',
5389
5401
            'Sort tags by different criteria.', title='Sorting',
5390
5402
            alpha='Sort tags lexicographically (default).',
5954
5966
 
5955
5967
    To check what clean-tree will do, use --dry-run.
5956
5968
    """
5957
 
    takes_options = ['directory',
5958
 
                     Option('ignored', help='Delete all ignored files.'),
 
5969
    takes_options = [Option('ignored', help='Delete all ignored files.'),
5959
5970
                     Option('detritus', help='Delete conflict files, merge'
5960
5971
                            ' backups, and failed selftest dirs.'),
5961
5972
                     Option('unknown',
5964
5975
                            ' deleting them.'),
5965
5976
                     Option('force', help='Do not prompt before deleting.')]
5966
5977
    def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
5967
 
            force=False, directory=u'.'):
 
5978
            force=False):
5968
5979
        from bzrlib.clean_tree import clean_tree
5969
5980
        if not (unknown or ignored or detritus):
5970
5981
            unknown = True
5971
5982
        if dry_run:
5972
5983
            force = True
5973
 
        clean_tree(directory, unknown=unknown, ignored=ignored,
5974
 
                   detritus=detritus, dry_run=dry_run, no_prompt=force)
 
5984
        clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus,
 
5985
                   dry_run=dry_run, no_prompt=force)
5975
5986
 
5976
5987
 
5977
5988
class cmd_reference(Command):