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'
1987
1986
# level of effort but possibly much less IO. (Or possibly not,
1988
1987
# if the directories are very large...)
1989
1988
_see_also = ['status', 'ls']
1990
takes_options = ['show-ids']
1989
takes_options = ['directory', 'show-ids']
1992
1991
@display_command
1993
def run(self, show_ids=False):
1994
tree = WorkingTree.open_containing(u'.')[0]
1992
def run(self, show_ids=False, directory=u'.'):
1993
tree = WorkingTree.open_containing(directory)[0]
1995
1994
self.add_cleanup(tree.lock_read().unlock)
1996
1995
old = tree.basis_tree()
1997
1996
self.add_cleanup(old.lock_read().unlock)
2012
2011
_see_also = ['status', 'ls']
2015
help='Write an ascii NUL (\\0) separator '
2016
'between files rather than a newline.')
2012
takes_options = ['directory', 'null']
2019
2014
@display_command
2020
def run(self, null=False):
2021
tree = WorkingTree.open_containing(u'.')[0]
2015
def run(self, null=False, directory=u'.'):
2016
tree = WorkingTree.open_containing(directory)[0]
2022
2017
td = tree.changes_from(tree.basis_tree())
2023
2018
for path, id, kind, text_modified, meta_modified in td.modified:
2035
2030
_see_also = ['status', 'ls']
2038
help='Write an ascii NUL (\\0) separator '
2039
'between files rather than a newline.')
2031
takes_options = ['directory', 'null']
2042
2033
@display_command
2043
def run(self, null=False):
2044
wt = WorkingTree.open_containing(u'.')[0]
2034
def run(self, null=False, directory=u'.'):
2035
wt = WorkingTree.open_containing(directory)[0]
2045
2036
self.add_cleanup(wt.lock_read().unlock)
2046
2037
basis = wt.basis_tree()
2047
2038
self.add_cleanup(basis.lock_read().unlock)
2053
2044
if inv.is_root(file_id) and len(basis_inv) == 0:
2055
2046
path = inv.id2path(file_id)
2056
if not os.access(osutils.abspath(path), os.F_OK):
2047
if not os.access(osutils.pathjoin(wt.basedir, path), os.F_OK):
2059
2050
self.outf.write(path + '\0')
2259
2250
help='Show just the specified revision.'
2260
2251
' See also "help revisionspec".'),
2253
RegistryOption('authors',
2254
'What names to list as authors - first, all or committer.',
2256
lazy_registry=('bzrlib.log', 'author_list_registry'),
2262
2258
Option('levels',
2263
2259
short_name='n',
2264
2260
help='Number of levels to display - 0 for all, 1 for flat.',
2382
2379
show_timezone=timezone,
2383
2380
delta_format=get_verbosity_level(),
2385
show_advice=levels is None)
2382
show_advice=levels is None,
2383
author_list_handler=authors)
2387
2385
# Choose the algorithm for doing the logging. It's annoying
2388
2386
# having multiple code paths like this but necessary until
2505
2503
help='Recurse into subdirectories.'),
2506
2504
Option('from-root',
2507
2505
help='Print paths relative to the root of the branch.'),
2508
Option('unknown', help='Print unknown files.'),
2506
Option('unknown', short_name='u',
2507
help='Print unknown files.'),
2509
2508
Option('versioned', help='Print versioned files.',
2510
2509
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.'),
2510
Option('ignored', short_name='i',
2511
help='Print ignored files.'),
2512
Option('kind', short_name='k',
2516
2513
help='List entries of a particular kind: file, directory, symlink.',
2520
2519
@display_command
2521
2520
def run(self, revision=None, verbose=False,
2522
2521
recursive=False, from_root=False,
2523
2522
unknown=False, versioned=False, ignored=False,
2524
null=False, kind=None, show_ids=False, path=None):
2523
null=False, kind=None, show_ids=False, path=None, directory=None):
2526
2525
if kind and kind not in ('file', 'directory', 'symlink'):
2527
2526
raise errors.BzrCommandError('invalid kind specified')
2539
2538
raise errors.BzrCommandError('cannot specify both --from-root'
2542
tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
2541
tree, branch, relpath = \
2542
_open_directory_or_containing_tree_or_branch(fs_path, directory)
2545
2544
# Calculate the prefix to use
2616
2615
_see_also = ['ls']
2616
takes_options = ['directory']
2618
2618
@display_command
2620
for f in WorkingTree.open_containing(u'.')[0].unknowns():
2619
def run(self, directory=u'.'):
2620
for f in WorkingTree.open_containing(directory)[0].unknowns():
2621
2621
self.outf.write(osutils.quotefn(f) + '\n')
2689
2689
_see_also = ['status', 'ignored', 'patterns']
2690
2690
takes_args = ['name_pattern*']
2691
takes_options = ['directory',
2692
2692
Option('default-rules',
2693
2693
help='Display the default ignore rules that bzr uses.')
2696
def run(self, name_pattern_list=None, default_rules=None):
2696
def run(self, name_pattern_list=None, default_rules=None,
2697
2698
from bzrlib import ignores
2698
2699
if default_rules is not None:
2699
2700
# dump the default rules and exit
2710
2711
(len(name_pattern) > 1 and name_pattern[1] == ':')):
2711
2712
raise errors.BzrCommandError(
2712
2713
"NAME_PATTERN should not be an absolute path")
2713
tree, relpath = WorkingTree.open_containing(u'.')
2714
tree, relpath = WorkingTree.open_containing(directory)
2714
2715
ignores.tree_ignores_add_patterns(tree, name_pattern_list)
2715
2716
ignored = globbing.Globster(name_pattern_list)
2743
2744
encoding_type = 'replace'
2744
2745
_see_also = ['ignore', 'ls']
2746
takes_options = ['directory']
2746
2748
@display_command
2748
tree = WorkingTree.open_containing(u'.')[0]
2749
def run(self, directory=u'.'):
2750
tree = WorkingTree.open_containing(directory)[0]
2749
2751
self.add_cleanup(tree.lock_read().unlock)
2750
2752
for path, file_class, kind, file_id, entry in tree.list_files():
2751
2753
if file_class != 'I':
2765
2767
takes_args = ['revno']
2768
takes_options = ['directory']
2767
2770
@display_command
2768
def run(self, revno):
2771
def run(self, revno, directory=u'.'):
2770
2773
revno = int(revno)
2771
2774
except ValueError:
2772
2775
raise errors.BzrCommandError("not a valid revision-number: %r"
2774
revid = WorkingTree.open_containing(u'.')[0].branch.get_rev_id(revno)
2777
revid = WorkingTree.open_containing(directory)[0].branch.get_rev_id(revno)
2775
2778
self.outf.write("%s\n" % revid)
2804
2807
================= =========================
2806
2809
takes_args = ['dest', 'branch_or_subdir?']
2810
takes_options = ['directory',
2808
2811
Option('format',
2809
2812
help="Type of file to export to.",
2819
2822
'revision in which it was changed.'),
2821
2824
def run(self, dest, branch_or_subdir=None, revision=None, format=None,
2822
root=None, filters=False, per_file_timestamps=False):
2825
root=None, filters=False, per_file_timestamps=False, directory=u'.'):
2823
2826
from bzrlib.export import export
2825
2828
if branch_or_subdir is None:
2826
tree = WorkingTree.open_containing(u'.')[0]
2829
tree = WorkingTree.open_containing(directory)[0]
2827
2830
b = tree.branch
2850
2853
_see_also = ['ls']
2854
takes_options = ['directory',
2852
2855
Option('name-from-revision', help='The path name in the old tree.'),
2853
2856
Option('filters', help='Apply content filters to display the '
2854
2857
'convenience form.'),
2860
2863
@display_command
2861
2864
def run(self, filename, revision=None, name_from_revision=False,
2865
filters=False, directory=None):
2863
2866
if revision is not None and len(revision) != 1:
2864
2867
raise errors.BzrCommandError("bzr cat --revision takes exactly"
2865
2868
" one revision specifier")
2866
2869
tree, branch, relpath = \
2867
bzrdir.BzrDir.open_containing_tree_or_branch(filename)
2870
_open_directory_or_containing_tree_or_branch(filename, directory)
2868
2871
self.add_cleanup(branch.lock_read().unlock)
2869
2872
return self._run(tree, branch, relpath, filename, revision,
2870
2873
name_from_revision, filters)
3354
3357
_see_also = ['info']
3355
3358
takes_args = ['nickname?']
3356
def run(self, nickname=None):
3357
branch = Branch.open_containing(u'.')[0]
3359
takes_options = ['directory']
3360
def run(self, nickname=None, directory=u'.'):
3361
branch = Branch.open_containing(directory)[0]
3358
3362
if nickname is None:
3359
3363
self.printme(branch)
3585
3589
self.additional_selftest_args['runner_class'] = SubUnitBzrRunner
3586
3590
# On Windows, disable automatic conversion of '\n' to '\r\n' in
3587
3591
# stdout, which would corrupt the subunit stream.
3588
if sys.platform == "win32" and sys.stdout.fileno() >= 0:
3592
# FIXME: This has been fixed in subunit trunk (>0.0.5) so the
3593
# following code can be deleted when it's sufficiently deployed
3594
# -- vila/mgz 20100514
3595
if (sys.platform == "win32"
3596
and getattr(sys.stdout, 'fileno', None) is not None):
3590
3598
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
3764
3772
' completely merged into the source, pull from the'
3765
3773
' source rather than merging. When this happens,'
3766
3774
' you do not need to commit the result.'),
3775
custom_help('directory',
3768
3776
help='Branch to merge into, '
3769
'rather than the one containing the working directory.',
3777
'rather than the one containing the working directory.'),
3773
3778
Option('preview', help='Instead of merging, show a diff of the'
3775
3780
Option('interactive', help='Select changes interactively.',
4542
4547
Option('long', help='Show commit date in annotations.'),
4546
4552
encoding_type = 'exact'
4548
4554
@display_command
4549
4555
def run(self, filename, all=False, long=False, revision=None,
4556
show_ids=False, directory=None):
4551
4557
from bzrlib.annotate import annotate_file, annotate_file_tree
4552
4558
wt, branch, relpath = \
4553
bzrdir.BzrDir.open_containing_tree_or_branch(filename)
4559
_open_directory_or_containing_tree_or_branch(filename, directory)
4554
4560
if wt is not None:
4555
4561
self.add_cleanup(wt.lock_read().unlock)
4581
4587
hidden = True # is this right ?
4582
4588
takes_args = ['revision_id*']
4583
takes_options = ['revision']
4589
takes_options = ['directory', 'revision']
4585
def run(self, revision_id_list=None, revision=None):
4591
def run(self, revision_id_list=None, revision=None, directory=u'.'):
4586
4592
if revision_id_list is not None and revision is not None:
4587
4593
raise errors.BzrCommandError('You can only supply one of revision_id or --revision')
4588
4594
if revision_id_list is None and revision is None:
4589
4595
raise errors.BzrCommandError('You must supply either --revision or a revision_id')
4590
b = WorkingTree.open_containing(u'.')[0].branch
4596
b = WorkingTree.open_containing(directory)[0].branch
4591
4597
self.add_cleanup(b.lock_write().unlock)
4592
4598
return self._run(b, revision_id_list, revision)
4654
4660
_see_also = ['checkouts', 'unbind']
4655
4661
takes_args = ['location?']
4662
takes_options = ['directory']
4658
def run(self, location=None):
4659
b, relpath = Branch.open_containing(u'.')
4664
def run(self, location=None, directory=u'.'):
4665
b, relpath = Branch.open_containing(directory)
4660
4666
if location is None:
4662
4668
location = b.get_old_bound_location()
4690
4696
_see_also = ['checkouts', 'bind']
4691
4697
takes_args = []
4698
takes_options = ['directory']
4695
b, relpath = Branch.open_containing(u'.')
4700
def run(self, directory=u'.'):
4701
b, relpath = Branch.open_containing(directory)
4696
4702
if not b.unbind():
4697
4703
raise errors.BzrCommandError('Local branch is not bound')
4860
4866
'result in a dynamically allocated port. The default port '
4861
4867
'depends on the protocol.',
4864
help='Serve contents of this directory.',
4869
custom_help('directory',
4870
help='Serve contents of this directory.'),
4866
4871
Option('allow-writes',
4867
4872
help='By default the server is a readonly server. Supplying '
4868
4873
'--allow-writes enables write access to the contents of '
5297
5302
Option('delete',
5298
5303
help='Delete this tag rather than placing it.',
5301
help='Branch in which to place the tag.',
5305
custom_help('directory',
5306
help='Branch in which to place the tag.'),
5305
5307
Option('force',
5306
5308
help='Replace existing tags.',
5350
5352
_see_also = ['tag']
5351
5353
takes_options = [
5353
help='Branch whose tags should be displayed.',
5354
custom_help('directory',
5355
help='Branch whose tags should be displayed.'),
5357
5356
RegistryOption.from_kwargs('sort',
5358
5357
'Sort tags by different criteria.', title='Sorting',
5359
5358
alpha='Sort tags lexicographically (default).',
5922
5921
To check what clean-tree will do, use --dry-run.
5924
takes_options = [Option('ignored', help='Delete all ignored files.'),
5923
takes_options = ['directory',
5924
Option('ignored', help='Delete all ignored files.'),
5925
5925
Option('detritus', help='Delete conflict files, merge'
5926
5926
' backups, and failed selftest dirs.'),
5927
5927
Option('unknown',
5930
5930
' deleting them.'),
5931
5931
Option('force', help='Do not prompt before deleting.')]
5932
5932
def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
5933
force=False, directory=u'.'):
5934
5934
from bzrlib.clean_tree import clean_tree
5935
5935
if not (unknown or ignored or detritus):
5939
clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus,
5940
dry_run=dry_run, no_prompt=force)
5939
clean_tree(directory, unknown=unknown, ignored=ignored,
5940
detritus=detritus, dry_run=dry_run, no_prompt=force)
5943
5943
class cmd_reference(Command):