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)
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
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'
361
353
self.outf.write(revtext.decode('utf-8'))
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
373
365
revisions = b.repository.revisions
374
366
if revisions is None:
560
552
takes_args = ['revision_info*']
561
553
takes_options = [
563
custom_help('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.',
566
561
Option('tree', help='Show revno of working tree'),
956
951
takes_options = ['remember', 'overwrite', 'revision',
957
952
custom_help('verbose',
958
953
help='Show logs of pulled revisions.'),
959
custom_help('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.',
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',
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.',
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']
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)
2011
2012
_see_also = ['status', 'ls']
2012
takes_options = ['directory', 'null']
2015
help='Write an ascii NUL (\\0) separator '
2016
'between files rather than a newline.')
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:
2030
2035
_see_also = ['status', 'ls']
2031
takes_options = ['directory', 'null']
2038
help='Write an ascii NUL (\\0) separator '
2039
'between files rather than a newline.')
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:
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):
2050
2059
self.outf.write(path + '\0')
2250
2259
help='Show just the specified revision.'
2251
2260
' 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'),
2258
2262
Option('levels',
2259
2263
short_name='n',
2260
2264
help='Number of levels to display - 0 for all, 1 for flat.',
2379
2382
show_timezone=timezone,
2380
2383
delta_format=get_verbosity_level(),
2382
show_advice=levels is None,
2383
author_list_handler=authors)
2385
show_advice=levels is None)
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.'),
2513
help='Write an ascii NUL (\\0) separator '
2514
'between files rather than a newline.'),
2513
2516
help='List entries of a particular kind: file, directory, symlink.',
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):
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'
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(
2544
2545
# Calculate the prefix to use
2615
2616
_see_also = ['ls']
2616
takes_options = ['directory']
2618
2618
@display_command
2619
def run(self, directory=u'.'):
2620
for f in WorkingTree.open_containing(directory)[0].unknowns():
2620
for f in WorkingTree.open_containing(u'.')[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):
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)
2744
2743
encoding_type = 'replace'
2745
2744
_see_also = ['ignore', 'ls']
2746
takes_options = ['directory']
2748
2746
@display_command
2749
def run(self, directory=u'.'):
2750
tree = WorkingTree.open_containing(directory)[0]
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':
2767
2765
takes_args = ['revno']
2768
takes_options = ['directory']
2770
2767
@display_command
2771
def run(self, revno, directory=u'.'):
2768
def run(self, revno):
2773
2770
revno = int(revno)
2774
2771
except ValueError:
2775
2772
raise errors.BzrCommandError("not a valid revision-number: %r"
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)
2807
2804
================= =========================
2809
2806
takes_args = ['dest', 'branch_or_subdir?']
2810
takes_options = ['directory',
2811
2808
Option('format',
2812
2809
help="Type of file to export to.",
2822
2819
'revision in which it was changed.'),
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
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
2853
2850
_see_also = ['ls']
2854
takes_options = ['directory',
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.'),
2863
2860
@display_command
2864
2861
def run(self, filename, revision=None, name_from_revision=False,
2865
filters=False, directory=None):
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"""
3148
f = codecs.open(file, 'rt', osutils.get_user_encoding())
3150
my_message = f.read()
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
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)
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:
3601
3590
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
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',
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.',
3781
3773
Option('preview', help='Instead of merging, show a diff of the'
3783
3775
Option('interactive', help='Select changes interactively.',
4550
4542
Option('long', help='Show commit date in annotations.'),
4555
4546
encoding_type = 'exact'
4557
4548
@display_command
4558
4549
def run(self, filename, all=False, long=False, revision=None,
4559
show_ids=False, directory=None):
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)
4590
4581
hidden = True # is this right ?
4591
4582
takes_args = ['revision_id*']
4592
takes_options = ['directory', 'revision']
4583
takes_options = ['revision']
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)
4663
4654
_see_also = ['checkouts', 'unbind']
4664
4655
takes_args = ['location?']
4665
takes_options = ['directory']
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:
4671
4662
location = b.get_old_bound_location()
4699
4690
_see_also = ['checkouts', 'bind']
4700
4691
takes_args = []
4701
takes_options = ['directory']
4703
def run(self, directory=u'.'):
4704
b, relpath = Branch.open_containing(directory)
4695
b, relpath = Branch.open_containing(u'.')
4705
4696
if not b.unbind():
4706
4697
raise errors.BzrCommandError('Local branch is not bound')
4869
4860
'result in a dynamically allocated port. The default port '
4870
4861
'depends on the protocol.',
4872
custom_help('directory',
4873
help='Serve contents of this directory.'),
4864
help='Serve contents of this directory.',
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.
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.
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.',
5308
custom_help('directory',
5309
help='Branch in which to place the tag.'),
5301
help='Branch in which to place the tag.',
5310
5305
Option('force',
5311
5306
help='Replace existing tags.',
5355
5350
_see_also = ['tag']
5356
5351
takes_options = [
5357
custom_help('directory',
5358
help='Branch whose tags should be displayed.'),
5353
help='Branch whose tags should be displayed.',
5359
5357
RegistryOption.from_kwargs('sort',
5360
5358
'Sort tags by different criteria.', title='Sorting',
5361
5359
alpha='Sort tags lexicographically (default).',
5924
5922
To check what clean-tree will do, use --dry-run.
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'.'):
5937
5934
from bzrlib.clean_tree import clean_tree
5938
5935
if not (unknown or ignored or detritus):
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)
5946
5943
class cmd_reference(Command):