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):
323
279
raise errors.BzrCommandError('bzr status --revision takes exactly'
324
280
' one or two revision specifiers')
326
tree, relfile_list = tree_files(file_list)
282
tree, relfile_list = WorkingTree.open_containing_paths(file_list)
327
283
# Avoid asking for specific files when that is not needed.
328
284
if relfile_list == ['']:
329
285
relfile_list = None
761
717
raise errors.BzrCommandError('invalid kind %r specified' % (kind,))
763
719
revision = _get_one_revision('inventory', revision)
764
work_tree, file_list = tree_files(file_list)
720
work_tree, file_list = WorkingTree.open_containing_paths(file_list)
765
721
self.add_cleanup(work_tree.lock_read().unlock)
766
722
if revision is not None:
767
723
tree = revision.as_tree(work_tree.branch)
833
789
if len(names_list) < 2:
834
790
raise errors.BzrCommandError("missing file argument")
835
tree, rel_names = tree_files(names_list, canonicalize=False)
791
tree, rel_names = WorkingTree.open_containing_paths(names_list, canonicalize=False)
836
792
self.add_cleanup(tree.lock_tree_write().unlock)
837
793
self._run(tree, names_list, rel_names, after)
844
800
raise errors.BzrCommandError('--after cannot be specified with'
846
work_tree, file_list = tree_files(names_list, default_branch='.')
802
work_tree, file_list = WorkingTree.open_containing_paths(
803
names_list, default_directory='.')
847
804
self.add_cleanup(work_tree.lock_tree_write().unlock)
848
805
rename_map.RenameMap.guess_renames(work_tree, dry_run)
1178
1135
_see_also = ['checkout']
1179
1136
takes_args = ['from_location', 'to_location?']
1180
takes_options = ['revision', Option('hardlink',
1181
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."),
1182
1141
Option('no-tree',
1183
1142
help="Create a branch without a working-tree."),
1184
1143
Option('switch',
1203
1162
def run(self, from_location, to_location=None, revision=None,
1204
1163
hardlink=False, stacked=False, standalone=False, no_tree=False,
1205
use_existing_dir=False, switch=False, bind=False):
1164
use_existing_dir=False, switch=False, bind=False,
1206
1166
from bzrlib import switch as _mod_switch
1207
1167
from bzrlib.tag import _merge_tags_if_possible
1208
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)
1210
1177
revision = _get_one_revision('branch', revision)
1211
1178
self.add_cleanup(br_from.lock_read().unlock)
1212
1179
if revision is not None:
1319
1286
to_location = branch_location
1320
1287
accelerator_tree, source = bzrdir.BzrDir.open_tree_or_branch(
1321
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
1322
1294
revision = _get_one_revision('checkout', revision)
1323
if files_from is not None:
1295
if files_from is not None and files_from != branch_location:
1324
1296
accelerator_tree = WorkingTree.open(files_from)
1325
1297
if revision is not None:
1326
1298
revision_id = revision.as_revision_id(source)
1527
1499
def run(self, file_list, verbose=False, new=False,
1528
1500
file_deletion_strategy='safe'):
1529
tree, file_list = tree_files(file_list)
1501
tree, file_list = WorkingTree.open_containing_paths(file_list)
1531
1503
if file_list is not None:
1532
1504
file_list = [f for f in file_list]
1911
1883
takes_args = ['file*']
1912
1884
takes_options = [
1913
1885
Option('diff-options', type=str,
1914
help='Pass these options to the external diff program.'),
1886
help='Pass these options to the diff program.'),
1915
1887
Option('prefix', type=str,
1916
1888
short_name='p',
1917
1889
help='Set prefixes added to old and new filenames, as '
1958
1930
'--prefix expects two values separated by a colon'
1959
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.')
1961
1937
if revision and len(revision) > 2:
1962
1938
raise errors.BzrCommandError('bzr diff --revision takes exactly'
1963
1939
' one or two revision specifiers')
2712
2688
"NAME_PATTERN or --default-rules.")
2713
2689
name_pattern_list = [globbing.normalize_pattern(p)
2714
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('')
2715
2699
for name_pattern in name_pattern_list:
2716
2700
if (name_pattern[0] == '/' or
2717
2701
(len(name_pattern) > 1 and name_pattern[1] == ':')):
3110
3094
properties = {}
3112
tree, selected_list = tree_files(selected_list)
3096
tree, selected_list = WorkingTree.open_containing_paths(selected_list)
3113
3097
if selected_list == ['']:
3114
3098
# workaround - commit of root of tree should be exactly the same
3115
3099
# as just default commit in that tree, and succeed even though
3150
3134
def get_message(commit_obj):
3151
3135
"""Callback to get commit message"""
3153
f = codecs.open(file, 'rt', osutils.get_user_encoding())
3155
my_message = f.read()
3139
my_message = f.read().decode(osutils.get_user_encoding())
3158
3142
elif message is not None:
3189
3173
reporter=None, verbose=verbose, revprops=properties,
3190
3174
authors=author, timestamp=commit_stamp,
3191
3175
timezone=offset,
3192
exclude=safe_relpath_files(tree, exclude))
3176
exclude=tree.safe_relpath_files(exclude))
3193
3177
except PointlessCommit:
3194
3178
raise errors.BzrCommandError("No changes to commit."
3195
3179
" Use --unchanged to commit anyhow.")
3529
3513
'throughout the test suite.',
3530
3514
type=get_transport_type),
3531
3515
Option('benchmark',
3532
help='Run the benchmarks rather than selftests.'),
3516
help='Run the benchmarks rather than selftests.',
3533
3518
Option('lsprof-timed',
3534
3519
help='Generate lsprof output for benchmarked'
3535
3520
' sections of code.'),
3536
3521
Option('lsprof-tests',
3537
3522
help='Generate lsprof output for each test.'),
3538
Option('cache-dir', type=str,
3539
help='Cache intermediate benchmark output in this '
3541
3523
Option('first',
3542
3524
help='Run all tests, but run specified tests first.',
3543
3525
short_name='f',
3578
3560
def run(self, testspecs_list=None, verbose=False, one=False,
3579
3561
transport=None, benchmark=None,
3580
lsprof_timed=None, cache_dir=None,
3581
3563
first=False, list_only=False,
3582
3564
randomize=None, exclude=None, strict=False,
3583
3565
load_list=None, debugflag=None, starting_with=None, subunit=False,
3584
3566
parallel=None, lsprof_tests=False):
3585
3567
from bzrlib.tests import selftest
3586
import bzrlib.benchmarks as benchmarks
3587
from bzrlib.benchmarks import tree_creator
3589
3569
# Make deprecation warnings visible, unless -Werror is set
3590
3570
symbol_versioning.activate_deprecation_warnings(override=False)
3592
if cache_dir is not None:
3593
tree_creator.TreeCreator.CACHE_ROOT = osutils.abspath(cache_dir)
3594
3572
if testspecs_list is not None:
3595
3573
pattern = '|'.join(testspecs_list)
3615
3593
self.additional_selftest_args.setdefault(
3616
3594
'suite_decorators', []).append(parallel)
3618
test_suite_factory = benchmarks.test_suite
3619
# Unless user explicitly asks for quiet, be verbose in benchmarks
3620
verbose = not is_quiet()
3621
# TODO: should possibly lock the history file...
3622
benchfile = open(".perf_history", "at", buffering=1)
3623
self.add_cleanup(benchfile.close)
3625
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
3627
3600
selftest_kwargs = {"verbose": verbose,
3628
3601
"pattern": pattern,
3629
3602
"stop_on_failure": one,
3631
3604
"test_suite_factory": test_suite_factory,
3632
3605
"lsprof_timed": lsprof_timed,
3633
3606
"lsprof_tests": lsprof_tests,
3634
"bench_history": benchfile,
3635
3607
"matching_tests_first": first,
3636
3608
"list_only": list_only,
3637
3609
"random_seed": randomize,
4091
4063
from bzrlib.conflicts import restore
4092
4064
if merge_type is None:
4093
4065
merge_type = _mod_merge.Merge3Merger
4094
tree, file_list = tree_files(file_list)
4066
tree, file_list = WorkingTree.open_containing_paths(file_list)
4095
4067
self.add_cleanup(tree.lock_write().unlock)
4096
4068
parents = tree.get_parent_ids()
4097
4069
if len(parents) != 2:
4208
4180
def run(self, revision=None, no_backup=False, file_list=None,
4209
4181
forget_merges=None):
4210
tree, file_list = tree_files(file_list)
4182
tree, file_list = WorkingTree.open_containing_paths(file_list)
4211
4183
self.add_cleanup(tree.lock_tree_write().unlock)
4212
4184
if forget_merges:
4213
4185
tree.set_parent_ids(tree.get_parent_ids()[:1])
5712
tree, file_list = tree_files(file_list, apply_view=False)
5684
tree, file_list = WorkingTree.open_containing_paths(file_list,
5713
5686
current_view, view_dict = tree.views.get_view_info()
5714
5687
if name is None:
5715
5688
name = current_view