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:
530
538
wt = WorkingTree.open_containing(location)[0]
539
self.add_cleanup(wt.lock_read().unlock)
532
540
except (errors.NoWorkingTree, errors.NotLocalUrl):
533
541
raise errors.NoWorkingTree(location)
534
self.add_cleanup(wt.unlock)
535
542
revid = wt.last_revision()
537
544
revno_t = wt.branch.revision_id_to_dotted_revno(revid)
540
547
revno = ".".join(str(n) for n in revno_t)
542
549
b = Branch.open_containing(location)[0]
544
self.add_cleanup(b.unlock)
550
self.add_cleanup(b.lock_read().unlock)
545
551
revno = b.revno()
546
552
self.cleanup_now()
547
553
self.outf.write(str(revno) + '\n')
554
560
takes_args = ['revision_info*']
555
561
takes_options = [
563
custom_help('directory',
558
564
help='Branch to examine, '
559
'rather than the one containing the working directory.',
565
'rather than the one containing the working directory.'),
563
566
Option('tree', help='Show revno of working tree'),
571
574
wt = WorkingTree.open_containing(directory)[0]
574
self.add_cleanup(wt.unlock)
576
self.add_cleanup(wt.lock_read().unlock)
575
577
except (errors.NoWorkingTree, errors.NotLocalUrl):
577
579
b = Branch.open_containing(directory)[0]
579
self.add_cleanup(b.unlock)
580
self.add_cleanup(b.lock_read().unlock)
580
581
revision_ids = []
581
582
if revision is not None:
582
583
revision_ids.extend(rev.as_revision_id(b) for rev in revision)
681
682
should_print=(not is_quiet()))
684
base_tree.lock_read()
685
self.add_cleanup(base_tree.unlock)
685
self.add_cleanup(base_tree.lock_read().unlock)
686
686
tree, file_list = tree_files_for_add(file_list)
687
687
added, ignored = tree.smart_add(file_list, not
688
688
no_recurse, action=action, save=not dry_run)
761
761
revision = _get_one_revision('inventory', revision)
762
762
work_tree, file_list = tree_files(file_list)
763
work_tree.lock_read()
764
self.add_cleanup(work_tree.unlock)
763
self.add_cleanup(work_tree.lock_read().unlock)
765
764
if revision is not None:
766
765
tree = revision.as_tree(work_tree.branch)
768
767
extra_trees = [work_tree]
770
self.add_cleanup(tree.unlock)
768
self.add_cleanup(tree.lock_read().unlock)
833
831
if len(names_list) < 2:
834
832
raise errors.BzrCommandError("missing file argument")
835
833
tree, rel_names = tree_files(names_list, canonicalize=False)
836
tree.lock_tree_write()
837
self.add_cleanup(tree.unlock)
834
self.add_cleanup(tree.lock_tree_write().unlock)
838
835
self._run(tree, names_list, rel_names, after)
840
837
def run_auto(self, names_list, after, dry_run):
845
842
raise errors.BzrCommandError('--after cannot be specified with'
847
844
work_tree, file_list = tree_files(names_list, default_branch='.')
848
work_tree.lock_tree_write()
849
self.add_cleanup(work_tree.unlock)
845
self.add_cleanup(work_tree.lock_tree_write().unlock)
850
846
rename_map.RenameMap.guess_renames(work_tree, dry_run)
852
848
def _run(self, tree, names_list, rel_names, after):
960
956
takes_options = ['remember', 'overwrite', 'revision',
961
957
custom_help('verbose',
962
958
help='Show logs of pulled revisions.'),
959
custom_help('directory',
964
960
help='Branch to pull into, '
965
'rather than the one containing the working directory.',
961
'rather than the one containing the working directory.'),
970
963
help="Perform a local pull in a bound "
971
964
"branch. Local pulls are not applied to "
987
980
tree_to = WorkingTree.open_containing(directory)[0]
988
981
branch_to = tree_to.branch
990
self.add_cleanup(tree_to.unlock)
982
self.add_cleanup(tree_to.lock_write().unlock)
991
983
except errors.NoWorkingTree:
993
985
branch_to = Branch.open_containing(directory)[0]
994
branch_to.lock_write()
995
self.add_cleanup(branch_to.unlock)
986
self.add_cleanup(branch_to.lock_write().unlock)
997
988
if local and not branch_to.get_bound_location():
998
989
raise errors.LocalRequiresBoundBranch()
1030
1021
branch_from = Branch.open(location,
1031
1022
possible_transports=possible_transports)
1032
branch_from.lock_read()
1033
self.add_cleanup(branch_from.unlock)
1023
self.add_cleanup(branch_from.lock_read().unlock)
1035
1025
if branch_to.get_parent() is None or remember:
1036
1026
branch_to.set_parent(branch_from.base)
1088
1078
Option('create-prefix',
1089
1079
help='Create the path leading up to the branch '
1090
1080
'if it does not already exist.'),
1081
custom_help('directory',
1092
1082
help='Branch to push from, '
1093
'rather than the one containing the working directory.',
1083
'rather than the one containing the working directory.'),
1097
1084
Option('use-existing-dir',
1098
1085
help='By default push will fail if the target'
1099
1086
' directory exists, but does not already'
1219
1206
accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
1221
1208
revision = _get_one_revision('branch', revision)
1223
self.add_cleanup(br_from.unlock)
1209
self.add_cleanup(br_from.lock_read().unlock)
1224
1210
if revision is not None:
1225
1211
revision_id = revision.as_revision_id(br_from)
1366
1352
@display_command
1367
1353
def run(self, dir=u'.'):
1368
1354
tree = WorkingTree.open_containing(dir)[0]
1370
self.add_cleanup(tree.unlock)
1355
self.add_cleanup(tree.lock_read().unlock)
1371
1356
new_inv = tree.inventory
1372
1357
old_tree = tree.basis_tree()
1373
old_tree.lock_read()
1374
self.add_cleanup(old_tree.unlock)
1358
self.add_cleanup(old_tree.lock_read().unlock)
1375
1359
old_inv = old_tree.inventory
1377
1361
iterator = tree.iter_changes(old_tree, include_unchanged=True)
1415
1399
master = branch.get_master_branch(
1416
1400
possible_transports=possible_transports)
1417
1401
if master is not None:
1419
1402
branch_location = master.base
1405
branch_location = tree.branch.base
1421
1406
tree.lock_tree_write()
1422
branch_location = tree.branch.base
1423
1407
self.add_cleanup(tree.unlock)
1424
1408
# get rid of the final '/' and be ready for display
1425
1409
branch_location = urlutils.unescape_for_display(
1545
1529
if file_list is not None:
1546
1530
file_list = [f for f in file_list]
1549
self.add_cleanup(tree.unlock)
1532
self.add_cleanup(tree.lock_write().unlock)
1550
1533
# Heuristics should probably all move into tree.remove_smart or
2003
1986
# level of effort but possibly much less IO. (Or possibly not,
2004
1987
# if the directories are very large...)
2005
1988
_see_also = ['status', 'ls']
2006
takes_options = ['show-ids']
1989
takes_options = ['directory', 'show-ids']
2008
1991
@display_command
2009
def run(self, show_ids=False):
2010
tree = WorkingTree.open_containing(u'.')[0]
2012
self.add_cleanup(tree.unlock)
1992
def run(self, show_ids=False, directory=u'.'):
1993
tree = WorkingTree.open_containing(directory)[0]
1994
self.add_cleanup(tree.lock_read().unlock)
2013
1995
old = tree.basis_tree()
2015
self.add_cleanup(old.unlock)
1996
self.add_cleanup(old.lock_read().unlock)
2016
1997
for path, ie in old.inventory.iter_entries():
2017
1998
if not tree.has_id(ie.file_id):
2018
1999
self.outf.write(path)
2030
2011
_see_also = ['status', 'ls']
2033
help='Write an ascii NUL (\\0) separator '
2034
'between files rather than a newline.')
2012
takes_options = ['directory', 'null']
2037
2014
@display_command
2038
def run(self, null=False):
2039
tree = WorkingTree.open_containing(u'.')[0]
2015
def run(self, null=False, directory=u'.'):
2016
tree = WorkingTree.open_containing(directory)[0]
2040
2017
td = tree.changes_from(tree.basis_tree())
2041
2018
for path, id, kind, text_modified, meta_modified in td.modified:
2053
2030
_see_also = ['status', 'ls']
2056
help='Write an ascii NUL (\\0) separator '
2057
'between files rather than a newline.')
2031
takes_options = ['directory', 'null']
2060
2033
@display_command
2061
def run(self, null=False):
2062
wt = WorkingTree.open_containing(u'.')[0]
2064
self.add_cleanup(wt.unlock)
2034
def run(self, null=False, directory=u'.'):
2035
wt = WorkingTree.open_containing(directory)[0]
2036
self.add_cleanup(wt.lock_read().unlock)
2065
2037
basis = wt.basis_tree()
2067
self.add_cleanup(basis.unlock)
2038
self.add_cleanup(basis.lock_read().unlock)
2068
2039
basis_inv = basis.inventory
2069
2040
inv = wt.inventory
2070
2041
for file_id in inv:
2073
2044
if inv.is_root(file_id) and len(basis_inv) == 0:
2075
2046
path = inv.id2path(file_id)
2076
if not os.access(osutils.abspath(path), os.F_OK):
2047
if not os.access(osutils.pathjoin(wt.basedir, path), os.F_OK):
2079
2050
self.outf.write(path + '\0')
2279
2250
help='Show just the specified revision.'
2280
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'),
2282
2258
Option('levels',
2283
2259
short_name='n',
2284
2260
help='Number of levels to display - 0 for all, 1 for flat.',
2353
2330
# find the file ids to log and check for directory filtering
2354
2331
b, file_info_list, rev1, rev2 = _get_info_for_log_files(
2355
revision, file_list)
2356
self.add_cleanup(b.unlock)
2332
revision, file_list, self.add_cleanup)
2357
2333
for relpath, file_id, kind in file_info_list:
2358
2334
if file_id is None:
2359
2335
raise errors.BzrCommandError(
2378
2354
dir, relpath = bzrdir.BzrDir.open_containing(location)
2379
2355
b = dir.open_branch()
2381
self.add_cleanup(b.unlock)
2356
self.add_cleanup(b.lock_read().unlock)
2382
2357
rev1, rev2 = _get_revision_range(revision, b, self.name())
2384
2359
# Decide on the type of delta & diff filtering to use
2404
2379
show_timezone=timezone,
2405
2380
delta_format=get_verbosity_level(),
2407
show_advice=levels is None)
2382
show_advice=levels is None,
2383
author_list_handler=authors)
2409
2385
# Choose the algorithm for doing the logging. It's annoying
2410
2386
# having multiple code paths like this but necessary until
2508
2484
tree, relpath = WorkingTree.open_containing(filename)
2509
2485
file_id = tree.path2id(relpath)
2510
2486
b = tree.branch
2512
self.add_cleanup(b.unlock)
2487
self.add_cleanup(b.lock_read().unlock)
2513
2488
touching_revs = log.find_touching_revisions(b, file_id)
2514
2489
for revno, revision_id, what in touching_revs:
2515
2490
self.outf.write("%6d %s\n" % (revno, what))
2528
2503
help='Recurse into subdirectories.'),
2529
2504
Option('from-root',
2530
2505
help='Print paths relative to the root of the branch.'),
2531
Option('unknown', help='Print unknown files.'),
2506
Option('unknown', short_name='u',
2507
help='Print unknown files.'),
2532
2508
Option('versioned', help='Print versioned files.',
2533
2509
short_name='V'),
2534
Option('ignored', help='Print ignored files.'),
2536
help='Write an ascii NUL (\\0) separator '
2537
'between files rather than a newline.'),
2510
Option('ignored', short_name='i',
2511
help='Print ignored files.'),
2512
Option('kind', short_name='k',
2539
2513
help='List entries of a particular kind: file, directory, symlink.',
2543
2519
@display_command
2544
2520
def run(self, revision=None, verbose=False,
2545
2521
recursive=False, from_root=False,
2546
2522
unknown=False, versioned=False, ignored=False,
2547
null=False, kind=None, show_ids=False, path=None):
2523
null=False, kind=None, show_ids=False, path=None, directory=None):
2549
2525
if kind and kind not in ('file', 'directory', 'symlink'):
2550
2526
raise errors.BzrCommandError('invalid kind specified')
2562
2538
raise errors.BzrCommandError('cannot specify both --from-root'
2565
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)
2568
2544
# Calculate the prefix to use
2584
2560
view_str = views.view_display_str(view_files)
2585
2561
note("Ignoring files outside view. View is %s" % view_str)
2588
self.add_cleanup(tree.unlock)
2563
self.add_cleanup(tree.lock_read().unlock)
2589
2564
for fp, fc, fkind, fid, entry in tree.list_files(include_root=False,
2590
2565
from_dir=relpath, recursive=recursive):
2591
2566
# Apply additional masking
2640
2615
_see_also = ['ls']
2616
takes_options = ['directory']
2642
2618
@display_command
2644
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():
2645
2621
self.outf.write(osutils.quotefn(f) + '\n')
2713
2689
_see_also = ['status', 'ignored', 'patterns']
2714
2690
takes_args = ['name_pattern*']
2691
takes_options = ['directory',
2716
2692
Option('default-rules',
2717
2693
help='Display the default ignore rules that bzr uses.')
2720
def run(self, name_pattern_list=None, default_rules=None):
2696
def run(self, name_pattern_list=None, default_rules=None,
2721
2698
from bzrlib import ignores
2722
2699
if default_rules is not None:
2723
2700
# dump the default rules and exit
2734
2711
(len(name_pattern) > 1 and name_pattern[1] == ':')):
2735
2712
raise errors.BzrCommandError(
2736
2713
"NAME_PATTERN should not be an absolute path")
2737
tree, relpath = WorkingTree.open_containing(u'.')
2714
tree, relpath = WorkingTree.open_containing(directory)
2738
2715
ignores.tree_ignores_add_patterns(tree, name_pattern_list)
2739
2716
ignored = globbing.Globster(name_pattern_list)
2767
2744
encoding_type = 'replace'
2768
2745
_see_also = ['ignore', 'ls']
2746
takes_options = ['directory']
2770
2748
@display_command
2772
tree = WorkingTree.open_containing(u'.')[0]
2774
self.add_cleanup(tree.unlock)
2749
def run(self, directory=u'.'):
2750
tree = WorkingTree.open_containing(directory)[0]
2751
self.add_cleanup(tree.lock_read().unlock)
2775
2752
for path, file_class, kind, file_id, entry in tree.list_files():
2776
2753
if file_class != 'I':
2790
2767
takes_args = ['revno']
2768
takes_options = ['directory']
2792
2770
@display_command
2793
def run(self, revno):
2771
def run(self, revno, directory=u'.'):
2795
2773
revno = int(revno)
2796
2774
except ValueError:
2797
2775
raise errors.BzrCommandError("not a valid revision-number: %r"
2799
revid = WorkingTree.open_containing(u'.')[0].branch.get_rev_id(revno)
2777
revid = WorkingTree.open_containing(directory)[0].branch.get_rev_id(revno)
2800
2778
self.outf.write("%s\n" % revid)
2829
2807
================= =========================
2831
2809
takes_args = ['dest', 'branch_or_subdir?']
2810
takes_options = ['directory',
2833
2811
Option('format',
2834
2812
help="Type of file to export to.",
2844
2822
'revision in which it was changed.'),
2846
2824
def run(self, dest, branch_or_subdir=None, revision=None, format=None,
2847
root=None, filters=False, per_file_timestamps=False):
2825
root=None, filters=False, per_file_timestamps=False, directory=u'.'):
2848
2826
from bzrlib.export import export
2850
2828
if branch_or_subdir is None:
2851
tree = WorkingTree.open_containing(u'.')[0]
2829
tree = WorkingTree.open_containing(directory)[0]
2852
2830
b = tree.branch
2875
2853
_see_also = ['ls']
2854
takes_options = ['directory',
2877
2855
Option('name-from-revision', help='The path name in the old tree.'),
2878
2856
Option('filters', help='Apply content filters to display the '
2879
2857
'convenience form.'),
2885
2863
@display_command
2886
2864
def run(self, filename, revision=None, name_from_revision=False,
2865
filters=False, directory=None):
2888
2866
if revision is not None and len(revision) != 1:
2889
2867
raise errors.BzrCommandError("bzr cat --revision takes exactly"
2890
2868
" one revision specifier")
2891
2869
tree, branch, relpath = \
2892
bzrdir.BzrDir.open_containing_tree_or_branch(filename)
2894
self.add_cleanup(branch.unlock)
2870
_open_directory_or_containing_tree_or_branch(filename, directory)
2871
self.add_cleanup(branch.lock_read().unlock)
2895
2872
return self._run(tree, branch, relpath, filename, revision,
2896
2873
name_from_revision, filters)
2900
2877
if tree is None:
2901
2878
tree = b.basis_tree()
2902
2879
rev_tree = _get_one_revision_tree('cat', revision, branch=b)
2903
rev_tree.lock_read()
2904
self.add_cleanup(rev_tree.unlock)
2880
self.add_cleanup(rev_tree.lock_read().unlock)
2906
2882
old_file_id = rev_tree.path2id(relpath)
3169
3145
def get_message(commit_obj):
3170
3146
"""Callback to get commit message"""
3172
my_message = codecs.open(
3173
file, 'rt', osutils.get_user_encoding()).read()
3148
f = codecs.open(file, 'rt', osutils.get_user_encoding())
3150
my_message = f.read()
3174
3153
elif message is not None:
3175
3154
my_message = message
3381
3360
_see_also = ['info']
3382
3361
takes_args = ['nickname?']
3383
def run(self, nickname=None):
3384
branch = Branch.open_containing(u'.')[0]
3362
takes_options = ['directory']
3363
def run(self, nickname=None, directory=u'.'):
3364
branch = Branch.open_containing(directory)[0]
3385
3365
if nickname is None:
3386
3366
self.printme(branch)
3612
3592
self.additional_selftest_args['runner_class'] = SubUnitBzrRunner
3613
3593
# On Windows, disable automatic conversion of '\n' to '\r\n' in
3614
3594
# stdout, which would corrupt the subunit stream.
3615
if sys.platform == "win32" and sys.stdout.fileno() >= 0:
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):
3617
3601
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
3691
3675
branch1 = Branch.open_containing(branch)[0]
3692
3676
branch2 = Branch.open_containing(other)[0]
3694
self.add_cleanup(branch1.unlock)
3696
self.add_cleanup(branch2.unlock)
3677
self.add_cleanup(branch1.lock_read().unlock)
3678
self.add_cleanup(branch2.lock_read().unlock)
3697
3679
last1 = ensure_null(branch1.last_revision())
3698
3680
last2 = ensure_null(branch2.last_revision())
3793
3775
' completely merged into the source, pull from the'
3794
3776
' source rather than merging. When this happens,'
3795
3777
' you do not need to commit the result.'),
3778
custom_help('directory',
3797
3779
help='Branch to merge into, '
3798
'rather than the one containing the working directory.',
3780
'rather than the one containing the working directory.'),
3802
3781
Option('preview', help='Instead of merging, show a diff of the'
3804
3783
Option('interactive', help='Select changes interactively.',
3837
3816
unversioned_filter=tree.is_ignored, view_info=view_info)
3838
3817
pb = ui.ui_factory.nested_progress_bar()
3839
3818
self.add_cleanup(pb.finished)
3841
self.add_cleanup(tree.unlock)
3819
self.add_cleanup(tree.lock_write().unlock)
3842
3820
if location is not None:
3844
3822
mergeable = bundle.read_mergeable_from_url(location,
4100
4078
if merge_type is None:
4101
4079
merge_type = _mod_merge.Merge3Merger
4102
4080
tree, file_list = tree_files(file_list)
4104
self.add_cleanup(tree.unlock)
4081
self.add_cleanup(tree.lock_write().unlock)
4105
4082
parents = tree.get_parent_ids()
4106
4083
if len(parents) != 2:
4107
4084
raise errors.BzrCommandError("Sorry, remerge only works after normal"
4217
4194
def run(self, revision=None, no_backup=False, file_list=None,
4218
4195
forget_merges=None):
4219
4196
tree, file_list = tree_files(file_list)
4220
tree.lock_tree_write()
4221
self.add_cleanup(tree.unlock)
4197
self.add_cleanup(tree.lock_tree_write().unlock)
4222
4198
if forget_merges:
4223
4199
tree.set_parent_ids(tree.get_parent_ids()[:1])
4313
4289
_see_also = ['merge', 'pull']
4314
4290
takes_args = ['other_branch?']
4315
4291
takes_options = [
4316
4293
Option('reverse', 'Reverse the order of revisions.'),
4317
4294
Option('mine-only',
4318
4295
'Display changes in the local branch only.'),
4340
4317
theirs_only=False,
4341
4318
log_format=None, long=False, short=False, line=False,
4342
4319
show_ids=False, verbose=False, this=False, other=False,
4343
include_merges=False, revision=None, my_revision=None):
4320
include_merges=False, revision=None, my_revision=None,
4344
4322
from bzrlib.missing import find_unmerged, iter_log_revisions
4345
4323
def message(s):
4346
4324
if not is_quiet():
4359
4337
elif theirs_only:
4360
4338
restrict = 'remote'
4362
local_branch = Branch.open_containing(u".")[0]
4363
local_branch.lock_read()
4364
self.add_cleanup(local_branch.unlock)
4340
local_branch = Branch.open_containing(directory)[0]
4341
self.add_cleanup(local_branch.lock_read().unlock)
4366
4343
parent = local_branch.get_parent()
4367
4344
if other_branch is None:
4378
4355
if remote_branch.base == local_branch.base:
4379
4356
remote_branch = local_branch
4381
remote_branch.lock_read()
4382
self.add_cleanup(remote_branch.unlock)
4358
self.add_cleanup(remote_branch.lock_read().unlock)
4384
4360
local_revid_range = _revision_range_to_revid_range(
4385
4361
_get_revision_range(my_revision, local_branch,
4440
4416
message("Branches are up to date.\n")
4441
4417
self.cleanup_now()
4442
4418
if not status_code and parent is None and other_branch is not None:
4443
local_branch.lock_write()
4444
self.add_cleanup(local_branch.unlock)
4419
self.add_cleanup(local_branch.lock_write().unlock)
4445
4420
# handle race conditions - a parent might be set while we run.
4446
4421
if local_branch.get_parent() is None:
4447
4422
local_branch.set_parent(remote_branch.base)
4578
4552
Option('long', help='Show commit date in annotations.'),
4582
4557
encoding_type = 'exact'
4584
4559
@display_command
4585
4560
def run(self, filename, all=False, long=False, revision=None,
4561
show_ids=False, directory=None):
4587
4562
from bzrlib.annotate import annotate_file, annotate_file_tree
4588
4563
wt, branch, relpath = \
4589
bzrdir.BzrDir.open_containing_tree_or_branch(filename)
4564
_open_directory_or_containing_tree_or_branch(filename, directory)
4590
4565
if wt is not None:
4592
self.add_cleanup(wt.unlock)
4566
self.add_cleanup(wt.lock_read().unlock)
4595
self.add_cleanup(branch.unlock)
4568
self.add_cleanup(branch.lock_read().unlock)
4596
4569
tree = _get_one_revision_tree('annotate', revision, branch=branch)
4598
self.add_cleanup(tree.unlock)
4570
self.add_cleanup(tree.lock_read().unlock)
4599
4571
if wt is not None:
4600
4572
file_id = wt.path2id(relpath)
4620
4592
hidden = True # is this right ?
4621
4593
takes_args = ['revision_id*']
4622
takes_options = ['revision']
4594
takes_options = ['directory', 'revision']
4624
def run(self, revision_id_list=None, revision=None):
4596
def run(self, revision_id_list=None, revision=None, directory=u'.'):
4625
4597
if revision_id_list is not None and revision is not None:
4626
4598
raise errors.BzrCommandError('You can only supply one of revision_id or --revision')
4627
4599
if revision_id_list is None and revision is None:
4628
4600
raise errors.BzrCommandError('You must supply either --revision or a revision_id')
4629
b = WorkingTree.open_containing(u'.')[0].branch
4631
self.add_cleanup(b.unlock)
4601
b = WorkingTree.open_containing(directory)[0].branch
4602
self.add_cleanup(b.lock_write().unlock)
4632
4603
return self._run(b, revision_id_list, revision)
4634
4605
def _run(self, b, revision_id_list, revision):
4694
4665
_see_also = ['checkouts', 'unbind']
4695
4666
takes_args = ['location?']
4667
takes_options = ['directory']
4698
def run(self, location=None):
4699
b, relpath = Branch.open_containing(u'.')
4669
def run(self, location=None, directory=u'.'):
4670
b, relpath = Branch.open_containing(directory)
4700
4671
if location is None:
4702
4673
location = b.get_old_bound_location()
4730
4701
_see_also = ['checkouts', 'bind']
4731
4702
takes_args = []
4703
takes_options = ['directory']
4735
b, relpath = Branch.open_containing(u'.')
4705
def run(self, directory=u'.'):
4706
b, relpath = Branch.open_containing(directory)
4736
4707
if not b.unbind():
4737
4708
raise errors.BzrCommandError('Local branch is not bound')
4784
4755
b = control.open_branch()
4786
4757
if tree is not None:
4788
self.add_cleanup(tree.unlock)
4758
self.add_cleanup(tree.lock_write().unlock)
4791
self.add_cleanup(b.unlock)
4760
self.add_cleanup(b.lock_write().unlock)
4792
4761
return self._run(b, tree, dry_run, verbose, revision, force, local=local)
4794
4763
def _run(self, b, tree, dry_run, verbose, revision, force, local=False):
4902
4871
'result in a dynamically allocated port. The default port '
4903
4872
'depends on the protocol.',
4906
help='Serve contents of this directory.',
4874
custom_help('directory',
4875
help='Serve contents of this directory.'),
4908
4876
Option('allow-writes',
4909
4877
help='By default the server is a readonly server. Supplying '
4910
4878
'--allow-writes enables write access to the contents of '
5064
5033
encoding_type = 'exact'
5066
5035
def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
5067
sign=False, revision=None, mail_to=None, message=None):
5036
sign=False, revision=None, mail_to=None, message=None,
5068
5038
from bzrlib.revision import ensure_null, NULL_REVISION
5069
5039
include_patch, include_bundle = {
5070
5040
'plain': (False, False),
5071
5041
'diff': (True, False),
5072
5042
'bundle': (True, True),
5074
branch = Branch.open('.')
5044
branch = Branch.open(directory)
5075
5045
stored_submit_branch = branch.get_submit_branch()
5076
5046
if submit_branch is None:
5077
5047
submit_branch = stored_submit_branch
5339
5309
Option('delete',
5340
5310
help='Delete this tag rather than placing it.',
5343
help='Branch in which to place the tag.',
5312
custom_help('directory',
5313
help='Branch in which to place the tag.'),
5347
5314
Option('force',
5348
5315
help='Replace existing tags.',
5359
5326
branch, relpath = Branch.open_containing(directory)
5361
self.add_cleanup(branch.unlock)
5327
self.add_cleanup(branch.lock_write().unlock)
5363
5329
if tag_name is None:
5364
5330
raise errors.BzrCommandError("No tag specified to delete.")
5393
5359
_see_also = ['tag']
5394
5360
takes_options = [
5396
help='Branch whose tags should be displayed.',
5361
custom_help('directory',
5362
help='Branch whose tags should be displayed.'),
5400
5363
RegistryOption.from_kwargs('sort',
5401
5364
'Sort tags by different criteria.', title='Sorting',
5402
5365
alpha='Sort tags lexicographically (default).',
5423
self.add_cleanup(branch.unlock)
5385
self.add_cleanup(branch.lock_read().unlock)
5425
5387
graph = branch.repository.get_graph()
5426
5388
rev1, rev2 = _get_revision_range(revision, branch, self.name())
5575
5537
takes_args = ['to_location?']
5576
takes_options = [Option('force',
5538
takes_options = ['directory',
5577
5540
help='Switch even if local commits will be lost.'),
5579
5542
Option('create-branch', short_name='b',
5584
5547
def run(self, to_location=None, force=False, create_branch=False,
5548
revision=None, directory=u'.'):
5586
5549
from bzrlib import switch
5550
tree_location = directory
5588
5551
revision = _get_one_revision('switch', revision)
5589
5552
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5590
5553
if to_location is None:
5591
5554
if revision is None:
5592
5555
raise errors.BzrCommandError('You must supply either a'
5593
5556
' revision or a location')
5557
to_location = tree_location
5596
5559
branch = control_dir.open_branch()
5597
5560
had_explicit_nick = branch.get_config().has_explicit_nickname()
5886
5850
_see_also = ['unshelve']
5888
5852
def run(self, revision=None, all=False, file_list=None, message=None,
5889
writer=None, list=False, destroy=False):
5853
writer=None, list=False, destroy=False, directory=u'.'):
5891
5855
return self.run_for_list()
5892
5856
from bzrlib.shelf_ui import Shelver
5894
5858
writer = bzrlib.option.diff_writer_registry.get()
5896
5860
shelver = Shelver.from_args(writer(sys.stdout), revision, all,
5897
file_list, message, destroy=destroy)
5861
file_list, message, destroy=destroy, directory=directory)
5905
5869
def run_for_list(self):
5906
5870
tree = WorkingTree.open_containing('.')[0]
5908
self.add_cleanup(tree.unlock)
5871
self.add_cleanup(tree.lock_read().unlock)
5909
5872
manager = tree.get_shelf_manager()
5910
5873
shelves = manager.active_shelves()
5911
5874
if len(shelves) == 0:
5930
5893
takes_args = ['shelf_id?']
5931
5894
takes_options = [
5932
5896
RegistryOption.from_kwargs(
5933
5897
'action', help="The action to perform.",
5934
5898
enum_switch=False, value_switches=True,
5943
5907
_see_also = ['shelve']
5945
def run(self, shelf_id=None, action='apply'):
5909
def run(self, shelf_id=None, action='apply', directory=u'.'):
5946
5910
from bzrlib.shelf_ui import Unshelver
5947
unshelver = Unshelver.from_args(shelf_id, action)
5911
unshelver = Unshelver.from_args(shelf_id, action, directory=directory)
5949
5913
unshelver.run()
5967
5931
To check what clean-tree will do, use --dry-run.
5969
takes_options = [Option('ignored', help='Delete all ignored files.'),
5933
takes_options = ['directory',
5934
Option('ignored', help='Delete all ignored files.'),
5970
5935
Option('detritus', help='Delete conflict files, merge'
5971
5936
' backups, and failed selftest dirs.'),
5972
5937
Option('unknown',
5975
5940
' deleting them.'),
5976
5941
Option('force', help='Do not prompt before deleting.')]
5977
5942
def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
5943
force=False, directory=u'.'):
5979
5944
from bzrlib.clean_tree import clean_tree
5980
5945
if not (unknown or ignored or detritus):
5984
clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus,
5985
dry_run=dry_run, no_prompt=force)
5949
clean_tree(directory, unknown=unknown, ignored=ignored,
5950
detritus=detritus, dry_run=dry_run, no_prompt=force)
5988
5953
class cmd_reference(Command):