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)
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
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'
353
361
self.outf.write(revtext.decode('utf-8'))
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
365
373
revisions = b.repository.revisions
366
374
if revisions is None:
552
560
takes_args = ['revision_info*']
553
561
takes_options = [
563
custom_help('directory',
556
564
help='Branch to examine, '
557
'rather than the one containing the working directory.',
565
'rather than the one containing the working directory.'),
561
566
Option('tree', help='Show revno of working tree'),
951
956
takes_options = ['remember', 'overwrite', 'revision',
952
957
custom_help('verbose',
953
958
help='Show logs of pulled revisions.'),
959
custom_help('directory',
955
960
help='Branch to pull into, '
956
'rather than the one containing the working directory.',
961
'rather than the one containing the working directory.'),
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.'),
1081
custom_help('directory',
1080
1082
help='Branch to push from, '
1081
'rather than the one containing the working directory.',
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)
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)
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']
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)
2012
2016
_see_also = ['status', 'ls']
2015
help='Write an ascii NUL (\\0) separator '
2016
'between files rather than a newline.')
2017
takes_options = ['directory', 'null']
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:
2035
2035
_see_also = ['status', 'ls']
2038
help='Write an ascii NUL (\\0) separator '
2039
'between files rather than a newline.')
2036
takes_options = ['directory', 'null']
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:
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):
2059
2055
self.outf.write(path + '\0')
2259
2255
help='Show just the specified revision.'
2260
2256
' See also "help revisionspec".'),
2258
RegistryOption('authors',
2259
'What names to list as authors - first, all or committer.',
2261
lazy_registry=('bzrlib.log', 'author_list_registry'),
2262
2263
Option('levels',
2263
2264
short_name='n',
2264
2265
help='Number of levels to display - 0 for all, 1 for flat.',
2382
2384
show_timezone=timezone,
2383
2385
delta_format=get_verbosity_level(),
2385
show_advice=levels is None)
2387
show_advice=levels is None,
2388
author_list_handler=authors)
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.'),
2513
help='Write an ascii NUL (\\0) separator '
2514
'between files rather than a newline.'),
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.',
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):
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'
2542
tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
2546
tree, branch, relpath = \
2547
_open_directory_or_containing_tree_or_branch(fs_path, directory)
2545
2549
# Calculate the prefix to use
2616
2620
_see_also = ['ls']
2621
takes_options = ['directory']
2618
2623
@display_command
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')
2689
2694
_see_also = ['status', 'ignored', 'patterns']
2690
2695
takes_args = ['name_pattern*']
2696
takes_options = ['directory',
2692
2697
Option('default-rules',
2693
2698
help='Display the default ignore rules that bzr uses.')
2696
def run(self, name_pattern_list=None, default_rules=None):
2701
def run(self, name_pattern_list=None, default_rules=None,
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)
2743
2749
encoding_type = 'replace'
2744
2750
_see_also = ['ignore', 'ls']
2751
takes_options = ['directory']
2746
2753
@display_command
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':
2765
2772
takes_args = ['revno']
2773
takes_options = ['directory']
2767
2775
@display_command
2768
def run(self, revno):
2776
def run(self, revno, directory=u'.'):
2770
2778
revno = int(revno)
2771
2779
except ValueError:
2772
2780
raise errors.BzrCommandError("not a valid revision-number: %r"
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)
2804
2812
================= =========================
2806
2814
takes_args = ['dest', 'branch_or_subdir?']
2815
takes_options = ['directory',
2808
2816
Option('format',
2809
2817
help="Type of file to export to.",
2819
2827
'revision in which it was changed.'),
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
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
2850
2858
_see_also = ['ls']
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.'),
2860
2868
@display_command
2861
2869
def run(self, filename, revision=None, name_from_revision=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)
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)
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.'),
3776
custom_help('directory',
3768
3777
help='Branch to merge into, '
3769
'rather than the one containing the working directory.',
3778
'rather than the one containing the working directory.'),
3773
3779
Option('preview', help='Instead of merging, show a diff of the'
3775
3781
Option('interactive', help='Select changes interactively.',
4542
4548
Option('long', help='Show commit date in annotations.'),
4546
4553
encoding_type = 'exact'
4548
4555
@display_command
4549
4556
def run(self, filename, all=False, long=False, revision=None,
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)
4581
4588
hidden = True # is this right ?
4582
4589
takes_args = ['revision_id*']
4583
takes_options = ['revision']
4590
takes_options = ['directory', 'revision']
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)
4654
4661
_see_also = ['checkouts', 'unbind']
4655
4662
takes_args = ['location?']
4663
takes_options = ['directory']
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:
4662
4669
location = b.get_old_bound_location()
4690
4697
_see_also = ['checkouts', 'bind']
4691
4698
takes_args = []
4699
takes_options = ['directory']
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')
4860
4867
'result in a dynamically allocated port. The default port '
4861
4868
'depends on the protocol.',
4864
help='Serve contents of this directory.',
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.',
5301
help='Branch in which to place the tag.',
5306
custom_help('directory',
5307
help='Branch in which to place the tag.'),
5305
5308
Option('force',
5306
5309
help='Replace existing tags.',
5350
5353
_see_also = ['tag']
5351
5354
takes_options = [
5353
help='Branch whose tags should be displayed.',
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).',
5922
5922
To check what clean-tree will do, use --dry-run.
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,
5934
force=False, directory=u'.'):
5934
5935
from bzrlib.clean_tree import clean_tree
5935
5936
if not (unknown or ignored or detritus):
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)
5943
5944
class cmd_reference(Command):