/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: Parth Malwankar
  • Date: 2010-05-05 04:08:11 UTC
  • mfrom: (5205 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5216.
  • Revision ID: parth.malwankar@gmail.com-20100505040811-2th2a48s7wak2p9d
merged in changes from trunk and resolved conflict in builtins.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
232
232
    return view_info
233
233
 
234
234
 
 
235
def _open_directory_or_containing_tree_or_branch(filename, directory):
 
236
    """Open the tree or branch containing the specified file, unless
 
237
    the --directory option is used to specify a different branch."""
 
238
    if directory is not None:
 
239
        return (None, Branch.open(directory), filename)
 
240
    return bzrdir.BzrDir.open_containing_tree_or_branch(filename)
 
241
 
 
242
 
235
243
# TODO: Make sure no commands unconditionally use the working directory as a
236
244
# branch.  If a filename argument is used, the first of them should be used to
237
245
# specify the branch.  (Perhaps this can be factored out into some kind of
340
348
 
341
349
    hidden = True
342
350
    takes_args = ['revision_id?']
343
 
    takes_options = ['revision']
 
351
    takes_options = ['directory', 'revision']
344
352
    # cat-revision is more for frontends so should be exact
345
353
    encoding = 'strict'
346
354
 
353
361
        self.outf.write(revtext.decode('utf-8'))
354
362
 
355
363
    @display_command
356
 
    def run(self, revision_id=None, revision=None):
 
364
    def run(self, revision_id=None, revision=None, directory=u'.'):
357
365
        if revision_id is not None and revision is not None:
358
366
            raise errors.BzrCommandError('You can only supply one of'
359
367
                                         ' revision_id or --revision')
360
368
        if revision_id is None and revision is None:
361
369
            raise errors.BzrCommandError('You must supply either'
362
370
                                         ' --revision or a revision_id')
363
 
        b = WorkingTree.open_containing(u'.')[0].branch
 
371
        b = WorkingTree.open_containing(directory)[0].branch
364
372
 
365
373
        revisions = b.repository.revisions
366
374
        if revisions is None:
554
562
    takes_args = ['revision_info*']
555
563
    takes_options = [
556
564
        'revision',
557
 
        Option('directory',
 
565
        custom_help('directory',
558
566
            help='Branch to examine, '
559
 
                 'rather than the one containing the working directory.',
560
 
            short_name='d',
561
 
            type=unicode,
562
 
            ),
 
567
                 'rather than the one containing the working directory.'),
563
568
        Option('tree', help='Show revno of working tree'),
564
569
        ]
565
570
 
960
965
    takes_options = ['remember', 'overwrite', 'revision',
961
966
        custom_help('verbose',
962
967
            help='Show logs of pulled revisions.'),
963
 
        Option('directory',
 
968
        custom_help('directory',
964
969
            help='Branch to pull into, '
965
 
                 'rather than the one containing the working directory.',
966
 
            short_name='d',
967
 
            type=unicode,
968
 
            ),
 
970
                 'rather than the one containing the working directory.'),
969
971
        Option('local',
970
972
            help="Perform a local pull in a bound "
971
973
                 "branch.  Local pulls are not applied to "
1088
1090
        Option('create-prefix',
1089
1091
               help='Create the path leading up to the branch '
1090
1092
                    'if it does not already exist.'),
1091
 
        Option('directory',
 
1093
        custom_help('directory',
1092
1094
            help='Branch to push from, '
1093
 
                 'rather than the one containing the working directory.',
1094
 
            short_name='d',
1095
 
            type=unicode,
1096
 
            ),
 
1095
                 'rather than the one containing the working directory.'),
1097
1096
        Option('use-existing-dir',
1098
1097
               help='By default push will fail if the target'
1099
1098
                    ' directory exists, but does not already'
2003
2002
    # level of effort but possibly much less IO.  (Or possibly not,
2004
2003
    # if the directories are very large...)
2005
2004
    _see_also = ['status', 'ls']
2006
 
    takes_options = ['show-ids']
 
2005
    takes_options = ['directory', 'show-ids']
2007
2006
 
2008
2007
    @display_command
2009
 
    def run(self, show_ids=False):
2010
 
        tree = WorkingTree.open_containing(u'.')[0]
 
2008
    def run(self, show_ids=False, directory=u'.'):
 
2009
        tree = WorkingTree.open_containing(directory)[0]
2011
2010
        tree.lock_read()
2012
2011
        self.add_cleanup(tree.unlock)
2013
2012
        old = tree.basis_tree()
2028
2027
 
2029
2028
    hidden = True
2030
2029
    _see_also = ['status', 'ls']
2031
 
    takes_options = ['null']
 
2030
    takes_options = ['directory', 'null']
2032
2031
 
2033
2032
    @display_command
2034
 
    def run(self, null=False):
2035
 
        tree = WorkingTree.open_containing(u'.')[0]
 
2033
    def run(self, null=False, directory=u'.'):
 
2034
        tree = WorkingTree.open_containing(directory)[0]
2036
2035
        td = tree.changes_from(tree.basis_tree())
2037
2036
        for path, id, kind, text_modified, meta_modified in td.modified:
2038
2037
            if null:
2047
2046
 
2048
2047
    hidden = True
2049
2048
    _see_also = ['status', 'ls']
2050
 
    takes_options = ['null']
 
2049
    takes_options = ['directory', 'null']
2051
2050
 
2052
2051
    @display_command
2053
 
    def run(self, null=False):
2054
 
        wt = WorkingTree.open_containing(u'.')[0]
 
2052
    def run(self, null=False, directory=u'.'):
 
2053
        wt = WorkingTree.open_containing(directory)[0]
2055
2054
        wt.lock_read()
2056
2055
        self.add_cleanup(wt.unlock)
2057
2056
        basis = wt.basis_tree()
2065
2064
            if inv.is_root(file_id) and len(basis_inv) == 0:
2066
2065
                continue
2067
2066
            path = inv.id2path(file_id)
2068
 
            if not os.access(osutils.abspath(path), os.F_OK):
 
2067
            if not os.access(osutils.pathjoin(wt.basedir, path), os.F_OK):
2069
2068
                continue
2070
2069
            if null:
2071
2070
                self.outf.write(path + '\0')
2531
2530
                   type=unicode),
2532
2531
            'null',
2533
2532
            'show-ids',
 
2533
            'directory',
2534
2534
            ]
2535
2535
    @display_command
2536
2536
    def run(self, revision=None, verbose=False,
2537
2537
            recursive=False, from_root=False,
2538
2538
            unknown=False, versioned=False, ignored=False,
2539
 
            null=False, kind=None, show_ids=False, path=None):
 
2539
            null=False, kind=None, show_ids=False, path=None, directory=None):
2540
2540
 
2541
2541
        if kind and kind not in ('file', 'directory', 'symlink'):
2542
2542
            raise errors.BzrCommandError('invalid kind specified')
2554
2554
                raise errors.BzrCommandError('cannot specify both --from-root'
2555
2555
                                             ' and PATH')
2556
2556
            fs_path = path
2557
 
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
2558
 
            fs_path)
 
2557
        tree, branch, relpath = \
 
2558
            _open_directory_or_containing_tree_or_branch(fs_path, directory)
2559
2559
 
2560
2560
        # Calculate the prefix to use
2561
2561
        prefix = None
2630
2630
 
2631
2631
    hidden = True
2632
2632
    _see_also = ['ls']
 
2633
    takes_options = ['directory']
2633
2634
 
2634
2635
    @display_command
2635
 
    def run(self):
2636
 
        for f in WorkingTree.open_containing(u'.')[0].unknowns():
 
2636
    def run(self, directory=u'.'):
 
2637
        for f in WorkingTree.open_containing(directory)[0].unknowns():
2637
2638
            self.outf.write(osutils.quotefn(f) + '\n')
2638
2639
 
2639
2640
 
2704
2705
 
2705
2706
    _see_also = ['status', 'ignored', 'patterns']
2706
2707
    takes_args = ['name_pattern*']
2707
 
    takes_options = [
 
2708
    takes_options = ['directory',
2708
2709
        Option('default-rules',
2709
2710
               help='Display the default ignore rules that bzr uses.')
2710
2711
        ]
2711
2712
 
2712
 
    def run(self, name_pattern_list=None, default_rules=None):
 
2713
    def run(self, name_pattern_list=None, default_rules=None,
 
2714
            directory=u'.'):
2713
2715
        from bzrlib import ignores
2714
2716
        if default_rules is not None:
2715
2717
            # dump the default rules and exit
2726
2728
                (len(name_pattern) > 1 and name_pattern[1] == ':')):
2727
2729
                raise errors.BzrCommandError(
2728
2730
                    "NAME_PATTERN should not be an absolute path")
2729
 
        tree, relpath = WorkingTree.open_containing(u'.')
 
2731
        tree, relpath = WorkingTree.open_containing(directory)
2730
2732
        ignores.tree_ignores_add_patterns(tree, name_pattern_list)
2731
2733
        ignored = globbing.Globster(name_pattern_list)
2732
2734
        matches = []
2758
2760
 
2759
2761
    encoding_type = 'replace'
2760
2762
    _see_also = ['ignore', 'ls']
 
2763
    takes_options = ['directory']
2761
2764
 
2762
2765
    @display_command
2763
 
    def run(self):
2764
 
        tree = WorkingTree.open_containing(u'.')[0]
 
2766
    def run(self, directory=u'.'):
 
2767
        tree = WorkingTree.open_containing(directory)[0]
2765
2768
        tree.lock_read()
2766
2769
        self.add_cleanup(tree.unlock)
2767
2770
        for path, file_class, kind, file_id, entry in tree.list_files():
2780
2783
    """
2781
2784
    hidden = True
2782
2785
    takes_args = ['revno']
 
2786
    takes_options = ['directory']
2783
2787
 
2784
2788
    @display_command
2785
 
    def run(self, revno):
 
2789
    def run(self, revno, directory=u'.'):
2786
2790
        try:
2787
2791
            revno = int(revno)
2788
2792
        except ValueError:
2789
2793
            raise errors.BzrCommandError("not a valid revision-number: %r"
2790
2794
                                         % revno)
2791
 
        revid = WorkingTree.open_containing(u'.')[0].branch.get_rev_id(revno)
 
2795
        revid = WorkingTree.open_containing(directory)[0].branch.get_rev_id(revno)
2792
2796
        self.outf.write("%s\n" % revid)
2793
2797
 
2794
2798
 
2821
2825
      =================       =========================
2822
2826
    """
2823
2827
    takes_args = ['dest', 'branch_or_subdir?']
2824
 
    takes_options = [
 
2828
    takes_options = ['directory',
2825
2829
        Option('format',
2826
2830
               help="Type of file to export to.",
2827
2831
               type=unicode),
2836
2840
                    'revision in which it was changed.'),
2837
2841
        ]
2838
2842
    def run(self, dest, branch_or_subdir=None, revision=None, format=None,
2839
 
        root=None, filters=False, per_file_timestamps=False):
 
2843
        root=None, filters=False, per_file_timestamps=False, directory=u'.'):
2840
2844
        from bzrlib.export import export
2841
2845
 
2842
2846
        if branch_or_subdir is None:
2843
 
            tree = WorkingTree.open_containing(u'.')[0]
 
2847
            tree = WorkingTree.open_containing(directory)[0]
2844
2848
            b = tree.branch
2845
2849
            subdir = None
2846
2850
        else:
2865
2869
    """
2866
2870
 
2867
2871
    _see_also = ['ls']
2868
 
    takes_options = [
 
2872
    takes_options = ['directory',
2869
2873
        Option('name-from-revision', help='The path name in the old tree.'),
2870
2874
        Option('filters', help='Apply content filters to display the '
2871
2875
                'convenience form.'),
2876
2880
 
2877
2881
    @display_command
2878
2882
    def run(self, filename, revision=None, name_from_revision=False,
2879
 
            filters=False):
 
2883
            filters=False, directory=None):
2880
2884
        if revision is not None and len(revision) != 1:
2881
2885
            raise errors.BzrCommandError("bzr cat --revision takes exactly"
2882
2886
                                         " one revision specifier")
2883
2887
        tree, branch, relpath = \
2884
 
            bzrdir.BzrDir.open_containing_tree_or_branch(filename)
 
2888
            _open_directory_or_containing_tree_or_branch(filename, directory)
2885
2889
        branch.lock_read()
2886
2890
        self.add_cleanup(branch.unlock)
2887
2891
        return self._run(tree, branch, relpath, filename, revision,
3065
3069
                         "the master branch until a normal commit "
3066
3070
                         "is performed."
3067
3071
                    ),
3068
 
             Option('show-diff',
 
3072
             Option('show-diff', short_name='p',
3069
3073
                    help='When no message is supplied, show the diff along'
3070
3074
                    ' with the status summary in the message editor.'),
3071
3075
             ]
3372
3376
 
3373
3377
    _see_also = ['info']
3374
3378
    takes_args = ['nickname?']
3375
 
    def run(self, nickname=None):
3376
 
        branch = Branch.open_containing(u'.')[0]
 
3379
    takes_options = ['directory']
 
3380
    def run(self, nickname=None, directory=u'.'):
 
3381
        branch = Branch.open_containing(directory)[0]
3377
3382
        if nickname is None:
3378
3383
            self.printme(branch)
3379
3384
        else:
3785
3790
                ' completely merged into the source, pull from the'
3786
3791
                ' source rather than merging.  When this happens,'
3787
3792
                ' you do not need to commit the result.'),
3788
 
        Option('directory',
 
3793
        custom_help('directory',
3789
3794
               help='Branch to merge into, '
3790
 
                    'rather than the one containing the working directory.',
3791
 
               short_name='d',
3792
 
               type=unicode,
3793
 
               ),
 
3795
                    'rather than the one containing the working directory.'),
3794
3796
        Option('preview', help='Instead of merging, show a diff of the'
3795
3797
               ' merge.'),
3796
3798
        Option('interactive', help='Select changes interactively.',
4570
4572
                     Option('long', help='Show commit date in annotations.'),
4571
4573
                     'revision',
4572
4574
                     'show-ids',
 
4575
                     'directory',
4573
4576
                     ]
4574
4577
    encoding_type = 'exact'
4575
4578
 
4576
4579
    @display_command
4577
4580
    def run(self, filename, all=False, long=False, revision=None,
4578
 
            show_ids=False):
 
4581
            show_ids=False, directory=None):
4579
4582
        from bzrlib.annotate import annotate_file, annotate_file_tree
4580
4583
        wt, branch, relpath = \
4581
 
            bzrdir.BzrDir.open_containing_tree_or_branch(filename)
 
4584
            _open_directory_or_containing_tree_or_branch(filename, directory)
4582
4585
        if wt is not None:
4583
4586
            wt.lock_read()
4584
4587
            self.add_cleanup(wt.unlock)
4611
4614
 
4612
4615
    hidden = True # is this right ?
4613
4616
    takes_args = ['revision_id*']
4614
 
    takes_options = ['revision']
 
4617
    takes_options = ['directory', 'revision']
4615
4618
 
4616
 
    def run(self, revision_id_list=None, revision=None):
 
4619
    def run(self, revision_id_list=None, revision=None, directory=u'.'):
4617
4620
        if revision_id_list is not None and revision is not None:
4618
4621
            raise errors.BzrCommandError('You can only supply one of revision_id or --revision')
4619
4622
        if revision_id_list is None and revision is None:
4620
4623
            raise errors.BzrCommandError('You must supply either --revision or a revision_id')
4621
 
        b = WorkingTree.open_containing(u'.')[0].branch
 
4624
        b = WorkingTree.open_containing(directory)[0].branch
4622
4625
        b.lock_write()
4623
4626
        self.add_cleanup(b.unlock)
4624
4627
        return self._run(b, revision_id_list, revision)
4673
4676
 
4674
4677
class cmd_bind(Command):
4675
4678
    __doc__ = """Convert the current branch into a checkout of the supplied branch.
 
4679
    If no branch is supplied, rebind to the last bound location.
4676
4680
 
4677
4681
    Once converted into a checkout, commits must succeed on the master branch
4678
4682
    before they will be applied to the local branch.
4684
4688
 
4685
4689
    _see_also = ['checkouts', 'unbind']
4686
4690
    takes_args = ['location?']
4687
 
    takes_options = []
 
4691
    takes_options = ['directory']
4688
4692
 
4689
 
    def run(self, location=None):
4690
 
        b, relpath = Branch.open_containing(u'.')
 
4693
    def run(self, location=None, directory=u'.'):
 
4694
        b, relpath = Branch.open_containing(directory)
4691
4695
        if location is None:
4692
4696
            try:
4693
4697
                location = b.get_old_bound_location()
4720
4724
 
4721
4725
    _see_also = ['checkouts', 'bind']
4722
4726
    takes_args = []
4723
 
    takes_options = []
 
4727
    takes_options = ['directory']
4724
4728
 
4725
 
    def run(self):
4726
 
        b, relpath = Branch.open_containing(u'.')
 
4729
    def run(self, directory=u'.'):
 
4730
        b, relpath = Branch.open_containing(directory)
4727
4731
        if not b.unbind():
4728
4732
            raise errors.BzrCommandError('Local branch is not bound')
4729
4733
 
4893
4897
                    'result in a dynamically allocated port.  The default port '
4894
4898
                    'depends on the protocol.',
4895
4899
               type=str),
4896
 
        Option('directory',
4897
 
               help='Serve contents of this directory.',
4898
 
               type=unicode),
 
4900
        custom_help('directory',
 
4901
               help='Serve contents of this directory.'),
4899
4902
        Option('allow-writes',
4900
4903
               help='By default the server is a readonly server.  Supplying '
4901
4904
                    '--allow-writes enables write access to the contents of '
5330
5333
        Option('delete',
5331
5334
            help='Delete this tag rather than placing it.',
5332
5335
            ),
5333
 
        Option('directory',
5334
 
            help='Branch in which to place the tag.',
5335
 
            short_name='d',
5336
 
            type=unicode,
5337
 
            ),
 
5336
        custom_help('directory',
 
5337
            help='Branch in which to place the tag.'),
5338
5338
        Option('force',
5339
5339
            help='Replace existing tags.',
5340
5340
            ),
5383
5383
 
5384
5384
    _see_also = ['tag']
5385
5385
    takes_options = [
5386
 
        Option('directory',
5387
 
            help='Branch whose tags should be displayed.',
5388
 
            short_name='d',
5389
 
            type=unicode,
5390
 
            ),
 
5386
        custom_help('directory',
 
5387
            help='Branch whose tags should be displayed.'),
5391
5388
        RegistryOption.from_kwargs('sort',
5392
5389
            'Sort tags by different criteria.', title='Sorting',
5393
5390
            alpha='Sort tags lexicographically (default).',
5957
5954
 
5958
5955
    To check what clean-tree will do, use --dry-run.
5959
5956
    """
5960
 
    takes_options = [Option('ignored', help='Delete all ignored files.'),
 
5957
    takes_options = ['directory',
 
5958
                     Option('ignored', help='Delete all ignored files.'),
5961
5959
                     Option('detritus', help='Delete conflict files, merge'
5962
5960
                            ' backups, and failed selftest dirs.'),
5963
5961
                     Option('unknown',
5966
5964
                            ' deleting them.'),
5967
5965
                     Option('force', help='Do not prompt before deleting.')]
5968
5966
    def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
5969
 
            force=False):
 
5967
            force=False, directory=u'.'):
5970
5968
        from bzrlib.clean_tree import clean_tree
5971
5969
        if not (unknown or ignored or detritus):
5972
5970
            unknown = True
5973
5971
        if dry_run:
5974
5972
            force = True
5975
 
        clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus,
5976
 
                   dry_run=dry_run, no_prompt=force)
 
5973
        clean_tree(directory, unknown=unknown, ignored=ignored,
 
5974
                   detritus=detritus, dry_run=dry_run, no_prompt=force)
5977
5975
 
5978
5976
 
5979
5977
class cmd_reference(Command):