74
75
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,
80
return internal_tree_files(file_list, default_branch, canonicalize,
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]))
84
88
def tree_files_for_add(file_list):
149
153
# XXX: Bad function name; should possibly also be a class method of
150
154
# WorkingTree rather than a function.
151
@symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
152
155
def internal_tree_files(file_list, default_branch=u'.', canonicalize=True,
153
156
apply_view=True):
154
157
"""Convert command-line paths to a WorkingTree and relative paths.
156
Deprecated: use WorkingTree.open_containing_paths instead.
158
159
This is typically used for command-line processors that take one or
159
160
more filenames, and infer the workingtree that contains them.
171
172
:return: workingtree, [relative_paths]
173
return WorkingTree.open_containing_paths(
174
file_list, default_directory='.',
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)
179
223
def _get_view_info_for_change_reporter(tree):
279
323
raise errors.BzrCommandError('bzr status --revision takes exactly'
280
324
' one or two revision specifiers')
282
tree, relfile_list = WorkingTree.open_containing_paths(file_list)
326
tree, relfile_list = tree_files(file_list)
283
327
# Avoid asking for specific files when that is not needed.
284
328
if relfile_list == ['']:
285
329
relfile_list = None
717
761
raise errors.BzrCommandError('invalid kind %r specified' % (kind,))
719
763
revision = _get_one_revision('inventory', revision)
720
work_tree, file_list = WorkingTree.open_containing_paths(file_list)
764
work_tree, file_list = tree_files(file_list)
721
765
self.add_cleanup(work_tree.lock_read().unlock)
722
766
if revision is not None:
723
767
tree = revision.as_tree(work_tree.branch)
789
833
if len(names_list) < 2:
790
834
raise errors.BzrCommandError("missing file argument")
791
tree, rel_names = WorkingTree.open_containing_paths(names_list, canonicalize=False)
835
tree, rel_names = tree_files(names_list, canonicalize=False)
792
836
self.add_cleanup(tree.lock_tree_write().unlock)
793
837
self._run(tree, names_list, rel_names, after)
800
844
raise errors.BzrCommandError('--after cannot be specified with'
802
work_tree, file_list = WorkingTree.open_containing_paths(
803
names_list, default_directory='.')
846
work_tree, file_list = tree_files(names_list, default_branch='.')
804
847
self.add_cleanup(work_tree.lock_tree_write().unlock)
805
848
rename_map.RenameMap.guess_renames(work_tree, dry_run)
1135
1178
_see_also = ['checkout']
1136
1179
takes_args = ['from_location', 'to_location?']
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."),
1180
takes_options = ['revision', Option('hardlink',
1181
help='Hard-link working tree files where possible.'),
1141
1182
Option('no-tree',
1142
1183
help="Create a branch without a working-tree."),
1143
1184
Option('switch',
1162
1203
def run(self, from_location, to_location=None, revision=None,
1163
1204
hardlink=False, stacked=False, standalone=False, no_tree=False,
1164
use_existing_dir=False, switch=False, bind=False,
1205
use_existing_dir=False, switch=False, bind=False):
1166
1206
from bzrlib import switch as _mod_switch
1167
1207
from bzrlib.tag import _merge_tags_if_possible
1168
1208
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)
1177
1210
revision = _get_one_revision('branch', revision)
1178
1211
self.add_cleanup(br_from.lock_read().unlock)
1179
1212
if revision is not None:
1286
1319
to_location = branch_location
1287
1320
accelerator_tree, source = bzrdir.BzrDir.open_tree_or_branch(
1288
1321
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
1294
1322
revision = _get_one_revision('checkout', revision)
1295
if files_from is not None and files_from != branch_location:
1323
if files_from is not None:
1296
1324
accelerator_tree = WorkingTree.open(files_from)
1297
1325
if revision is not None:
1298
1326
revision_id = revision.as_revision_id(source)
1477
1505
class cmd_remove(Command):
1478
1506
__doc__ = """Remove files or directories.
1480
This makes Bazaar stop tracking changes to the specified files. Bazaar will
1481
delete them if they can easily be recovered using revert otherwise they
1482
will be backed up (adding an extention of the form .~#~). If no options or
1483
parameters are given Bazaar will scan for files that are being tracked by
1484
Bazaar but missing in your tree and stop tracking them for you.
1508
This makes bzr stop tracking changes to the specified files. bzr will delete
1509
them if they can easily be recovered using revert. If no options or
1510
parameters are given bzr will scan for files that are being tracked by bzr
1511
but missing in your tree and stop tracking them for you.
1486
1513
takes_args = ['file*']
1487
1514
takes_options = ['verbose',
1489
1516
RegistryOption.from_kwargs('file-deletion-strategy',
1490
1517
'The file deletion mode to be used.',
1491
1518
title='Deletion Strategy', value_switches=True, enum_switch=False,
1492
safe='Backup changed files (default).',
1519
safe='Only delete files if they can be'
1520
' safely recovered (default).',
1493
1521
keep='Delete from bzr but leave the working copy.',
1494
1522
force='Delete all the specified files, even if they can not be '
1495
1523
'recovered and even if they are non-empty directories.')]
1499
1527
def run(self, file_list, verbose=False, new=False,
1500
1528
file_deletion_strategy='safe'):
1501
tree, file_list = WorkingTree.open_containing_paths(file_list)
1529
tree, file_list = tree_files(file_list)
1503
1531
if file_list is not None:
1504
1532
file_list = [f for f in file_list]
1593
1621
_see_also = ['check']
1594
1622
takes_args = ['branch?']
1596
Option('canonicalize-chks',
1597
help='Make sure CHKs are in canonical form (repairs '
1602
def run(self, branch=".", canonicalize_chks=False):
1624
def run(self, branch="."):
1603
1625
from bzrlib.reconcile import reconcile
1604
1626
dir = bzrdir.BzrDir.open(branch)
1605
reconcile(dir, canonicalize_chks=canonicalize_chks)
1608
1630
class cmd_revision_history(Command):
2694
2712
"NAME_PATTERN or --default-rules.")
2695
2713
name_pattern_list = [globbing.normalize_pattern(p)
2696
2714
for p in name_pattern_list]
2698
for p in name_pattern_list:
2699
if not globbing.Globster.is_pattern_valid(p):
2700
bad_patterns += ('\n %s' % p)
2702
msg = ('Invalid ignore pattern(s) found. %s' % bad_patterns)
2703
ui.ui_factory.show_error(msg)
2704
raise errors.InvalidPattern('')
2705
2715
for name_pattern in name_pattern_list:
2706
2716
if (name_pattern[0] == '/' or
2707
2717
(len(name_pattern) > 1 and name_pattern[1] == ':')):
2711
2721
ignores.tree_ignores_add_patterns(tree, name_pattern_list)
2712
2722
ignored = globbing.Globster(name_pattern_list)
2714
self.add_cleanup(tree.lock_read().unlock)
2715
2725
for entry in tree.list_files():
2717
2727
if id is not None:
2718
2728
filename = entry[0]
2719
2729
if ignored.match(filename):
2720
2730
matches.append(filename)
2721
2732
if len(matches) > 0:
2722
2733
self.outf.write("Warning: the following files are version controlled and"
2723
2734
" match your ignore pattern:\n%s"
3100
3111
properties = {}
3102
tree, selected_list = WorkingTree.open_containing_paths(selected_list)
3113
tree, selected_list = tree_files(selected_list)
3103
3114
if selected_list == ['']:
3104
3115
# workaround - commit of root of tree should be exactly the same
3105
3116
# as just default commit in that tree, and succeed even though
3140
3151
def get_message(commit_obj):
3141
3152
"""Callback to get commit message"""
3154
f = codecs.open(file, 'rt', osutils.get_user_encoding())
3145
my_message = f.read().decode(osutils.get_user_encoding())
3156
my_message = f.read()
3148
3159
elif message is not None:
3179
3190
reporter=None, verbose=verbose, revprops=properties,
3180
3191
authors=author, timestamp=commit_stamp,
3181
3192
timezone=offset,
3182
exclude=tree.safe_relpath_files(exclude))
3193
exclude=safe_relpath_files(tree, exclude))
3183
3194
except PointlessCommit:
3184
3195
raise errors.BzrCommandError("No changes to commit."
3185
3196
" Use --unchanged to commit anyhow.")
3323
3334
c = Branch.open_containing(u'.')[0].get_config()
3324
3335
except errors.NotBranchError:
3325
c = _mod_config.GlobalConfig()
3336
c = config.GlobalConfig()
3327
3338
c = Branch.open(directory).get_config()
3334
3345
# display a warning if an email address isn't included in the given name.
3336
_mod_config.extract_email_address(name)
3347
config.extract_email_address(name)
3337
3348
except errors.NoEmailInUsername, e:
3338
3349
warning('"%s" does not seem to contain an email address. '
3339
3350
'This is allowed, but not recommended.', name)
3418
3429
'bzr alias --remove expects an alias to remove.')
3419
3430
# If alias is not found, print something like:
3420
3431
# unalias: foo: not found
3421
c = _mod_config.GlobalConfig()
3432
c = config.GlobalConfig()
3422
3433
c.unset_alias(alias_name)
3424
3435
@display_command
3425
3436
def print_aliases(self):
3426
3437
"""Print out the defined aliases in a similar format to bash."""
3427
aliases = _mod_config.GlobalConfig().get_aliases()
3438
aliases = config.GlobalConfig().get_aliases()
3428
3439
for key, value in sorted(aliases.iteritems()):
3429
3440
self.outf.write('bzr alias %s="%s"\n' % (key, value))
3441
3452
def set_alias(self, alias_name, alias_command):
3442
3453
"""Save the alias in the global config."""
3443
c = _mod_config.GlobalConfig()
3454
c = config.GlobalConfig()
3444
3455
c.set_alias(alias_name, alias_command)
3519
3530
'throughout the test suite.',
3520
3531
type=get_transport_type),
3521
3532
Option('benchmark',
3522
help='Run the benchmarks rather than selftests.',
3533
help='Run the benchmarks rather than selftests.'),
3524
3534
Option('lsprof-timed',
3525
3535
help='Generate lsprof output for benchmarked'
3526
3536
' sections of code.'),
3527
3537
Option('lsprof-tests',
3528
3538
help='Generate lsprof output for each test.'),
3539
Option('cache-dir', type=str,
3540
help='Cache intermediate benchmark output in this '
3529
3542
Option('first',
3530
3543
help='Run all tests, but run specified tests first.',
3531
3544
short_name='f',
3566
3579
def run(self, testspecs_list=None, verbose=False, one=False,
3567
3580
transport=None, benchmark=None,
3581
lsprof_timed=None, cache_dir=None,
3569
3582
first=False, list_only=False,
3570
3583
randomize=None, exclude=None, strict=False,
3571
3584
load_list=None, debugflag=None, starting_with=None, subunit=False,
3572
3585
parallel=None, lsprof_tests=False):
3573
from bzrlib import tests
3586
from bzrlib.tests import selftest
3587
import bzrlib.benchmarks as benchmarks
3588
from bzrlib.benchmarks import tree_creator
3590
# Make deprecation warnings visible, unless -Werror is set
3591
symbol_versioning.activate_deprecation_warnings(override=False)
3593
if cache_dir is not None:
3594
tree_creator.TreeCreator.CACHE_ROOT = osutils.abspath(cache_dir)
3575
3595
if testspecs_list is not None:
3576
3596
pattern = '|'.join(testspecs_list)
3596
3616
self.additional_selftest_args.setdefault(
3597
3617
'suite_decorators', []).append(parallel)
3599
raise errors.BzrCommandError(
3600
"--benchmark is no longer supported from bzr 2.2; "
3601
"use bzr-usertest instead")
3602
test_suite_factory = None
3619
test_suite_factory = benchmarks.test_suite
3620
# Unless user explicitly asks for quiet, be verbose in benchmarks
3621
verbose = not is_quiet()
3622
# TODO: should possibly lock the history file...
3623
benchfile = open(".perf_history", "at", buffering=1)
3624
self.add_cleanup(benchfile.close)
3626
test_suite_factory = None
3603
3628
selftest_kwargs = {"verbose": verbose,
3604
3629
"pattern": pattern,
3605
3630
"stop_on_failure": one,
3607
3632
"test_suite_factory": test_suite_factory,
3608
3633
"lsprof_timed": lsprof_timed,
3609
3634
"lsprof_tests": lsprof_tests,
3635
"bench_history": benchfile,
3610
3636
"matching_tests_first": first,
3611
3637
"list_only": list_only,
3612
3638
"random_seed": randomize,
3617
3643
"starting_with": starting_with
3619
3645
selftest_kwargs.update(self.additional_selftest_args)
3621
# Make deprecation warnings visible, unless -Werror is set
3622
cleanup = symbol_versioning.activate_deprecation_warnings(
3625
result = tests.selftest(**selftest_kwargs)
3646
result = selftest(**selftest_kwargs)
3628
3647
return int(not result)
4073
4092
from bzrlib.conflicts import restore
4074
4093
if merge_type is None:
4075
4094
merge_type = _mod_merge.Merge3Merger
4076
tree, file_list = WorkingTree.open_containing_paths(file_list)
4095
tree, file_list = tree_files(file_list)
4077
4096
self.add_cleanup(tree.lock_write().unlock)
4078
4097
parents = tree.get_parent_ids()
4079
4098
if len(parents) != 2:
4190
4209
def run(self, revision=None, no_backup=False, file_list=None,
4191
4210
forget_merges=None):
4192
tree, file_list = WorkingTree.open_containing_paths(file_list)
4211
tree, file_list = tree_files(file_list)
4193
4212
self.add_cleanup(tree.lock_tree_write().unlock)
4194
4213
if forget_merges:
4195
4214
tree.set_parent_ids(tree.get_parent_ids()[:1])
4813
4832
class cmd_break_lock(Command):
4814
__doc__ = """Break a dead lock.
4816
This command breaks a lock on a repository, branch, working directory or
4833
__doc__ = """Break a dead lock on a repository, branch or working directory.
4819
4835
CAUTION: Locks should only be broken when you are sure that the process
4820
4836
holding the lock has been stopped.
4827
4843
bzr break-lock bzr+ssh://example.com/bzr/foo
4828
bzr break-lock --conf ~/.bazaar
4831
4845
takes_args = ['location?']
4834
help='LOCATION is the directory where the config lock is.'),
4837
def run(self, location=None, config=False):
4847
def run(self, location=None, show=False):
4838
4848
if location is None:
4839
4849
location = u'.'
4841
conf = _mod_config.LockableConfig(file_name=location)
4844
control, relpath = bzrdir.BzrDir.open_containing(location)
4846
control.break_lock()
4847
except NotImplementedError:
4850
control, relpath = bzrdir.BzrDir.open_containing(location)
4852
control.break_lock()
4853
except NotImplementedError:
4851
4857
class cmd_wait_until_signalled(Command):
4915
4921
def run(self, port=None, inet=False, directory=None, allow_writes=False,
4916
4922
protocol=None):
4917
from bzrlib import transport
4923
from bzrlib.transport import get_transport, transport_server_registry
4918
4924
if directory is None:
4919
4925
directory = os.getcwd()
4920
4926
if protocol is None:
4921
protocol = transport.transport_server_registry.get()
4927
protocol = transport_server_registry.get()
4922
4928
host, port = self.get_host_and_port(port)
4923
4929
url = urlutils.local_path_to_url(directory)
4924
4930
if not allow_writes:
4925
4931
url = 'readonly+' + url
4926
t = transport.get_transport(url)
4927
protocol(t, host, port, inet)
4932
transport = get_transport(url)
4933
protocol(transport, host, port, inet)
4930
4936
class cmd_join(Command):
5707
tree, file_list = WorkingTree.open_containing_paths(file_list,
5713
tree, file_list = tree_files(file_list, apply_view=False)
5709
5714
current_view, view_dict = tree.views.get_view_info()
5710
5715
if name is None:
5711
5716
name = current_view