86
def _get_branch_location(control_dir, possible_transports=None):
87
"""Return location of branch for this control dir."""
89
this_branch = control_dir.open_branch(
90
possible_transports=possible_transports)
91
# This may be a heavy checkout, where we want the master branch
92
master_location = this_branch.get_bound_location()
93
if master_location is not None:
94
return master_location
95
# If not, use a local sibling
96
return this_branch.base
97
except errors.NotBranchError:
98
format = control_dir.find_branch_format()
99
if getattr(format, 'get_reference', None) is not None:
100
return format.get_reference(control_dir)
102
return control_dir.root_transport.base
105
def _is_colocated(control_dir, possible_transports=None):
106
"""Check if the branch in control_dir is colocated.
108
:param control_dir: Control directory
109
:return: Boolean indicating whether
111
# This path is meant to be relative to the existing branch
112
this_url = _get_branch_location(control_dir,
113
possible_transports=possible_transports)
114
# Perhaps the target control dir supports colocated branches?
116
root = controldir.ControlDir.open(this_url,
117
possible_transports=possible_transports)
118
except errors.NotBranchError:
119
return (False, this_url)
122
wt = control_dir.open_workingtree()
123
except (errors.NoWorkingTree, errors.NotLocalUrl):
124
return (False, this_url)
127
root._format.colocated_branches and
128
control_dir.control_url == root.control_url,
132
def lookup_new_sibling_branch(control_dir, location, possible_transports=None):
133
"""Lookup the location for a new sibling branch.
135
:param control_dir: Control directory relative to which to look up
137
:param location: Name of the new branch
138
:return: Full location to the new branch
140
location = directory_service.directories.dereference(location)
141
if '/' not in location and '\\' not in location:
142
(colocated, this_url) = _is_colocated(control_dir, possible_transports)
145
return urlutils.join_segment_parameters(this_url,
146
{"branch": urlutils.escape(location)})
148
return urlutils.join(this_url, '..', urlutils.escape(location))
152
def lookup_sibling_branch(control_dir, location, possible_transports=None):
153
"""Lookup sibling branch.
155
:param control_dir: Control directory relative to which to lookup the
157
:param location: Location to look up
158
:return: branch to open
161
# Perhaps it's a colocated branch?
162
return control_dir.open_branch(location,
163
possible_transports=possible_transports)
164
except (errors.NotBranchError, errors.NoColocatedBranchSupport):
166
return Branch.open(location)
167
except errors.NotBranchError:
168
this_url = _get_branch_location(control_dir)
171
this_url, '..', urlutils.escape(location)))
174
80
@symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
175
81
def tree_files(file_list, default_branch=u'.', canonicalize=True,
649
556
_see_also = ['info']
650
557
takes_args = ['location?']
651
558
takes_options = [
652
Option('tree', help='Show revno of working tree.'),
559
Option('tree', help='Show revno of working tree'),
657
def run(self, tree=False, location=u'.', revision=None):
658
if revision is not None and tree:
659
raise errors.BzrCommandError(gettext("--tree and --revision can "
660
"not be used together"))
563
def run(self, tree=False, location=u'.'):
664
566
wt = WorkingTree.open_containing(location)[0]
665
567
self.add_cleanup(wt.lock_read().unlock)
666
568
except (errors.NoWorkingTree, errors.NotLocalUrl):
667
569
raise errors.NoWorkingTree(location)
669
570
revid = wt.last_revision()
572
revno_t = wt.branch.revision_id_to_dotted_revno(revid)
573
except errors.NoSuchRevision:
575
revno = ".".join(str(n) for n in revno_t)
671
577
b = Branch.open_containing(location)[0]
672
578
self.add_cleanup(b.lock_read().unlock)
674
if len(revision) != 1:
675
raise errors.BzrCommandError(gettext(
676
"Tags can only be placed on a single revision, "
678
revid = revision[0].as_revision_id(b)
680
revid = b.last_revision()
682
revno_t = b.revision_id_to_dotted_revno(revid)
683
except errors.NoSuchRevision:
685
revno = ".".join(str(n) for n in revno_t)
686
580
self.cleanup_now()
687
self.outf.write(revno + '\n')
581
self.outf.write(str(revno) + '\n')
690
584
class cmd_revision_info(Command):
846
732
takes_args = ['dir+']
850
help='No error if existing, make parent directories as needed.',
854
733
encoding_type = 'replace'
857
def add_file_with_parents(cls, wt, relpath):
858
if wt.path2id(relpath) is not None:
860
cls.add_file_with_parents(wt, osutils.dirname(relpath))
864
def add_file_single(cls, wt, relpath):
867
def run(self, dir_list, parents=False):
869
add_file = self.add_file_with_parents
871
add_file = self.add_file_single
873
wt, relpath = WorkingTree.open_containing(dir)
878
if e.errno != errno.EEXIST:
735
def run(self, dir_list):
737
wt, dd = WorkingTree.open_containing(d)
738
base = os.path.dirname(dd)
739
id = wt.path2id(base)
743
self.outf.write('added %s\n' % d)
882
add_file(wt, relpath)
884
self.outf.write(gettext('added %s\n') % dir)
745
raise errors.NotVersionedError(path=base)
887
748
class cmd_relpath(Command):
994
855
return self.run_auto(names_list, after, dry_run)
996
raise errors.BzrCommandError(gettext('--dry-run requires --auto.'))
857
raise errors.BzrCommandError('--dry-run requires --auto.')
997
858
if names_list is None:
999
860
if len(names_list) < 2:
1000
raise errors.BzrCommandError(gettext("missing file argument"))
861
raise errors.BzrCommandError("missing file argument")
1001
862
tree, rel_names = WorkingTree.open_containing_paths(names_list, canonicalize=False)
1002
for file_name in rel_names[0:-1]:
1004
raise errors.BzrCommandError(gettext("can not move root of branch"))
1005
863
self.add_cleanup(tree.lock_tree_write().unlock)
1006
864
self._run(tree, names_list, rel_names, after)
1008
866
def run_auto(self, names_list, after, dry_run):
1009
867
if names_list is not None and len(names_list) > 1:
1010
raise errors.BzrCommandError(gettext('Only one path may be specified to'
868
raise errors.BzrCommandError('Only one path may be specified to'
1013
raise errors.BzrCommandError(gettext('--after cannot be specified with'
871
raise errors.BzrCommandError('--after cannot be specified with'
1015
873
work_tree, file_list = WorkingTree.open_containing_paths(
1016
874
names_list, default_directory='.')
1017
875
self.add_cleanup(work_tree.lock_tree_write().unlock)
1331
1183
# error by the feedback given to them. RBC 20080227.
1332
1184
stacked_on = parent_url
1333
1185
if not stacked_on:
1334
raise errors.BzrCommandError(gettext(
1335
"Could not determine branch to refer to."))
1186
raise errors.BzrCommandError(
1187
"Could not determine branch to refer to.")
1337
1189
# Get the destination location
1338
1190
if location is None:
1339
1191
stored_loc = br_from.get_push_location()
1340
1192
if stored_loc is None:
1341
parent_loc = br_from.get_parent()
1343
raise errors.BzrCommandError(gettext(
1344
"No push location known or specified. To push to the "
1345
"parent branch (at %s), use 'bzr push :parent'." %
1346
urlutils.unescape_for_display(parent_loc,
1347
self.outf.encoding)))
1349
raise errors.BzrCommandError(gettext(
1350
"No push location known or specified."))
1193
raise errors.BzrCommandError(
1194
"No push location known or specified.")
1352
1196
display_url = urlutils.unescape_for_display(stored_loc,
1353
1197
self.outf.encoding)
1354
note(gettext("Using saved push location: %s") % display_url)
1198
self.outf.write("Using saved push location: %s\n" % display_url)
1355
1199
location = stored_loc
1357
1201
_show_push_branch(br_from, revision_id, location, self.outf,
1435
1279
revision_id = br_from.last_revision()
1436
1280
if to_location is None:
1437
to_location = getattr(br_from, "name", None)
1439
to_location = urlutils.derive_to_location(from_location)
1281
to_location = urlutils.derive_to_location(from_location)
1440
1282
to_transport = transport.get_transport(to_location)
1442
1284
to_transport.mkdir('.')
1443
1285
except errors.FileExists:
1445
to_dir = controldir.ControlDir.open_from_transport(
1447
except errors.NotBranchError:
1448
if not use_existing_dir:
1449
raise errors.BzrCommandError(gettext('Target directory "%s" '
1450
'already exists.') % to_location)
1286
if not use_existing_dir:
1287
raise errors.BzrCommandError('Target directory "%s" '
1288
'already exists.' % to_location)
1455
to_dir.open_branch()
1291
bzrdir.BzrDir.open_from_transport(to_transport)
1456
1292
except errors.NotBranchError:
1459
1295
raise errors.AlreadyBranchError(to_location)
1460
1296
except errors.NoSuchFile:
1461
raise errors.BzrCommandError(gettext('Parent of "%s" does not exist.')
1297
raise errors.BzrCommandError('Parent of "%s" does not exist.'
1467
# preserve whatever source format we have.
1468
to_dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
1469
possible_transports=[to_transport],
1470
accelerator_tree=accelerator_tree,
1471
hardlink=hardlink, stacked=stacked,
1472
force_new_repo=standalone,
1473
create_tree_if_local=not no_tree,
1474
source_branch=br_from)
1475
branch = to_dir.open_branch(
1476
possible_transports=[
1477
br_from.bzrdir.root_transport, to_transport])
1478
except errors.NoSuchRevision:
1479
to_transport.delete_tree('.')
1480
msg = gettext("The branch {0} has no revision {1}.").format(
1481
from_location, revision)
1482
raise errors.BzrCommandError(msg)
1485
to_repo = to_dir.open_repository()
1486
except errors.NoRepositoryPresent:
1487
to_repo = to_dir.create_repository()
1488
to_repo.fetch(br_from.repository, revision_id=revision_id)
1489
branch = br_from.sprout(to_dir, revision_id=revision_id)
1300
# preserve whatever source format we have.
1301
dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
1302
possible_transports=[to_transport],
1303
accelerator_tree=accelerator_tree,
1304
hardlink=hardlink, stacked=stacked,
1305
force_new_repo=standalone,
1306
create_tree_if_local=not no_tree,
1307
source_branch=br_from)
1308
branch = dir.open_branch()
1309
except errors.NoSuchRevision:
1310
to_transport.delete_tree('.')
1311
msg = "The branch %s has no revision %s." % (from_location,
1313
raise errors.BzrCommandError(msg)
1490
1314
_merge_tags_if_possible(br_from, branch)
1491
1315
# If the source branch is stacked, the new branch may
1492
1316
# be stacked whether we asked for that explicitly or not.
1493
1317
# We therefore need a try/except here and not just 'if stacked:'
1495
note(gettext('Created new stacked branch referring to %s.') %
1319
note('Created new stacked branch referring to %s.' %
1496
1320
branch.get_stacked_on_url())
1497
1321
except (errors.NotStacked, errors.UnstackableBranchFormat,
1498
1322
errors.UnstackableRepositoryFormat), e:
1499
note(ngettext('Branched %d revision.', 'Branched %d revisions.', branch.revno()) % branch.revno())
1323
note('Branched %d revision(s).' % branch.revno())
1501
1325
# Bind to the parent
1502
1326
parent_branch = Branch.open(from_location)
1503
1327
branch.bind(parent_branch)
1504
note(gettext('New branch bound to %s') % from_location)
1328
note('New branch bound to %s' % from_location)
1506
1330
# Switch to the new branch
1507
1331
wt, _ = WorkingTree.open_containing('.')
1508
1332
_mod_switch.switch(wt.bzrdir, branch)
1509
note(gettext('Switched to branch: %s'),
1333
note('Switched to branch: %s',
1510
1334
urlutils.unescape_for_display(branch.base, 'utf-8'))
1513
class cmd_branches(Command):
1514
__doc__ = """List the branches available at the current location.
1516
This command will print the names of all the branches at the current
1520
takes_args = ['location?']
1522
Option('recursive', short_name='R',
1523
help='Recursively scan for branches rather than '
1524
'just looking in the specified location.')]
1526
def run(self, location=".", recursive=False):
1528
t = transport.get_transport(location)
1529
if not t.listable():
1530
raise errors.BzrCommandError(
1531
"Can't scan this type of location.")
1532
for b in controldir.ControlDir.find_branches(t):
1533
self.outf.write("%s\n" % urlutils.unescape_for_display(
1534
urlutils.relative_url(t.base, b.base),
1535
self.outf.encoding).rstrip("/"))
1537
dir = controldir.ControlDir.open_containing(location)[0]
1539
active_branch = dir.open_branch(name="")
1540
except errors.NotBranchError:
1541
active_branch = None
1542
branches = dir.get_branches()
1544
for name, branch in branches.iteritems():
1547
active = (active_branch is not None and
1548
active_branch.base == branch.base)
1549
names[name] = active
1550
# Only mention the current branch explicitly if it's not
1551
# one of the colocated branches
1552
if not any(names.values()) and active_branch is not None:
1553
self.outf.write("* %s\n" % gettext("(default)"))
1554
for name in sorted(names.keys()):
1555
active = names[name]
1560
self.outf.write("%s %s\n" % (
1561
prefix, name.encode(self.outf.encoding)))
1564
1337
class cmd_checkout(Command):
1565
1338
__doc__ = """Create a new checkout of an existing branch.
1668
1441
class cmd_update(Command):
1669
__doc__ = """Update a working tree to a new revision.
1671
This will perform a merge of the destination revision (the tip of the
1672
branch, or the specified revision) into the working tree, and then make
1673
that revision the basis revision for the working tree.
1675
You can use this to visit an older revision, or to update a working tree
1676
that is out of date from its branch.
1678
If there are any uncommitted changes in the tree, they will be carried
1679
across and remain as uncommitted changes after the update. To discard
1680
these changes, use 'bzr revert'. The uncommitted changes may conflict
1681
with the changes brought in by the change in basis revision.
1683
If the tree's branch is bound to a master branch, bzr will also update
1442
__doc__ = """Update a tree to have the latest code committed to its branch.
1444
This will perform a merge into the working tree, and may generate
1445
conflicts. If you have any local changes, you will still
1446
need to commit them after the update for the update to be complete.
1448
If you want to discard your local changes, you can just do a
1449
'bzr revert' instead of 'bzr commit' after the update.
1451
If you want to restore a file that has been removed locally, use
1452
'bzr revert' instead of 'bzr update'.
1454
If the tree's branch is bound to a master branch, it will also update
1684
1455
the branch from the master.
1686
You cannot update just a single file or directory, because each Bazaar
1687
working tree has just a single basis revision. If you want to restore a
1688
file that has been removed locally, use 'bzr revert' instead of 'bzr
1689
update'. If you want to restore a file to its state in a previous
1690
revision, use 'bzr revert' with a '-r' option, or use 'bzr cat' to write
1691
out the old content of that file to a new location.
1693
The 'dir' argument, if given, must be the location of the root of a
1694
working tree to update. By default, the working tree that contains the
1695
current working directory is used.
1698
1458
_see_also = ['pull', 'working-trees', 'status-flags']
1760
1512
old_tip=old_tip,
1761
1513
show_base=show_base)
1762
1514
except errors.NoSuchRevision, e:
1763
raise errors.BzrCommandError(gettext(
1515
raise errors.BzrCommandError(
1764
1516
"branch has no revision %s\n"
1765
1517
"bzr update --revision only works"
1766
" for a revision in the branch history")
1518
" for a revision in the branch history"
1767
1519
% (e.revision))
1768
1520
revno = tree.branch.revision_id_to_dotted_revno(
1769
1521
_mod_revision.ensure_null(tree.last_revision()))
1770
note(gettext('Updated to revision {0} of branch {1}').format(
1771
'.'.join(map(str, revno)), branch_location))
1522
note('Updated to revision %s of branch %s' %
1523
('.'.join(map(str, revno)), branch_location))
1772
1524
parent_ids = tree.get_parent_ids()
1773
1525
if parent_ids[1:] and parent_ids[1:] != existing_pending_merges:
1774
note(gettext('Your local commits will now show as pending merges with '
1775
"'bzr status', and can be committed with 'bzr commit'."))
1526
note('Your local commits will now show as pending merges with '
1527
"'bzr status', and can be committed with 'bzr commit'.")
1776
1528
if conflicts != 0:
2173
1920
def run(self, location, format=None, no_trees=False):
2174
1921
if format is None:
2175
format = controldir.format_registry.make_bzrdir('default')
1922
format = bzrdir.format_registry.make_bzrdir('default')
2177
1924
if location is None:
2180
1927
to_transport = transport.get_transport(location)
1928
to_transport.ensure_base()
2182
(repo, newdir, require_stacking, repository_policy) = (
2183
format.initialize_on_transport_ex(to_transport,
2184
create_prefix=True, make_working_trees=not no_trees,
2185
shared_repo=True, force_new_repo=True,
2186
use_existing_dir=True,
2187
repo_format_name=format.repository_format.get_format_string()))
1930
newdir = format.initialize_on_transport(to_transport)
1931
repo = newdir.create_repository(shared=True)
1932
repo.set_make_working_trees(not no_trees)
2188
1933
if not is_quiet():
2189
1934
from bzrlib.info import show_bzrdir_info
2190
show_bzrdir_info(newdir, verbose=0, outfile=self.outf)
1935
show_bzrdir_info(repo.bzrdir, verbose=0, outfile=self.outf)
2193
1938
class cmd_diff(Command):
2654
2396
Option('show-diff',
2655
2397
short_name='p',
2656
2398
help='Show changes made in each revision as a patch.'),
2657
Option('include-merged',
2399
Option('include-merges',
2658
2400
help='Show merged revisions like --levels 0 does.'),
2659
Option('include-merges', hidden=True,
2660
help='Historical alias for --include-merged.'),
2661
Option('omit-merges',
2662
help='Do not report commits with more than one parent.'),
2663
2401
Option('exclude-common-ancestry',
2664
2402
help='Display only the revisions that are not part'
2665
' of both ancestries (require -rX..Y).'
2403
' of both ancestries (require -rX..Y)'
2667
2405
Option('signatures',
2668
help='Show digital signature validity.'),
2671
help='Show revisions whose properties match this '
2674
ListOption('match-message',
2675
help='Show revisions whose message matches this '
2678
ListOption('match-committer',
2679
help='Show revisions whose committer matches this '
2682
ListOption('match-author',
2683
help='Show revisions whose authors match this '
2686
ListOption('match-bugs',
2687
help='Show revisions whose bugs match this '
2406
help='Show digital signature validity'),
2691
2408
encoding_type = 'replace'
2720
2430
_get_info_for_log_files,
2722
2432
direction = (forward and 'forward') or 'reverse'
2723
if symbol_versioning.deprecated_passed(include_merges):
2724
ui.ui_factory.show_user_warning(
2725
'deprecated_command_option',
2726
deprecated_name='--include-merges',
2727
recommended_name='--include-merged',
2728
deprecated_in_version='2.5',
2729
command=self.invoked_as)
2730
if include_merged is None:
2731
include_merged = include_merges
2733
raise errors.BzrCommandError(gettext(
2734
'{0} and {1} are mutually exclusive').format(
2735
'--include-merges', '--include-merged'))
2736
if include_merged is None:
2737
include_merged = False
2738
2433
if (exclude_common_ancestry
2739
2434
and (revision is None or len(revision) != 2)):
2740
raise errors.BzrCommandError(gettext(
2741
'--exclude-common-ancestry requires -r with two revisions'))
2435
raise errors.BzrCommandError(
2436
'--exclude-common-ancestry requires -r with two revisions')
2743
2438
if levels is None:
2746
raise errors.BzrCommandError(gettext(
2747
'{0} and {1} are mutually exclusive').format(
2748
'--levels', '--include-merged'))
2441
raise errors.BzrCommandError(
2442
'--levels and --include-merges are mutually exclusive')
2750
2444
if change is not None:
2751
2445
if len(change) > 1:
2752
2446
raise errors.RangeInChangeOption()
2753
2447
if revision is not None:
2754
raise errors.BzrCommandError(gettext(
2755
'{0} and {1} are mutually exclusive').format(
2756
'--revision', '--change'))
2448
raise errors.BzrCommandError(
2449
'--revision and --change are mutually exclusive')
2758
2451
revision = change
3164
2845
self.outf.write("%s\n" % pattern)
3166
2847
if not name_pattern_list:
3167
raise errors.BzrCommandError(gettext("ignore requires at least one "
3168
"NAME_PATTERN or --default-rules."))
2848
raise errors.BzrCommandError("ignore requires at least one "
2849
"NAME_PATTERN or --default-rules.")
3169
2850
name_pattern_list = [globbing.normalize_pattern(p)
3170
2851
for p in name_pattern_list]
3171
2852
bad_patterns = ''
3172
bad_patterns_count = 0
3173
2853
for p in name_pattern_list:
3174
2854
if not globbing.Globster.is_pattern_valid(p):
3175
bad_patterns_count += 1
3176
2855
bad_patterns += ('\n %s' % p)
3177
2856
if bad_patterns:
3178
msg = (ngettext('Invalid ignore pattern found. %s',
3179
'Invalid ignore patterns found. %s',
3180
bad_patterns_count) % bad_patterns)
2857
msg = ('Invalid ignore pattern(s) found. %s' % bad_patterns)
3181
2858
ui.ui_factory.show_error(msg)
3182
2859
raise errors.InvalidPattern('')
3183
2860
for name_pattern in name_pattern_list:
3184
2861
if (name_pattern[0] == '/' or
3185
2862
(len(name_pattern) > 1 and name_pattern[1] == ':')):
3186
raise errors.BzrCommandError(gettext(
3187
"NAME_PATTERN should not be an absolute path"))
2863
raise errors.BzrCommandError(
2864
"NAME_PATTERN should not be an absolute path")
3188
2865
tree, relpath = WorkingTree.open_containing(directory)
3189
2866
ignores.tree_ignores_add_patterns(tree, name_pattern_list)
3190
2867
ignored = globbing.Globster(name_pattern_list)
3294
2971
Option('per-file-timestamps',
3295
2972
help='Set modification time of files to that of the last '
3296
2973
'revision in which it was changed.'),
3297
Option('uncommitted',
3298
help='Export the working tree contents rather than that of the '
3301
2975
def run(self, dest, branch_or_subdir=None, revision=None, format=None,
3302
root=None, filters=False, per_file_timestamps=False, uncommitted=False,
2976
root=None, filters=False, per_file_timestamps=False, directory=u'.'):
3304
2977
from bzrlib.export import export
3306
2979
if branch_or_subdir is None:
3307
branch_or_subdir = directory
3309
(tree, b, subdir) = controldir.ControlDir.open_containing_tree_or_branch(
3311
if tree is not None:
3312
self.add_cleanup(tree.lock_read().unlock)
3316
raise errors.BzrCommandError(
3317
gettext("--uncommitted requires a working tree"))
2980
tree = WorkingTree.open_containing(directory)[0]
3320
export_tree = _get_one_revision_tree('export', revision, branch=b, tree=tree)
2984
b, subdir = Branch.open_containing(branch_or_subdir)
2987
rev_tree = _get_one_revision_tree('export', revision, branch=b, tree=tree)
3322
export(export_tree, dest, format, root, subdir, filtered=filters,
2989
export(rev_tree, dest, format, root, subdir, filtered=filters,
3323
2990
per_file_timestamps=per_file_timestamps)
3324
2991
except errors.NoSuchExportFormat, e:
3325
raise errors.BzrCommandError(
3326
gettext('Unsupported export format: %s') % e.format)
2992
raise errors.BzrCommandError('Unsupported export format: %s' % e.format)
3329
2995
class cmd_cat(Command):
3367
3033
old_file_id = rev_tree.path2id(relpath)
3369
# TODO: Split out this code to something that generically finds the
3370
# best id for a path across one or more trees; it's like
3371
# find_ids_across_trees but restricted to find just one. -- mbp
3373
3035
if name_from_revision:
3374
3036
# Try in revision if requested
3375
3037
if old_file_id is None:
3376
raise errors.BzrCommandError(gettext(
3377
"{0!r} is not present in revision {1}").format(
3038
raise errors.BzrCommandError(
3039
"%r is not present in revision %s" % (
3378
3040
filename, rev_tree.get_revision_id()))
3380
actual_file_id = old_file_id
3042
content = rev_tree.get_file_text(old_file_id)
3382
3044
cur_file_id = tree.path2id(relpath)
3383
if cur_file_id is not None and rev_tree.has_id(cur_file_id):
3384
actual_file_id = cur_file_id
3385
elif old_file_id is not None:
3386
actual_file_id = old_file_id
3388
raise errors.BzrCommandError(gettext(
3389
"{0!r} is not present in revision {1}").format(
3046
if cur_file_id is not None:
3047
# Then try with the actual file id
3049
content = rev_tree.get_file_text(cur_file_id)
3051
except errors.NoSuchId:
3052
# The actual file id didn't exist at that time
3054
if not found and old_file_id is not None:
3055
# Finally try with the old file id
3056
content = rev_tree.get_file_text(old_file_id)
3059
# Can't be found anywhere
3060
raise errors.BzrCommandError(
3061
"%r is not present in revision %s" % (
3390
3062
filename, rev_tree.get_revision_id()))
3392
from bzrlib.filter_tree import ContentFilterTree
3393
filter_tree = ContentFilterTree(rev_tree,
3394
rev_tree._content_filter_stack)
3395
content = filter_tree.get_file_text(actual_file_id)
3064
from bzrlib.filters import (
3065
ContentFilterContext,
3066
filtered_output_bytes,
3068
filters = rev_tree._content_filter_stack(relpath)
3069
chunks = content.splitlines(True)
3070
content = filtered_output_bytes(chunks, filters,
3071
ContentFilterContext(relpath, rev_tree))
3073
self.outf.writelines(content)
3397
content = rev_tree.get_file_text(actual_file_id)
3399
self.outf.write(content)
3076
self.outf.write(content)
3402
3079
class cmd_local_time_offset(Command):
3509
3186
aliases = ['ci', 'checkin']
3511
3188
def _iter_bug_fix_urls(self, fixes, branch):
3512
default_bugtracker = None
3513
3189
# Configure the properties for bug fixing attributes.
3514
3190
for fixed_bug in fixes:
3515
3191
tokens = fixed_bug.split(':')
3516
if len(tokens) == 1:
3517
if default_bugtracker is None:
3518
branch_config = branch.get_config()
3519
default_bugtracker = branch_config.get_user_option(
3521
if default_bugtracker is None:
3522
raise errors.BzrCommandError(gettext(
3523
"No tracker specified for bug %s. Use the form "
3524
"'tracker:id' or specify a default bug tracker "
3525
"using the `bugtracker` option.\nSee "
3526
"\"bzr help bugs\" for more information on this "
3527
"feature. Commit refused.") % fixed_bug)
3528
tag = default_bugtracker
3530
elif len(tokens) != 2:
3531
raise errors.BzrCommandError(gettext(
3192
if len(tokens) != 2:
3193
raise errors.BzrCommandError(
3532
3194
"Invalid bug %s. Must be in the form of 'tracker:id'. "
3533
3195
"See \"bzr help bugs\" for more information on this "
3534
"feature.\nCommit refused.") % fixed_bug)
3536
tag, bug_id = tokens
3196
"feature.\nCommit refused." % fixed_bug)
3197
tag, bug_id = tokens
3538
3199
yield bugtracker.get_bug_url(tag, branch, bug_id)
3539
3200
except errors.UnknownBugTrackerAbbreviation:
3540
raise errors.BzrCommandError(gettext(
3541
'Unrecognized bug %s. Commit refused.') % fixed_bug)
3201
raise errors.BzrCommandError(
3202
'Unrecognized bug %s. Commit refused.' % fixed_bug)
3542
3203
except errors.MalformedBugIdentifier, e:
3543
raise errors.BzrCommandError(gettext(
3544
"%s\nCommit refused.") % (str(e),))
3204
raise errors.BzrCommandError(
3205
"%s\nCommit refused." % (str(e),))
3546
3207
def run(self, message=None, file=None, verbose=False, selected_list=None,
3547
3208
unchanged=False, strict=False, local=False, fixes=None,
3657
3315
exclude=tree.safe_relpath_files(exclude),
3659
3317
except PointlessCommit:
3660
raise errors.BzrCommandError(gettext("No changes to commit."
3318
raise errors.BzrCommandError("No changes to commit."
3661
3319
" Please 'bzr add' the files you want to commit, or use"
3662
" --unchanged to force an empty commit."))
3320
" --unchanged to force an empty commit.")
3663
3321
except ConflictsInTree:
3664
raise errors.BzrCommandError(gettext('Conflicts detected in working '
3322
raise errors.BzrCommandError('Conflicts detected in working '
3665
3323
'tree. Use "bzr conflicts" to list, "bzr resolve FILE" to'
3667
3325
except StrictCommitFailed:
3668
raise errors.BzrCommandError(gettext("Commit refused because there are"
3669
" unknown files in the working tree."))
3326
raise errors.BzrCommandError("Commit refused because there are"
3327
" unknown files in the working tree.")
3670
3328
except errors.BoundBranchOutOfDate, e:
3671
e.extra_help = (gettext("\n"
3329
e.extra_help = ("\n"
3672
3330
'To commit to master branch, run update and then commit.\n'
3673
3331
'You can also pass --local to commit to continue working '
4895
4540
theirs_only=False,
4896
4541
log_format=None, long=False, short=False, line=False,
4897
4542
show_ids=False, verbose=False, this=False, other=False,
4898
include_merged=None, revision=None, my_revision=None,
4900
include_merges=symbol_versioning.DEPRECATED_PARAMETER):
4543
include_merges=False, revision=None, my_revision=None,
4901
4545
from bzrlib.missing import find_unmerged, iter_log_revisions
4902
4546
def message(s):
4903
4547
if not is_quiet():
4904
4548
self.outf.write(s)
4906
if symbol_versioning.deprecated_passed(include_merges):
4907
ui.ui_factory.show_user_warning(
4908
'deprecated_command_option',
4909
deprecated_name='--include-merges',
4910
recommended_name='--include-merged',
4911
deprecated_in_version='2.5',
4912
command=self.invoked_as)
4913
if include_merged is None:
4914
include_merged = include_merges
4916
raise errors.BzrCommandError(gettext(
4917
'{0} and {1} are mutually exclusive').format(
4918
'--include-merges', '--include-merged'))
4919
if include_merged is None:
4920
include_merged = False
4922
4551
mine_only = this
5256
4882
location = b.get_old_bound_location()
5257
4883
except errors.UpgradeRequired:
5258
raise errors.BzrCommandError(gettext('No location supplied. '
5259
'This format does not remember old locations.'))
4884
raise errors.BzrCommandError('No location supplied. '
4885
'This format does not remember old locations.')
5261
4887
if location is None:
5262
4888
if b.get_bound_location() is not None:
5263
raise errors.BzrCommandError(gettext('Branch is already bound'))
4889
raise errors.BzrCommandError('Branch is already bound')
5265
raise errors.BzrCommandError(gettext('No location supplied '
5266
'and no previous location known'))
4891
raise errors.BzrCommandError('No location supplied '
4892
'and no previous location known')
5267
4893
b_other = Branch.open(location)
5269
4895
b.bind(b_other)
5270
4896
except errors.DivergedBranches:
5271
raise errors.BzrCommandError(gettext('These branches have diverged.'
5272
' Try merging, and then bind again.'))
4897
raise errors.BzrCommandError('These branches have diverged.'
4898
' Try merging, and then bind again.')
5273
4899
if b.get_config().has_explicit_nickname():
5274
4900
b.nick = b_other.nick
5382
5005
end_revision=last_revno)
5385
self.outf.write(gettext('Dry-run, pretending to remove'
5386
' the above revisions.\n'))
5008
self.outf.write('Dry-run, pretending to remove'
5009
' the above revisions.\n')
5388
self.outf.write(gettext('The above revision(s) will be removed.\n'))
5011
self.outf.write('The above revision(s) will be removed.\n')
5391
5014
if not ui.ui_factory.confirm_action(
5392
gettext(u'Uncommit these revisions'),
5015
u'Uncommit these revisions',
5393
5016
'bzrlib.builtins.uncommit',
5395
self.outf.write(gettext('Canceled\n'))
5018
self.outf.write('Canceled\n')
5398
5021
mutter('Uncommitting from {%s} to {%s}',
5399
5022
last_rev_id, rev_id)
5400
5023
uncommit(b, tree=tree, dry_run=dry_run, verbose=verbose,
5401
revno=revno, local=local, keep_tags=keep_tags)
5402
self.outf.write(gettext('You can restore the old tip by running:\n'
5403
' bzr pull . -r revid:%s\n') % last_rev_id)
5024
revno=revno, local=local)
5025
self.outf.write('You can restore the old tip by running:\n'
5026
' bzr pull . -r revid:%s\n' % last_rev_id)
5406
5029
class cmd_break_lock(Command):
5514
5135
return host, port
5516
5137
def run(self, port=None, inet=False, directory=None, allow_writes=False,
5517
protocol=None, client_timeout=None):
5518
5139
from bzrlib import transport
5519
5140
if directory is None:
5520
5141
directory = os.getcwd()
5521
5142
if protocol is None:
5522
5143
protocol = transport.transport_server_registry.get()
5523
5144
host, port = self.get_host_and_port(port)
5524
url = transport.location_to_url(directory)
5145
url = urlutils.local_path_to_url(directory)
5525
5146
if not allow_writes:
5526
5147
url = 'readonly+' + url
5527
t = transport.get_transport_from_url(url)
5529
protocol(t, host, port, inet, client_timeout)
5530
except TypeError, e:
5531
# We use symbol_versioning.deprecated_in just so that people
5532
# grepping can find it here.
5533
# symbol_versioning.deprecated_in((2, 5, 0))
5534
symbol_versioning.warn(
5535
'Got TypeError(%s)\ntrying to call protocol: %s.%s\n'
5536
'Most likely it needs to be updated to support a'
5537
' "timeout" parameter (added in bzr 2.5.0)'
5538
% (e, protocol.__module__, protocol),
5540
protocol(t, host, port, inet)
5148
t = transport.get_transport(url)
5149
protocol(t, host, port, inet)
5543
5152
class cmd_join(Command):
5955
5564
self.add_cleanup(branch.lock_write().unlock)
5957
5566
if tag_name is None:
5958
raise errors.BzrCommandError(gettext("No tag specified to delete."))
5567
raise errors.BzrCommandError("No tag specified to delete.")
5959
5568
branch.tags.delete_tag(tag_name)
5960
note(gettext('Deleted tag %s.') % tag_name)
5569
note('Deleted tag %s.' % tag_name)
5963
5572
if len(revision) != 1:
5964
raise errors.BzrCommandError(gettext(
5573
raise errors.BzrCommandError(
5965
5574
"Tags can only be placed on a single revision, "
5967
5576
revision_id = revision[0].as_revision_id(branch)
5969
5578
revision_id = branch.last_revision()
5970
5579
if tag_name is None:
5971
5580
tag_name = branch.automatic_tag_name(revision_id)
5972
5581
if tag_name is None:
5973
raise errors.BzrCommandError(gettext(
5974
"Please specify a tag name."))
5976
existing_target = branch.tags.lookup_tag(tag_name)
5977
except errors.NoSuchTag:
5978
existing_target = None
5979
if not force and existing_target not in (None, revision_id):
5582
raise errors.BzrCommandError(
5583
"Please specify a tag name.")
5584
if (not force) and branch.tags.has_tag(tag_name):
5980
5585
raise errors.TagAlreadyExists(tag_name)
5981
if existing_target == revision_id:
5982
note(gettext('Tag %s already exists for that revision.') % tag_name)
5984
branch.tags.set_tag(tag_name, revision_id)
5985
if existing_target is None:
5986
note(gettext('Created tag %s.') % tag_name)
5988
note(gettext('Updated tag %s.') % tag_name)
5586
branch.tags.set_tag(tag_name, revision_id)
5587
note('Created tag %s.' % tag_name)
5991
5590
class cmd_tags(Command):
6085
5682
takes_args = ['location?']
6086
5683
takes_options = [
6087
5684
RegistryOption.from_kwargs(
6090
help='The relation between branch and tree.',
5686
title='Target type',
5687
help='The type to reconfigure the directory to.',
6091
5688
value_switches=True, enum_switch=False,
6092
5689
branch='Reconfigure to be an unbound branch with no working tree.',
6093
5690
tree='Reconfigure to be an unbound branch with a working tree.',
6094
5691
checkout='Reconfigure to be a bound branch with a working tree.',
6095
5692
lightweight_checkout='Reconfigure to be a lightweight'
6096
5693
' checkout (with no local history).',
6098
RegistryOption.from_kwargs(
6100
title='Repository type',
6101
help='Location fo the repository.',
6102
value_switches=True, enum_switch=False,
6103
5694
standalone='Reconfigure to be a standalone branch '
6104
5695
'(i.e. stop using shared repository).',
6105
5696
use_shared='Reconfigure to use a shared repository.',
6107
RegistryOption.from_kwargs(
6109
title='Trees in Repository',
6110
help='Whether new branches in the repository have trees.',
6111
value_switches=True, enum_switch=False,
6112
5697
with_trees='Reconfigure repository to create '
6113
5698
'working trees on branches by default.',
6114
5699
with_no_trees='Reconfigure repository to not create '
6141
5726
# At the moment you can use --stacked-on and a different
6142
5727
# reconfiguration shape at the same time; there seems no good reason
6144
if (tree_type is None and
6145
repository_type is None and
6146
repository_trees is None):
5729
if target_type is None:
6147
5730
if stacked_on or unstacked:
6150
raise errors.BzrCommandError(gettext('No target configuration '
6152
reconfiguration = None
6153
if tree_type == 'branch':
5733
raise errors.BzrCommandError('No target configuration '
5735
elif target_type == 'branch':
6154
5736
reconfiguration = reconfigure.Reconfigure.to_branch(directory)
6155
elif tree_type == 'tree':
5737
elif target_type == 'tree':
6156
5738
reconfiguration = reconfigure.Reconfigure.to_tree(directory)
6157
elif tree_type == 'checkout':
5739
elif target_type == 'checkout':
6158
5740
reconfiguration = reconfigure.Reconfigure.to_checkout(
6159
5741
directory, bind_to)
6160
elif tree_type == 'lightweight-checkout':
5742
elif target_type == 'lightweight-checkout':
6161
5743
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
6162
5744
directory, bind_to)
6164
reconfiguration.apply(force)
6165
reconfiguration = None
6166
if repository_type == 'use-shared':
5745
elif target_type == 'use-shared':
6167
5746
reconfiguration = reconfigure.Reconfigure.to_use_shared(directory)
6168
elif repository_type == 'standalone':
5747
elif target_type == 'standalone':
6169
5748
reconfiguration = reconfigure.Reconfigure.to_standalone(directory)
6171
reconfiguration.apply(force)
6172
reconfiguration = None
6173
if repository_trees == 'with-trees':
5749
elif target_type == 'with-trees':
6174
5750
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
6175
5751
directory, True)
6176
elif repository_trees == 'with-no-trees':
5752
elif target_type == 'with-no-trees':
6177
5753
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
6178
5754
directory, False)
6180
reconfiguration.apply(force)
6181
reconfiguration = None
5755
reconfiguration.apply(force)
6184
5758
class cmd_switch(Command):
6219
5793
from bzrlib import switch
6220
5794
tree_location = directory
6221
5795
revision = _get_one_revision('switch', revision)
6222
possible_transports = []
6223
control_dir = controldir.ControlDir.open_containing(tree_location,
6224
possible_transports=possible_transports)[0]
5796
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
6225
5797
if to_location is None:
6226
5798
if revision is None:
6227
raise errors.BzrCommandError(gettext('You must supply either a'
6228
' revision or a location'))
5799
raise errors.BzrCommandError('You must supply either a'
5800
' revision or a location')
6229
5801
to_location = tree_location
6231
branch = control_dir.open_branch(
6232
possible_transports=possible_transports)
5803
branch = control_dir.open_branch()
6233
5804
had_explicit_nick = branch.get_config().has_explicit_nickname()
6234
5805
except errors.NotBranchError:
6236
5807
had_explicit_nick = False
6237
5808
if create_branch:
6238
5809
if branch is None:
6239
raise errors.BzrCommandError(
6240
gettext('cannot create branch without source branch'))
6241
to_location = lookup_new_sibling_branch(control_dir, to_location,
6242
possible_transports=possible_transports)
5810
raise errors.BzrCommandError('cannot create branch without'
5812
to_location = directory_service.directories.dereference(
5814
if '/' not in to_location and '\\' not in to_location:
5815
# This path is meant to be relative to the existing branch
5816
this_url = self._get_branch_location(control_dir)
5817
to_location = urlutils.join(this_url, '..', to_location)
6243
5818
to_branch = branch.bzrdir.sprout(to_location,
6244
possible_transports=possible_transports,
6245
source_branch=branch).open_branch()
5819
possible_transports=[branch.bzrdir.root_transport],
5820
source_branch=branch).open_branch()
6247
to_branch = lookup_sibling_branch(control_dir, to_location)
5823
to_branch = Branch.open(to_location)
5824
except errors.NotBranchError:
5825
this_url = self._get_branch_location(control_dir)
5826
to_branch = Branch.open(
5827
urlutils.join(this_url, '..', to_location))
6248
5828
if revision is not None:
6249
5829
revision = revision.as_revision_id(to_branch)
6250
5830
switch.switch(control_dir, to_branch, force, revision_id=revision)
6251
5831
if had_explicit_nick:
6252
5832
branch = control_dir.open_branch() #get the new branch!
6253
5833
branch.nick = to_branch.nick
6254
note(gettext('Switched to branch: %s'),
5834
note('Switched to branch: %s',
6255
5835
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
5837
def _get_branch_location(self, control_dir):
5838
"""Return location of branch for this control dir."""
5840
this_branch = control_dir.open_branch()
5841
# This may be a heavy checkout, where we want the master branch
5842
master_location = this_branch.get_bound_location()
5843
if master_location is not None:
5844
return master_location
5845
# If not, use a local sibling
5846
return this_branch.base
5847
except errors.NotBranchError:
5848
format = control_dir.find_branch_format()
5849
if getattr(format, 'get_reference', None) is not None:
5850
return format.get_reference(control_dir)
5852
return control_dir.root_transport.base
6259
5855
class cmd_view(Command):
6350
5946
name = current_view
6353
raise errors.BzrCommandError(gettext(
6354
"Both --delete and a file list specified"))
5949
raise errors.BzrCommandError(
5950
"Both --delete and a file list specified")
6356
raise errors.BzrCommandError(gettext(
6357
"Both --delete and --switch specified"))
5952
raise errors.BzrCommandError(
5953
"Both --delete and --switch specified")
6359
5955
tree.views.set_view_info(None, {})
6360
self.outf.write(gettext("Deleted all views.\n"))
5956
self.outf.write("Deleted all views.\n")
6361
5957
elif name is None:
6362
raise errors.BzrCommandError(gettext("No current view to delete"))
5958
raise errors.BzrCommandError("No current view to delete")
6364
5960
tree.views.delete_view(name)
6365
self.outf.write(gettext("Deleted '%s' view.\n") % name)
5961
self.outf.write("Deleted '%s' view.\n" % name)
6368
raise errors.BzrCommandError(gettext(
6369
"Both --switch and a file list specified"))
5964
raise errors.BzrCommandError(
5965
"Both --switch and a file list specified")
6371
raise errors.BzrCommandError(gettext(
6372
"Both --switch and --all specified"))
5967
raise errors.BzrCommandError(
5968
"Both --switch and --all specified")
6373
5969
elif switch == 'off':
6374
5970
if current_view is None:
6375
raise errors.BzrCommandError(gettext("No current view to disable"))
5971
raise errors.BzrCommandError("No current view to disable")
6376
5972
tree.views.set_view_info(None, view_dict)
6377
self.outf.write(gettext("Disabled '%s' view.\n") % (current_view))
5973
self.outf.write("Disabled '%s' view.\n" % (current_view))
6379
5975
tree.views.set_view_info(switch, view_dict)
6380
5976
view_str = views.view_display_str(tree.views.lookup_view())
6381
self.outf.write(gettext("Using '{0}' view: {1}\n").format(switch, view_str))
5977
self.outf.write("Using '%s' view: %s\n" % (switch, view_str))
6384
self.outf.write(gettext('Views defined:\n'))
5980
self.outf.write('Views defined:\n')
6385
5981
for view in sorted(view_dict):
6386
5982
if view == current_view:
6390
5986
view_str = views.view_display_str(view_dict[view])
6391
5987
self.outf.write('%s %-20s %s\n' % (active, view, view_str))
6393
self.outf.write(gettext('No views defined.\n'))
5989
self.outf.write('No views defined.\n')
6394
5990
elif file_list:
6395
5991
if name is None:
6396
5992
# No name given and no current view set
6398
5994
elif name == 'off':
6399
raise errors.BzrCommandError(gettext(
6400
"Cannot change the 'off' pseudo view"))
5995
raise errors.BzrCommandError(
5996
"Cannot change the 'off' pseudo view")
6401
5997
tree.views.set_view(name, sorted(file_list))
6402
5998
view_str = views.view_display_str(tree.views.lookup_view())
6403
self.outf.write(gettext("Using '{0}' view: {1}\n").format(name, view_str))
5999
self.outf.write("Using '%s' view: %s\n" % (name, view_str))
6405
6001
# list the files
6406
6002
if name is None:
6407
6003
# No name given and no current view set
6408
self.outf.write(gettext('No current view.\n'))
6004
self.outf.write('No current view.\n')
6410
6006
view_str = views.view_display_str(tree.views.lookup_view(name))
6411
self.outf.write(gettext("'{0}' view is: {1}\n").format(name, view_str))
6007
self.outf.write("'%s' view is: %s\n" % (name, view_str))
6414
6010
class cmd_hooks(Command):