75
74
from bzrlib.trace import mutter, note, warning, is_quiet, get_verbosity_level
77
@symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
78
78
def tree_files(file_list, default_branch=u'.', canonicalize=True,
81
return internal_tree_files(file_list, default_branch, canonicalize,
83
except errors.FileInWrongBranch, e:
84
raise errors.BzrCommandError("%s is not in the same branch as %s" %
85
(e.path, file_list[0]))
80
return internal_tree_files(file_list, default_branch, canonicalize,
88
84
def tree_files_for_add(file_list):
153
149
# XXX: Bad function name; should possibly also be a class method of
154
150
# WorkingTree rather than a function.
151
@symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
155
152
def internal_tree_files(file_list, default_branch=u'.', canonicalize=True,
156
153
apply_view=True):
157
154
"""Convert command-line paths to a WorkingTree and relative paths.
156
Deprecated: use WorkingTree.open_containing_paths instead.
159
158
This is typically used for command-line processors that take one or
160
159
more filenames, and infer the workingtree that contains them.
172
171
:return: workingtree, [relative_paths]
174
if file_list is None or len(file_list) == 0:
175
tree = WorkingTree.open_containing(default_branch)[0]
176
if tree.supports_views() and apply_view:
177
view_files = tree.views.lookup_view()
179
file_list = view_files
180
view_str = views.view_display_str(view_files)
181
note("Ignoring files outside view. View is %s" % view_str)
182
return tree, file_list
183
tree = WorkingTree.open_containing(osutils.realpath(file_list[0]))[0]
184
return tree, safe_relpath_files(tree, file_list, canonicalize,
185
apply_view=apply_view)
188
def safe_relpath_files(tree, file_list, canonicalize=True, apply_view=True):
189
"""Convert file_list into a list of relpaths in tree.
191
:param tree: A tree to operate on.
192
:param file_list: A list of user provided paths or None.
193
:param apply_view: if True and a view is set, apply it or check that
194
specified files are within it
195
:return: A list of relative paths.
196
:raises errors.PathNotChild: When a provided path is in a different tree
199
if file_list is None:
201
if tree.supports_views() and apply_view:
202
view_files = tree.views.lookup_view()
206
# tree.relpath exists as a "thunk" to osutils, but canonical_relpath
207
# doesn't - fix that up here before we enter the loop.
209
fixer = lambda p: osutils.canonical_relpath(tree.basedir, p)
212
for filename in file_list:
214
relpath = fixer(osutils.dereference_path(filename))
215
if view_files and not osutils.is_inside_any(view_files, relpath):
216
raise errors.FileOutsideView(filename, view_files)
217
new_list.append(relpath)
218
except errors.PathNotChild:
219
raise errors.FileInWrongBranch(tree.branch, filename)
173
return WorkingTree.open_containing_paths(
174
file_list, default_directory='.',
223
179
def _get_view_info_for_change_reporter(tree):
191
def _open_directory_or_containing_tree_or_branch(filename, directory):
192
"""Open the tree or branch containing the specified file, unless
193
the --directory option is used to specify a different branch."""
194
if directory is not None:
195
return (None, Branch.open(directory), filename)
196
return bzrdir.BzrDir.open_containing_tree_or_branch(filename)
235
199
# TODO: Make sure no commands unconditionally use the working directory as a
236
200
# branch. If a filename argument is used, the first of them should be used to
237
201
# specify the branch. (Perhaps this can be factored out into some kind of
315
279
raise errors.BzrCommandError('bzr status --revision takes exactly'
316
280
' one or two revision specifiers')
318
tree, relfile_list = tree_files(file_list)
282
tree, relfile_list = WorkingTree.open_containing_paths(file_list)
319
283
# Avoid asking for specific files when that is not needed.
320
284
if relfile_list == ['']:
321
285
relfile_list = None
353
317
self.outf.write(revtext.decode('utf-8'))
356
def run(self, revision_id=None, revision=None):
320
def run(self, revision_id=None, revision=None, directory=u'.'):
357
321
if revision_id is not None and revision is not None:
358
322
raise errors.BzrCommandError('You can only supply one of'
359
323
' revision_id or --revision')
360
324
if revision_id is None and revision is None:
361
325
raise errors.BzrCommandError('You must supply either'
362
326
' --revision or a revision_id')
363
b = WorkingTree.open_containing(u'.')[0].branch
327
b = WorkingTree.open_containing(directory)[0].branch
365
329
revisions = b.repository.revisions
366
330
if revisions is None:
504
468
if (working.has_changes()):
505
469
raise errors.UncommittedChanges(working)
470
if working.get_shelf_manager().last_shelf() is not None:
471
raise errors.ShelvedChanges(working)
507
473
if working.user_url != working.branch.user_url:
508
474
raise errors.BzrCommandError("You cannot remove the working tree"
552
518
takes_args = ['revision_info*']
553
519
takes_options = [
521
custom_help('directory',
556
522
help='Branch to examine, '
557
'rather than the one containing the working directory.',
523
'rather than the one containing the working directory.'),
561
524
Option('tree', help='Show revno of working tree'),
754
717
raise errors.BzrCommandError('invalid kind %r specified' % (kind,))
756
719
revision = _get_one_revision('inventory', revision)
757
work_tree, file_list = tree_files(file_list)
720
work_tree, file_list = WorkingTree.open_containing_paths(file_list)
758
721
self.add_cleanup(work_tree.lock_read().unlock)
759
722
if revision is not None:
760
723
tree = revision.as_tree(work_tree.branch)
826
789
if len(names_list) < 2:
827
790
raise errors.BzrCommandError("missing file argument")
828
tree, rel_names = tree_files(names_list, canonicalize=False)
791
tree, rel_names = WorkingTree.open_containing_paths(names_list, canonicalize=False)
829
792
self.add_cleanup(tree.lock_tree_write().unlock)
830
793
self._run(tree, names_list, rel_names, after)
837
800
raise errors.BzrCommandError('--after cannot be specified with'
839
work_tree, file_list = tree_files(names_list, default_branch='.')
802
work_tree, file_list = WorkingTree.open_containing_paths(
803
names_list, default_directory='.')
840
804
self.add_cleanup(work_tree.lock_tree_write().unlock)
841
805
rename_map.RenameMap.guess_renames(work_tree, dry_run)
951
915
takes_options = ['remember', 'overwrite', 'revision',
952
916
custom_help('verbose',
953
917
help='Show logs of pulled revisions.'),
918
custom_help('directory',
955
919
help='Branch to pull into, '
956
'rather than the one containing the working directory.',
920
'rather than the one containing the working directory.'),
961
922
help="Perform a local pull in a bound "
962
923
"branch. Local pulls are not applied to "
1076
1037
Option('create-prefix',
1077
1038
help='Create the path leading up to the branch '
1078
1039
'if it does not already exist.'),
1040
custom_help('directory',
1080
1041
help='Branch to push from, '
1081
'rather than the one containing the working directory.',
1042
'rather than the one containing the working directory.'),
1085
1043
Option('use-existing-dir',
1086
1044
help='By default push will fail if the target'
1087
1045
' directory exists, but does not already'
1177
1135
_see_also = ['checkout']
1178
1136
takes_args = ['from_location', 'to_location?']
1179
takes_options = ['revision', Option('hardlink',
1180
help='Hard-link working tree files where possible.'),
1137
takes_options = ['revision',
1138
Option('hardlink', help='Hard-link working tree files where possible.'),
1139
Option('files-from', type=str,
1140
help="Get file contents from this tree."),
1181
1141
Option('no-tree',
1182
1142
help="Create a branch without a working-tree."),
1183
1143
Option('switch',
1202
1162
def run(self, from_location, to_location=None, revision=None,
1203
1163
hardlink=False, stacked=False, standalone=False, no_tree=False,
1204
use_existing_dir=False, switch=False, bind=False):
1164
use_existing_dir=False, switch=False, bind=False,
1205
1166
from bzrlib import switch as _mod_switch
1206
1167
from bzrlib.tag import _merge_tags_if_possible
1207
1168
accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
1170
if not (hardlink or files_from):
1171
# accelerator_tree is usually slower because you have to read N
1172
# files (no readahead, lots of seeks, etc), but allow the user to
1173
# explicitly request it
1174
accelerator_tree = None
1175
if files_from is not None and files_from != from_location:
1176
accelerator_tree = WorkingTree.open(files_from)
1209
1177
revision = _get_one_revision('branch', revision)
1210
1178
self.add_cleanup(br_from.lock_read().unlock)
1211
1179
if revision is not None:
1318
1286
to_location = branch_location
1319
1287
accelerator_tree, source = bzrdir.BzrDir.open_tree_or_branch(
1320
1288
branch_location)
1289
if not (hardlink or files_from):
1290
# accelerator_tree is usually slower because you have to read N
1291
# files (no readahead, lots of seeks, etc), but allow the user to
1292
# explicitly request it
1293
accelerator_tree = None
1321
1294
revision = _get_one_revision('checkout', revision)
1322
if files_from is not None:
1295
if files_from is not None and files_from != branch_location:
1323
1296
accelerator_tree = WorkingTree.open(files_from)
1324
1297
if revision is not None:
1325
1298
revision_id = revision.as_revision_id(source)
1526
1499
def run(self, file_list, verbose=False, new=False,
1527
1500
file_deletion_strategy='safe'):
1528
tree, file_list = tree_files(file_list)
1501
tree, file_list = WorkingTree.open_containing_paths(file_list)
1530
1503
if file_list is not None:
1531
1504
file_list = [f for f in file_list]
1910
1883
takes_args = ['file*']
1911
1884
takes_options = [
1912
1885
Option('diff-options', type=str,
1913
help='Pass these options to the external diff program.'),
1886
help='Pass these options to the diff program.'),
1914
1887
Option('prefix', type=str,
1915
1888
short_name='p',
1916
1889
help='Set prefixes added to old and new filenames, as '
1957
1930
'--prefix expects two values separated by a colon'
1958
1931
' (eg "old/:new/")')
1933
if using is not None and diff_options is not None:
1934
raise errors.BzrCommandError(
1935
'--diff-options and --using are mutually exclusive.')
1960
1937
if revision and len(revision) > 2:
1961
1938
raise errors.BzrCommandError('bzr diff --revision takes exactly'
1962
1939
' one or two revision specifiers')
1969
1946
old_branch, new_branch,
1970
1947
specific_files, extra_trees) = get_trees_and_branches_to_diff_locked(
1971
1948
file_list, revision, old, new, self.add_cleanup, apply_view=True)
1949
# GNU diff on Windows uses ANSI encoding for filenames
1950
path_encoding = osutils.get_diff_header_encoding()
1972
1951
return show_diff_trees(old_tree, new_tree, sys.stdout,
1973
1952
specific_files=specific_files,
1974
1953
external_diff_options=diff_options,
1975
1954
old_label=old_label, new_label=new_label,
1976
extra_trees=extra_trees, using=using,
1955
extra_trees=extra_trees,
1956
path_encoding=path_encoding,
1977
1958
format_cls=format)
1987
1968
# level of effort but possibly much less IO. (Or possibly not,
1988
1969
# if the directories are very large...)
1989
1970
_see_also = ['status', 'ls']
1990
takes_options = ['show-ids']
1971
takes_options = ['directory', 'show-ids']
1992
1973
@display_command
1993
def run(self, show_ids=False):
1994
tree = WorkingTree.open_containing(u'.')[0]
1974
def run(self, show_ids=False, directory=u'.'):
1975
tree = WorkingTree.open_containing(directory)[0]
1995
1976
self.add_cleanup(tree.lock_read().unlock)
1996
1977
old = tree.basis_tree()
1997
1978
self.add_cleanup(old.lock_read().unlock)
2012
1993
_see_also = ['status', 'ls']
2015
help='Write an ascii NUL (\\0) separator '
2016
'between files rather than a newline.')
1994
takes_options = ['directory', 'null']
2019
1996
@display_command
2020
def run(self, null=False):
2021
tree = WorkingTree.open_containing(u'.')[0]
1997
def run(self, null=False, directory=u'.'):
1998
tree = WorkingTree.open_containing(directory)[0]
2022
1999
td = tree.changes_from(tree.basis_tree())
2023
2000
for path, id, kind, text_modified, meta_modified in td.modified:
2035
2012
_see_also = ['status', 'ls']
2038
help='Write an ascii NUL (\\0) separator '
2039
'between files rather than a newline.')
2013
takes_options = ['directory', 'null']
2042
2015
@display_command
2043
def run(self, null=False):
2044
wt = WorkingTree.open_containing(u'.')[0]
2016
def run(self, null=False, directory=u'.'):
2017
wt = WorkingTree.open_containing(directory)[0]
2045
2018
self.add_cleanup(wt.lock_read().unlock)
2046
2019
basis = wt.basis_tree()
2047
2020
self.add_cleanup(basis.lock_read().unlock)
2053
2026
if inv.is_root(file_id) and len(basis_inv) == 0:
2055
2028
path = inv.id2path(file_id)
2056
if not os.access(osutils.abspath(path), os.F_OK):
2029
if not os.access(osutils.pathjoin(wt.basedir, path), os.F_OK):
2059
2032
self.outf.write(path + '\0')
2259
2232
help='Show just the specified revision.'
2260
2233
' See also "help revisionspec".'),
2235
RegistryOption('authors',
2236
'What names to list as authors - first, all or committer.',
2238
lazy_registry=('bzrlib.log', 'author_list_registry'),
2262
2240
Option('levels',
2263
2241
short_name='n',
2264
2242
help='Number of levels to display - 0 for all, 1 for flat.',
2382
2361
show_timezone=timezone,
2383
2362
delta_format=get_verbosity_level(),
2385
show_advice=levels is None)
2364
show_advice=levels is None,
2365
author_list_handler=authors)
2387
2367
# Choose the algorithm for doing the logging. It's annoying
2388
2368
# having multiple code paths like this but necessary until
2505
2485
help='Recurse into subdirectories.'),
2506
2486
Option('from-root',
2507
2487
help='Print paths relative to the root of the branch.'),
2508
Option('unknown', help='Print unknown files.'),
2488
Option('unknown', short_name='u',
2489
help='Print unknown files.'),
2509
2490
Option('versioned', help='Print versioned files.',
2510
2491
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.'),
2492
Option('ignored', short_name='i',
2493
help='Print ignored files.'),
2494
Option('kind', short_name='k',
2516
2495
help='List entries of a particular kind: file, directory, symlink.',
2520
2501
@display_command
2521
2502
def run(self, revision=None, verbose=False,
2522
2503
recursive=False, from_root=False,
2523
2504
unknown=False, versioned=False, ignored=False,
2524
null=False, kind=None, show_ids=False, path=None):
2505
null=False, kind=None, show_ids=False, path=None, directory=None):
2526
2507
if kind and kind not in ('file', 'directory', 'symlink'):
2527
2508
raise errors.BzrCommandError('invalid kind specified')
2539
2520
raise errors.BzrCommandError('cannot specify both --from-root'
2542
tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
2523
tree, branch, relpath = \
2524
_open_directory_or_containing_tree_or_branch(fs_path, directory)
2545
2526
# Calculate the prefix to use
2616
2597
_see_also = ['ls']
2598
takes_options = ['directory']
2618
2600
@display_command
2620
for f in WorkingTree.open_containing(u'.')[0].unknowns():
2601
def run(self, directory=u'.'):
2602
for f in WorkingTree.open_containing(directory)[0].unknowns():
2621
2603
self.outf.write(osutils.quotefn(f) + '\n')
2689
2671
_see_also = ['status', 'ignored', 'patterns']
2690
2672
takes_args = ['name_pattern*']
2673
takes_options = ['directory',
2692
2674
Option('default-rules',
2693
2675
help='Display the default ignore rules that bzr uses.')
2696
def run(self, name_pattern_list=None, default_rules=None):
2678
def run(self, name_pattern_list=None, default_rules=None,
2697
2680
from bzrlib import ignores
2698
2681
if default_rules is not None:
2699
2682
# dump the default rules and exit
2705
2688
"NAME_PATTERN or --default-rules.")
2706
2689
name_pattern_list = [globbing.normalize_pattern(p)
2707
2690
for p in name_pattern_list]
2692
for p in name_pattern_list:
2693
if not globbing.Globster.is_pattern_valid(p):
2694
bad_patterns += ('\n %s' % p)
2696
msg = ('Invalid ignore pattern(s) found. %s' % bad_patterns)
2697
ui.ui_factory.show_error(msg)
2698
raise errors.InvalidPattern('')
2708
2699
for name_pattern in name_pattern_list:
2709
2700
if (name_pattern[0] == '/' or
2710
2701
(len(name_pattern) > 1 and name_pattern[1] == ':')):
2711
2702
raise errors.BzrCommandError(
2712
2703
"NAME_PATTERN should not be an absolute path")
2713
tree, relpath = WorkingTree.open_containing(u'.')
2704
tree, relpath = WorkingTree.open_containing(directory)
2714
2705
ignores.tree_ignores_add_patterns(tree, name_pattern_list)
2715
2706
ignored = globbing.Globster(name_pattern_list)
2708
self.add_cleanup(tree.lock_read().unlock)
2718
2709
for entry in tree.list_files():
2720
2711
if id is not None:
2721
2712
filename = entry[0]
2722
2713
if ignored.match(filename):
2723
2714
matches.append(filename)
2725
2715
if len(matches) > 0:
2726
2716
self.outf.write("Warning: the following files are version controlled and"
2727
2717
" match your ignore pattern:\n%s"
2743
2733
encoding_type = 'replace'
2744
2734
_see_also = ['ignore', 'ls']
2735
takes_options = ['directory']
2746
2737
@display_command
2748
tree = WorkingTree.open_containing(u'.')[0]
2738
def run(self, directory=u'.'):
2739
tree = WorkingTree.open_containing(directory)[0]
2749
2740
self.add_cleanup(tree.lock_read().unlock)
2750
2741
for path, file_class, kind, file_id, entry in tree.list_files():
2751
2742
if file_class != 'I':
2765
2756
takes_args = ['revno']
2757
takes_options = ['directory']
2767
2759
@display_command
2768
def run(self, revno):
2760
def run(self, revno, directory=u'.'):
2770
2762
revno = int(revno)
2771
2763
except ValueError:
2772
2764
raise errors.BzrCommandError("not a valid revision-number: %r"
2774
revid = WorkingTree.open_containing(u'.')[0].branch.get_rev_id(revno)
2766
revid = WorkingTree.open_containing(directory)[0].branch.get_rev_id(revno)
2775
2767
self.outf.write("%s\n" % revid)
2804
2796
================= =========================
2806
2798
takes_args = ['dest', 'branch_or_subdir?']
2799
takes_options = ['directory',
2808
2800
Option('format',
2809
2801
help="Type of file to export to.",
2819
2811
'revision in which it was changed.'),
2821
2813
def run(self, dest, branch_or_subdir=None, revision=None, format=None,
2822
root=None, filters=False, per_file_timestamps=False):
2814
root=None, filters=False, per_file_timestamps=False, directory=u'.'):
2823
2815
from bzrlib.export import export
2825
2817
if branch_or_subdir is None:
2826
tree = WorkingTree.open_containing(u'.')[0]
2818
tree = WorkingTree.open_containing(directory)[0]
2827
2819
b = tree.branch
2850
2842
_see_also = ['ls']
2843
takes_options = ['directory',
2852
2844
Option('name-from-revision', help='The path name in the old tree.'),
2853
2845
Option('filters', help='Apply content filters to display the '
2854
2846
'convenience form.'),
2860
2852
@display_command
2861
2853
def run(self, filename, revision=None, name_from_revision=False,
2854
filters=False, directory=None):
2863
2855
if revision is not None and len(revision) != 1:
2864
2856
raise errors.BzrCommandError("bzr cat --revision takes exactly"
2865
2857
" one revision specifier")
2866
2858
tree, branch, relpath = \
2867
bzrdir.BzrDir.open_containing_tree_or_branch(filename)
2859
_open_directory_or_containing_tree_or_branch(filename, directory)
2868
2860
self.add_cleanup(branch.lock_read().unlock)
2869
2861
return self._run(tree, branch, relpath, filename, revision,
2870
2862
name_from_revision, filters)
3102
3094
properties = {}
3104
tree, selected_list = tree_files(selected_list)
3096
tree, selected_list = WorkingTree.open_containing_paths(selected_list)
3105
3097
if selected_list == ['']:
3106
3098
# workaround - commit of root of tree should be exactly the same
3107
3099
# as just default commit in that tree, and succeed even though
3142
3134
def get_message(commit_obj):
3143
3135
"""Callback to get commit message"""
3145
my_message = codecs.open(
3146
file, 'rt', osutils.get_user_encoding()).read()
3139
my_message = f.read().decode(osutils.get_user_encoding())
3147
3142
elif message is not None:
3148
3143
my_message = message
3178
3173
reporter=None, verbose=verbose, revprops=properties,
3179
3174
authors=author, timestamp=commit_stamp,
3180
3175
timezone=offset,
3181
exclude=safe_relpath_files(tree, exclude))
3176
exclude=tree.safe_relpath_files(exclude))
3182
3177
except PointlessCommit:
3183
3178
raise errors.BzrCommandError("No changes to commit."
3184
3179
" Use --unchanged to commit anyhow.")
3304
3299
bzr whoami "Frank Chu <fchu@example.com>"
3306
takes_options = [ Option('email',
3301
takes_options = [ 'directory',
3307
3303
help='Display email address only.'),
3308
3304
Option('branch',
3309
3305
help='Set identity for the current branch instead of '
3313
3309
encoding_type = 'replace'
3315
3311
@display_command
3316
def run(self, email=False, branch=False, name=None):
3312
def run(self, email=False, branch=False, name=None, directory=None):
3317
3313
if name is None:
3318
# use branch if we're inside one; otherwise global config
3320
c = Branch.open_containing('.')[0].get_config()
3321
except errors.NotBranchError:
3322
c = config.GlobalConfig()
3314
if directory is None:
3315
# use branch if we're inside one; otherwise global config
3317
c = Branch.open_containing(u'.')[0].get_config()
3318
except errors.NotBranchError:
3319
c = config.GlobalConfig()
3321
c = Branch.open(directory).get_config()
3324
3323
self.outf.write(c.user_email() + '\n')
3336
3335
# use global config unless --branch given
3338
c = Branch.open_containing('.')[0].get_config()
3337
if directory is None:
3338
c = Branch.open_containing(u'.')[0].get_config()
3340
c = Branch.open(directory).get_config()
3340
3342
c = config.GlobalConfig()
3341
3343
c.set_user_option('email', name)
3354
3356
_see_also = ['info']
3355
3357
takes_args = ['nickname?']
3356
def run(self, nickname=None):
3357
branch = Branch.open_containing(u'.')[0]
3358
takes_options = ['directory']
3359
def run(self, nickname=None, directory=u'.'):
3360
branch = Branch.open_containing(directory)[0]
3358
3361
if nickname is None:
3359
3362
self.printme(branch)
3510
3513
'throughout the test suite.',
3511
3514
type=get_transport_type),
3512
3515
Option('benchmark',
3513
help='Run the benchmarks rather than selftests.'),
3516
help='Run the benchmarks rather than selftests.',
3514
3518
Option('lsprof-timed',
3515
3519
help='Generate lsprof output for benchmarked'
3516
3520
' sections of code.'),
3517
3521
Option('lsprof-tests',
3518
3522
help='Generate lsprof output for each test.'),
3519
Option('cache-dir', type=str,
3520
help='Cache intermediate benchmark output in this '
3522
3523
Option('first',
3523
3524
help='Run all tests, but run specified tests first.',
3524
3525
short_name='f',
3559
3560
def run(self, testspecs_list=None, verbose=False, one=False,
3560
3561
transport=None, benchmark=None,
3561
lsprof_timed=None, cache_dir=None,
3562
3563
first=False, list_only=False,
3563
3564
randomize=None, exclude=None, strict=False,
3564
3565
load_list=None, debugflag=None, starting_with=None, subunit=False,
3565
3566
parallel=None, lsprof_tests=False):
3566
3567
from bzrlib.tests import selftest
3567
import bzrlib.benchmarks as benchmarks
3568
from bzrlib.benchmarks import tree_creator
3570
3569
# Make deprecation warnings visible, unless -Werror is set
3571
3570
symbol_versioning.activate_deprecation_warnings(override=False)
3573
if cache_dir is not None:
3574
tree_creator.TreeCreator.CACHE_ROOT = osutils.abspath(cache_dir)
3575
3572
if testspecs_list is not None:
3576
3573
pattern = '|'.join(testspecs_list)
3585
3582
self.additional_selftest_args['runner_class'] = SubUnitBzrRunner
3586
3583
# On Windows, disable automatic conversion of '\n' to '\r\n' in
3587
3584
# stdout, which would corrupt the subunit stream.
3588
if sys.platform == "win32" and sys.stdout.fileno() >= 0:
3585
# FIXME: This has been fixed in subunit trunk (>0.0.5) so the
3586
# following code can be deleted when it's sufficiently deployed
3587
# -- vila/mgz 20100514
3588
if (sys.platform == "win32"
3589
and getattr(sys.stdout, 'fileno', None) is not None):
3590
3591
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
3592
3593
self.additional_selftest_args.setdefault(
3593
3594
'suite_decorators', []).append(parallel)
3595
test_suite_factory = benchmarks.test_suite
3596
# Unless user explicitly asks for quiet, be verbose in benchmarks
3597
verbose = not is_quiet()
3598
# TODO: should possibly lock the history file...
3599
benchfile = open(".perf_history", "at", buffering=1)
3600
self.add_cleanup(benchfile.close)
3602
test_suite_factory = None
3596
raise errors.BzrCommandError(
3597
"--benchmark is no longer supported from bzr 2.2; "
3598
"use bzr-usertest instead")
3599
test_suite_factory = None
3604
3600
selftest_kwargs = {"verbose": verbose,
3605
3601
"pattern": pattern,
3606
3602
"stop_on_failure": one,
3608
3604
"test_suite_factory": test_suite_factory,
3609
3605
"lsprof_timed": lsprof_timed,
3610
3606
"lsprof_tests": lsprof_tests,
3611
"bench_history": benchfile,
3612
3607
"matching_tests_first": first,
3613
3608
"list_only": list_only,
3614
3609
"random_seed": randomize,
3764
3759
' completely merged into the source, pull from the'
3765
3760
' source rather than merging. When this happens,'
3766
3761
' you do not need to commit the result.'),
3762
custom_help('directory',
3768
3763
help='Branch to merge into, '
3769
'rather than the one containing the working directory.',
3764
'rather than the one containing the working directory.'),
3773
3765
Option('preview', help='Instead of merging, show a diff of the'
3775
3767
Option('interactive', help='Select changes interactively.',
3875
3867
def _do_preview(self, merger):
3876
3868
from bzrlib.diff import show_diff_trees
3877
3869
result_tree = self._get_preview(merger)
3870
path_encoding = osutils.get_diff_header_encoding()
3878
3871
show_diff_trees(merger.this_tree, result_tree, self.outf,
3879
old_label='', new_label='')
3872
old_label='', new_label='',
3873
path_encoding=path_encoding)
3881
3875
def _do_merge(self, merger, change_reporter, allow_pending, verified):
3882
3876
merger.change_reporter = change_reporter
4069
4063
from bzrlib.conflicts import restore
4070
4064
if merge_type is None:
4071
4065
merge_type = _mod_merge.Merge3Merger
4072
tree, file_list = tree_files(file_list)
4066
tree, file_list = WorkingTree.open_containing_paths(file_list)
4073
4067
self.add_cleanup(tree.lock_write().unlock)
4074
4068
parents = tree.get_parent_ids()
4075
4069
if len(parents) != 2:
4186
4180
def run(self, revision=None, no_backup=False, file_list=None,
4187
4181
forget_merges=None):
4188
tree, file_list = tree_files(file_list)
4182
tree, file_list = WorkingTree.open_containing_paths(file_list)
4189
4183
self.add_cleanup(tree.lock_tree_write().unlock)
4190
4184
if forget_merges:
4191
4185
tree.set_parent_ids(tree.get_parent_ids()[:1])
4281
4275
_see_also = ['merge', 'pull']
4282
4276
takes_args = ['other_branch?']
4283
4277
takes_options = [
4284
4279
Option('reverse', 'Reverse the order of revisions.'),
4285
4280
Option('mine-only',
4286
4281
'Display changes in the local branch only.'),
4308
4303
theirs_only=False,
4309
4304
log_format=None, long=False, short=False, line=False,
4310
4305
show_ids=False, verbose=False, this=False, other=False,
4311
include_merges=False, revision=None, my_revision=None):
4306
include_merges=False, revision=None, my_revision=None,
4312
4308
from bzrlib.missing import find_unmerged, iter_log_revisions
4313
4309
def message(s):
4314
4310
if not is_quiet():
4542
4538
Option('long', help='Show commit date in annotations.'),
4546
4543
encoding_type = 'exact'
4548
4545
@display_command
4549
4546
def run(self, filename, all=False, long=False, revision=None,
4547
show_ids=False, directory=None):
4551
4548
from bzrlib.annotate import annotate_file, annotate_file_tree
4552
4549
wt, branch, relpath = \
4553
bzrdir.BzrDir.open_containing_tree_or_branch(filename)
4550
_open_directory_or_containing_tree_or_branch(filename, directory)
4554
4551
if wt is not None:
4555
4552
self.add_cleanup(wt.lock_read().unlock)
4581
4578
hidden = True # is this right ?
4582
4579
takes_args = ['revision_id*']
4583
takes_options = ['revision']
4580
takes_options = ['directory', 'revision']
4585
def run(self, revision_id_list=None, revision=None):
4582
def run(self, revision_id_list=None, revision=None, directory=u'.'):
4586
4583
if revision_id_list is not None and revision is not None:
4587
4584
raise errors.BzrCommandError('You can only supply one of revision_id or --revision')
4588
4585
if revision_id_list is None and revision is None:
4589
4586
raise errors.BzrCommandError('You must supply either --revision or a revision_id')
4590
b = WorkingTree.open_containing(u'.')[0].branch
4587
b = WorkingTree.open_containing(directory)[0].branch
4591
4588
self.add_cleanup(b.lock_write().unlock)
4592
4589
return self._run(b, revision_id_list, revision)
4654
4651
_see_also = ['checkouts', 'unbind']
4655
4652
takes_args = ['location?']
4653
takes_options = ['directory']
4658
def run(self, location=None):
4659
b, relpath = Branch.open_containing(u'.')
4655
def run(self, location=None, directory=u'.'):
4656
b, relpath = Branch.open_containing(directory)
4660
4657
if location is None:
4662
4659
location = b.get_old_bound_location()
4690
4687
_see_also = ['checkouts', 'bind']
4691
4688
takes_args = []
4689
takes_options = ['directory']
4695
b, relpath = Branch.open_containing(u'.')
4691
def run(self, directory=u'.'):
4692
b, relpath = Branch.open_containing(directory)
4696
4693
if not b.unbind():
4697
4694
raise errors.BzrCommandError('Local branch is not bound')
4860
4857
'result in a dynamically allocated port. The default port '
4861
4858
'depends on the protocol.',
4864
help='Serve contents of this directory.',
4860
custom_help('directory',
4861
help='Serve contents of this directory.'),
4866
4862
Option('allow-writes',
4867
4863
help='By default the server is a readonly server. Supplying '
4868
4864
'--allow-writes enables write access to the contents of '
4896
4892
def run(self, port=None, inet=False, directory=None, allow_writes=False,
4897
4893
protocol=None):
4898
from bzrlib.transport import get_transport, transport_server_registry
4894
from bzrlib import transport
4899
4895
if directory is None:
4900
4896
directory = os.getcwd()
4901
4897
if protocol is None:
4902
protocol = transport_server_registry.get()
4898
protocol = transport.transport_server_registry.get()
4903
4899
host, port = self.get_host_and_port(port)
4904
4900
url = urlutils.local_path_to_url(directory)
4905
4901
if not allow_writes:
4906
4902
url = 'readonly+' + url
4907
transport = get_transport(url)
4908
protocol(transport, host, port, inet)
4903
t = transport.get_transport(url)
4904
protocol(t, host, port, inet)
4911
4907
class cmd_join(Command):
5022
5019
encoding_type = 'exact'
5024
5021
def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
5025
sign=False, revision=None, mail_to=None, message=None):
5022
sign=False, revision=None, mail_to=None, message=None,
5026
5024
from bzrlib.revision import ensure_null, NULL_REVISION
5027
5025
include_patch, include_bundle = {
5028
5026
'plain': (False, False),
5029
5027
'diff': (True, False),
5030
5028
'bundle': (True, True),
5032
branch = Branch.open('.')
5030
branch = Branch.open(directory)
5033
5031
stored_submit_branch = branch.get_submit_branch()
5034
5032
if submit_branch is None:
5035
5033
submit_branch = stored_submit_branch
5120
5118
given, in which case it is sent to a file.
5122
5120
Mail is sent using your preferred mail program. This should be transparent
5123
on Windows (it uses MAPI). On Linux, it requires the xdg-email utility.
5121
on Windows (it uses MAPI). On Unix, it requires the xdg-email utility.
5124
5122
If the preferred client can't be found (or used), your editor will be used.
5126
5124
To use a specific mail program, set the mail_client configuration option.
5297
5295
Option('delete',
5298
5296
help='Delete this tag rather than placing it.',
5301
help='Branch in which to place the tag.',
5298
custom_help('directory',
5299
help='Branch in which to place the tag.'),
5305
5300
Option('force',
5306
5301
help='Replace existing tags.',
5350
5345
_see_also = ['tag']
5351
5346
takes_options = [
5353
help='Branch whose tags should be displayed.',
5347
custom_help('directory',
5348
help='Branch whose tags should be displayed.'),
5357
5349
RegistryOption.from_kwargs('sort',
5358
5350
'Sort tags by different criteria.', title='Sorting',
5359
5351
alpha='Sort tags lexicographically (default).',
5531
5523
takes_args = ['to_location?']
5532
takes_options = [Option('force',
5524
takes_options = ['directory',
5533
5526
help='Switch even if local commits will be lost.'),
5535
5528
Option('create-branch', short_name='b',
5540
5533
def run(self, to_location=None, force=False, create_branch=False,
5534
revision=None, directory=u'.'):
5542
5535
from bzrlib import switch
5536
tree_location = directory
5544
5537
revision = _get_one_revision('switch', revision)
5545
5538
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5546
5539
if to_location is None:
5547
5540
if revision is None:
5548
5541
raise errors.BzrCommandError('You must supply either a'
5549
5542
' revision or a location')
5543
to_location = tree_location
5552
5545
branch = control_dir.open_branch()
5553
5546
had_explicit_nick = branch.get_config().has_explicit_nickname()
5691
tree, file_list = tree_files(file_list, apply_view=False)
5684
tree, file_list = WorkingTree.open_containing_paths(file_list,
5692
5686
current_view, view_dict = tree.views.get_view_info()
5693
5687
if name is None:
5694
5688
name = current_view
5842
5837
_see_also = ['unshelve']
5844
5839
def run(self, revision=None, all=False, file_list=None, message=None,
5845
writer=None, list=False, destroy=False):
5840
writer=None, list=False, destroy=False, directory=u'.'):
5847
5842
return self.run_for_list()
5848
5843
from bzrlib.shelf_ui import Shelver
5850
5845
writer = bzrlib.option.diff_writer_registry.get()
5852
5847
shelver = Shelver.from_args(writer(sys.stdout), revision, all,
5853
file_list, message, destroy=destroy)
5848
file_list, message, destroy=destroy, directory=directory)
5885
5880
takes_args = ['shelf_id?']
5886
5881
takes_options = [
5887
5883
RegistryOption.from_kwargs(
5888
5884
'action', help="The action to perform.",
5889
5885
enum_switch=False, value_switches=True,
5898
5894
_see_also = ['shelve']
5900
def run(self, shelf_id=None, action='apply'):
5896
def run(self, shelf_id=None, action='apply', directory=u'.'):
5901
5897
from bzrlib.shelf_ui import Unshelver
5902
unshelver = Unshelver.from_args(shelf_id, action)
5898
unshelver = Unshelver.from_args(shelf_id, action, directory=directory)
5904
5900
unshelver.run()
5922
5918
To check what clean-tree will do, use --dry-run.
5924
takes_options = [Option('ignored', help='Delete all ignored files.'),
5920
takes_options = ['directory',
5921
Option('ignored', help='Delete all ignored files.'),
5925
5922
Option('detritus', help='Delete conflict files, merge'
5926
5923
' backups, and failed selftest dirs.'),
5927
5924
Option('unknown',
5930
5927
' deleting them.'),
5931
5928
Option('force', help='Do not prompt before deleting.')]
5932
5929
def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
5930
force=False, directory=u'.'):
5934
5931
from bzrlib.clean_tree import clean_tree
5935
5932
if not (unknown or ignored or detritus):
5939
clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus,
5940
dry_run=dry_run, no_prompt=force)
5936
clean_tree(directory, unknown=unknown, ignored=ignored,
5937
detritus=detritus, dry_run=dry_run, no_prompt=force)
5943
5940
class cmd_reference(Command):