289
287
from bzrlib.status import show_tree_status
291
289
if revision and len(revision) > 2:
292
raise errors.BzrCommandError(gettext('bzr status --revision takes exactly'
293
' one or two revision specifiers'))
290
raise errors.BzrCommandError('bzr status --revision takes exactly'
291
' one or two revision specifiers')
295
293
tree, relfile_list = WorkingTree.open_containing_paths(file_list)
296
294
# Avoid asking for specific files when that is not needed.
334
332
def run(self, revision_id=None, revision=None, directory=u'.'):
335
333
if revision_id is not None and revision is not None:
336
raise errors.BzrCommandError(gettext('You can only supply one of'
337
' revision_id or --revision'))
334
raise errors.BzrCommandError('You can only supply one of'
335
' revision_id or --revision')
338
336
if revision_id is None and revision is None:
339
raise errors.BzrCommandError(gettext('You must supply either'
340
' --revision or a revision_id'))
337
raise errors.BzrCommandError('You must supply either'
338
' --revision or a revision_id')
342
340
b = bzrdir.BzrDir.open_containing_tree_or_branch(directory)[1]
344
342
revisions = b.repository.revisions
345
343
if revisions is None:
346
raise errors.BzrCommandError(gettext('Repository %r does not support '
347
'access to raw revision texts'))
344
raise errors.BzrCommandError('Repository %r does not support '
345
'access to raw revision texts')
349
347
b.repository.lock_read()
355
353
self.print_revision(revisions, revision_id)
356
354
except errors.NoSuchRevision:
357
msg = gettext("The repository {0} contains no revision {1}.").format(
355
msg = "The repository %s contains no revision %s." % (
358
356
b.repository.base, revision_id)
359
357
raise errors.BzrCommandError(msg)
360
358
elif revision is not None:
361
359
for rev in revision:
363
361
raise errors.BzrCommandError(
364
gettext('You cannot specify a NULL revision.'))
362
'You cannot specify a NULL revision.')
365
363
rev_id = rev.as_revision_id(b)
366
364
self.print_revision(revisions, rev_id)
479
477
working = d.open_workingtree()
480
478
except errors.NoWorkingTree:
481
raise errors.BzrCommandError(gettext("No working tree to remove"))
479
raise errors.BzrCommandError("No working tree to remove")
482
480
except errors.NotLocalUrl:
483
raise errors.BzrCommandError(gettext("You cannot remove the working tree"
484
" of a remote path"))
481
raise errors.BzrCommandError("You cannot remove the working tree"
486
484
if (working.has_changes()):
487
485
raise errors.UncommittedChanges(working)
540
538
tree.reset_state(revision_ids)
541
539
except errors.BzrError, e:
542
540
if revision_ids is None:
543
extra = (gettext(', the header appears corrupt, try passing -r -1'
544
' to set the state to the last commit'))
541
extra = (', the header appears corrupt, try passing -r -1'
542
' to set the state to the last commit')
547
raise errors.BzrCommandError(gettext('failed to reset the tree state{0}').format(extra))
545
raise errors.BzrCommandError('failed to reset the tree state'
550
549
class cmd_revno(Command):
793
784
def run(self, revision=None, show_ids=False, kind=None, file_list=None):
794
785
if kind and kind not in ['file', 'directory', 'symlink']:
795
raise errors.BzrCommandError(gettext('invalid kind %r specified') % (kind,))
786
raise errors.BzrCommandError('invalid kind %r specified' % (kind,))
797
788
revision = _get_one_revision('inventory', revision)
798
789
work_tree, file_list = WorkingTree.open_containing_paths(file_list)
863
853
return self.run_auto(names_list, after, dry_run)
865
raise errors.BzrCommandError(gettext('--dry-run requires --auto.'))
855
raise errors.BzrCommandError('--dry-run requires --auto.')
866
856
if names_list is None:
868
858
if len(names_list) < 2:
869
raise errors.BzrCommandError(gettext("missing file argument"))
859
raise errors.BzrCommandError("missing file argument")
870
860
tree, rel_names = WorkingTree.open_containing_paths(names_list, canonicalize=False)
871
861
self.add_cleanup(tree.lock_tree_write().unlock)
872
862
self._run(tree, names_list, rel_names, after)
874
864
def run_auto(self, names_list, after, dry_run):
875
865
if names_list is not None and len(names_list) > 1:
876
raise errors.BzrCommandError(gettext('Only one path may be specified to'
866
raise errors.BzrCommandError('Only one path may be specified to'
879
raise errors.BzrCommandError(gettext('--after cannot be specified with'
869
raise errors.BzrCommandError('--after cannot be specified with'
881
871
work_tree, file_list = WorkingTree.open_containing_paths(
882
872
names_list, default_directory='.')
883
873
self.add_cleanup(work_tree.lock_tree_write().unlock)
1043
1033
stored_loc = branch_to.get_parent()
1044
1034
if location is None:
1045
1035
if stored_loc is None:
1046
raise errors.BzrCommandError(gettext("No pull location known or"
1036
raise errors.BzrCommandError("No pull location known or"
1049
1039
display_url = urlutils.unescape_for_display(stored_loc,
1050
1040
self.outf.encoding)
1051
1041
if not is_quiet():
1052
self.outf.write(gettext("Using saved parent location: %s\n") % display_url)
1042
self.outf.write("Using saved parent location: %s\n" % display_url)
1053
1043
location = stored_loc
1055
1045
revision = _get_one_revision('pull', revision)
1056
1046
if mergeable is not None:
1057
1047
if revision is not None:
1058
raise errors.BzrCommandError(gettext(
1059
'Cannot use -r with merge directives or bundles'))
1048
raise errors.BzrCommandError(
1049
'Cannot use -r with merge directives or bundles')
1060
1050
mergeable.install_revisions(branch_to.repository)
1061
1051
base_revision_id, revision_id, verified = \
1062
1052
mergeable.get_merge_request(branch_to.repository)
1080
1070
view_info=view_info)
1081
1071
result = tree_to.pull(
1082
1072
branch_from, overwrite, revision_id, change_reporter,
1083
local=local, show_base=show_base)
1073
possible_transports=possible_transports, local=local,
1074
show_base=show_base)
1085
1076
result = branch_to.pull(
1086
1077
branch_from, overwrite, revision_id, local=local)
1117
1108
After that you will be able to do a push without '--overwrite'.
1119
1110
If there is no default push location set, the first push will set it (use
1120
--no-remember to avoid setting it). After that, you can omit the
1111
--no-remember to avoid settting it). After that, you can omit the
1121
1112
location to use the default. To change the default, use --remember. The
1122
1113
value will only be saved if the remote location can be accessed.
1190
1181
# error by the feedback given to them. RBC 20080227.
1191
1182
stacked_on = parent_url
1192
1183
if not stacked_on:
1193
raise errors.BzrCommandError(gettext(
1194
"Could not determine branch to refer to."))
1184
raise errors.BzrCommandError(
1185
"Could not determine branch to refer to.")
1196
1187
# Get the destination location
1197
1188
if location is None:
1198
1189
stored_loc = br_from.get_push_location()
1199
1190
if stored_loc is None:
1200
raise errors.BzrCommandError(gettext(
1201
"No push location known or specified."))
1191
raise errors.BzrCommandError(
1192
"No push location known or specified.")
1203
1194
display_url = urlutils.unescape_for_display(stored_loc,
1204
1195
self.outf.encoding)
1205
note(gettext("Using saved push location: %s") % display_url)
1196
self.outf.write("Using saved push location: %s\n" % display_url)
1206
1197
location = stored_loc
1208
1199
_show_push_branch(br_from, revision_id, location, self.outf,
1315
1306
branch = dir.open_branch()
1316
1307
except errors.NoSuchRevision:
1317
1308
to_transport.delete_tree('.')
1318
msg = gettext("The branch {0} has no revision {1}.").format(
1319
from_location, revision)
1309
msg = "The branch %s has no revision %s." % (from_location,
1320
1311
raise errors.BzrCommandError(msg)
1321
1312
_merge_tags_if_possible(br_from, branch)
1322
1313
# If the source branch is stacked, the new branch may
1323
1314
# be stacked whether we asked for that explicitly or not.
1324
1315
# We therefore need a try/except here and not just 'if stacked:'
1326
note(gettext('Created new stacked branch referring to %s.') %
1317
note('Created new stacked branch referring to %s.' %
1327
1318
branch.get_stacked_on_url())
1328
1319
except (errors.NotStacked, errors.UnstackableBranchFormat,
1329
1320
errors.UnstackableRepositoryFormat), e:
1330
note(ngettext('Branched %d revision.', 'Branched %d revisions.', branch.revno()) % branch.revno())
1321
note('Branched %d revision(s).' % branch.revno())
1332
1323
# Bind to the parent
1333
1324
parent_branch = Branch.open(from_location)
1334
1325
branch.bind(parent_branch)
1335
note(gettext('New branch bound to %s') % from_location)
1326
note('New branch bound to %s' % from_location)
1337
1328
# Switch to the new branch
1338
1329
wt, _ = WorkingTree.open_containing('.')
1339
1330
_mod_switch.switch(wt.bzrdir, branch)
1340
note(gettext('Switched to branch: %s'),
1331
note('Switched to branch: %s',
1341
1332
urlutils.unescape_for_display(branch.base, 'utf-8'))
1344
class cmd_branches(Command):
1345
__doc__ = """List the branches available at the current location.
1347
This command will print the names of all the branches at the current
1351
takes_args = ['location?']
1353
Option('recursive', short_name='R',
1354
help='Recursively scan for branches rather than '
1355
'just looking in the specified location.')]
1357
def run(self, location=".", recursive=False):
1359
t = transport.get_transport(location)
1360
if not t.listable():
1361
raise errors.BzrCommandError(
1362
"Can't scan this type of location.")
1363
for b in bzrdir.BzrDir.find_branches(t):
1364
self.outf.write("%s\n" % urlutils.unescape_for_display(
1365
urlutils.relative_url(t.base, b.base),
1366
self.outf.encoding).rstrip("/"))
1368
dir = bzrdir.BzrDir.open_containing(location)[0]
1369
for branch in dir.list_branches():
1370
if branch.name is None:
1371
self.outf.write(gettext(" (default)\n"))
1373
self.outf.write(" %s\n" % branch.name.encode(
1374
self.outf.encoding))
1377
1335
class cmd_checkout(Command):
1378
1336
__doc__ = """Create a new checkout of an existing branch.
1506
1464
def run(self, dir='.', revision=None, show_base=None):
1507
1465
if revision is not None and len(revision) != 1:
1508
raise errors.BzrCommandError(gettext(
1509
"bzr update --revision takes exactly one revision"))
1466
raise errors.BzrCommandError(
1467
"bzr update --revision takes exactly one revision")
1510
1468
tree = WorkingTree.open_containing(dir)[0]
1511
1469
branch = tree.branch
1512
1470
possible_transports = []
1537
1495
revision_id = branch.last_revision()
1538
1496
if revision_id == _mod_revision.ensure_null(tree.last_revision()):
1539
1497
revno = branch.revision_id_to_dotted_revno(revision_id)
1540
note(gettext("Tree is up to date at revision {0} of branch {1}"
1541
).format('.'.join(map(str, revno)), branch_location))
1498
note("Tree is up to date at revision %s of branch %s" %
1499
('.'.join(map(str, revno)), branch_location))
1543
1501
view_info = _get_view_info_for_change_reporter(tree)
1544
1502
change_reporter = delta._ChangeReporter(
1552
1510
old_tip=old_tip,
1553
1511
show_base=show_base)
1554
1512
except errors.NoSuchRevision, e:
1555
raise errors.BzrCommandError(gettext(
1513
raise errors.BzrCommandError(
1556
1514
"branch has no revision %s\n"
1557
1515
"bzr update --revision only works"
1558
" for a revision in the branch history")
1516
" for a revision in the branch history"
1559
1517
% (e.revision))
1560
1518
revno = tree.branch.revision_id_to_dotted_revno(
1561
1519
_mod_revision.ensure_null(tree.last_revision()))
1562
note(gettext('Updated to revision {0} of branch {1}').format(
1563
'.'.join(map(str, revno)), branch_location))
1520
note('Updated to revision %s of branch %s' %
1521
('.'.join(map(str, revno)), branch_location))
1564
1522
parent_ids = tree.get_parent_ids()
1565
1523
if parent_ids[1:] and parent_ids[1:] != existing_pending_merges:
1566
note(gettext('Your local commits will now show as pending merges with '
1567
"'bzr status', and can be committed with 'bzr commit'."))
1524
note('Your local commits will now show as pending merges with '
1525
"'bzr status', and can be committed with 'bzr commit'.")
1568
1526
if conflicts != 0:
1642
1600
def run(self, file_list, verbose=False, new=False,
1643
1601
file_deletion_strategy='safe'):
1644
1602
if file_deletion_strategy == 'force':
1645
note(gettext("(The --force option is deprecated, rather use --no-backup "
1603
note("(The --force option is deprecated, rather use --no-backup "
1647
1605
file_deletion_strategy = 'no-backup'
1649
1607
tree, file_list = WorkingTree.open_containing_paths(file_list)
1789
1747
last_revision = wt.last_revision()
1791
self.add_cleanup(b.repository.lock_read().unlock)
1792
graph = b.repository.get_graph()
1793
revisions = [revid for revid, parents in
1794
graph.iter_ancestry([last_revision])]
1795
for revision_id in reversed(revisions):
1796
if _mod_revision.is_null(revision_id):
1749
revision_ids = b.repository.get_ancestry(last_revision)
1751
for revision_id in revision_ids:
1798
1752
self.outf.write(revision_id + '\n')
1904
1858
repository = branch.repository
1905
1859
layout = describe_layout(repository, branch, tree).lower()
1906
1860
format = describe_format(a_bzrdir, repository, branch, tree)
1907
self.outf.write(gettext("Created a {0} (format: {1})\n").format(
1861
self.outf.write("Created a %s (format: %s)\n" % (layout, format))
1909
1862
if repository.is_shared():
1910
1863
#XXX: maybe this can be refactored into transport.path_or_url()
1911
1864
url = repository.bzrdir.root_transport.external_url()
2110
2063
elif ':' in prefix:
2111
2064
old_label, new_label = prefix.split(":")
2113
raise errors.BzrCommandError(gettext(
2066
raise errors.BzrCommandError(
2114
2067
'--prefix expects two values separated by a colon'
2115
' (eg "old/:new/")'))
2068
' (eg "old/:new/")')
2117
2070
if revision and len(revision) > 2:
2118
raise errors.BzrCommandError(gettext('bzr diff --revision takes exactly'
2119
' one or two revision specifiers'))
2071
raise errors.BzrCommandError('bzr diff --revision takes exactly'
2072
' one or two revision specifiers')
2121
2074
if using is not None and format is not None:
2122
raise errors.BzrCommandError(gettext(
2123
'{0} and {1} are mutually exclusive').format(
2124
'--using', '--format'))
2075
raise errors.BzrCommandError('--using and --format are mutually '
2126
2078
(old_tree, new_tree,
2127
2079
old_branch, new_branch,
2360
2312
:Other filtering:
2362
The --match option can be used for finding revisions that match a
2363
regular expression in a commit message, committer, author or bug.
2364
Specifying the option several times will match any of the supplied
2365
expressions. --match-author, --match-bugs, --match-committer and
2366
--match-message can be used to only match a specific field.
2314
The --message option can be used for finding revisions that match a
2315
regular expression in a commit message.
2368
2317
:Tips & tricks:
2441
2390
Option('show-diff',
2442
2391
short_name='p',
2443
2392
help='Show changes made in each revision as a patch.'),
2444
Option('include-merged',
2393
Option('include-merges',
2445
2394
help='Show merged revisions like --levels 0 does.'),
2446
Option('include-merges', hidden=True,
2447
help='Historical alias for --include-merged.'),
2448
Option('omit-merges',
2449
help='Do not report commits with more than one parent.'),
2450
2395
Option('exclude-common-ancestry',
2451
2396
help='Display only the revisions that are not part'
2452
2397
' of both ancestries (require -rX..Y)'
2454
Option('signatures',
2455
help='Show digital signature validity'),
2458
help='Show revisions whose properties match this '
2461
ListOption('match-message',
2462
help='Show revisions whose message matches this '
2465
ListOption('match-committer',
2466
help='Show revisions whose committer matches this '
2469
ListOption('match-author',
2470
help='Show revisions whose authors match this '
2473
ListOption('match-bugs',
2474
help='Show revisions whose bugs match this '
2478
2400
encoding_type = 'replace'
2507
2421
_get_info_for_log_files,
2509
2423
direction = (forward and 'forward') or 'reverse'
2510
if symbol_versioning.deprecated_passed(include_merges):
2511
ui.ui_factory.show_user_warning(
2512
'deprecated_command_option',
2513
deprecated_name='--include-merges',
2514
recommended_name='--include-merged',
2515
deprecated_in_version='2.5',
2516
command=self.invoked_as)
2517
if include_merged is None:
2518
include_merged = include_merges
2520
raise errors.BzrCommandError(gettext(
2521
'{0} and {1} are mutually exclusive').format(
2522
'--include-merges', '--include-merged'))
2523
if include_merged is None:
2524
include_merged = False
2525
2424
if (exclude_common_ancestry
2526
2425
and (revision is None or len(revision) != 2)):
2527
raise errors.BzrCommandError(gettext(
2528
'--exclude-common-ancestry requires -r with two revisions'))
2426
raise errors.BzrCommandError(
2427
'--exclude-common-ancestry requires -r with two revisions')
2530
2429
if levels is None:
2533
raise errors.BzrCommandError(gettext(
2534
'{0} and {1} are mutually exclusive').format(
2535
'--levels', '--include-merged'))
2432
raise errors.BzrCommandError(
2433
'--levels and --include-merges are mutually exclusive')
2537
2435
if change is not None:
2538
2436
if len(change) > 1:
2539
2437
raise errors.RangeInChangeOption()
2540
2438
if revision is not None:
2541
raise errors.BzrCommandError(gettext(
2542
'{0} and {1} are mutually exclusive').format(
2543
'--revision', '--change'))
2439
raise errors.BzrCommandError(
2440
'--revision and --change are mutually exclusive')
2545
2442
revision = change
2552
2449
revision, file_list, self.add_cleanup)
2553
2450
for relpath, file_id, kind in file_info_list:
2554
2451
if file_id is None:
2555
raise errors.BzrCommandError(gettext(
2556
"Path unknown at end or start of revision range: %s") %
2452
raise errors.BzrCommandError(
2453
"Path unknown at end or start of revision range: %s" %
2558
2455
# If the relpath is the top of the tree, we log everything
2559
2456
if relpath == '':
2576
2473
self.add_cleanup(b.lock_read().unlock)
2577
2474
rev1, rev2 = _get_revision_range(revision, b, self.name())
2579
if b.get_config().validate_signatures_in_log():
2583
if not gpg.GPGStrategy.verify_signatures_available():
2584
raise errors.GpgmeNotInstalled(None)
2586
2476
# Decide on the type of delta & diff filtering to use
2587
2477
# TODO: add an --all-files option to make this configurable & consistent
2588
2478
if not verbose:
2645
2523
start_revision=rev1, end_revision=rev2, limit=limit,
2646
2524
message_search=message, delta_type=delta_type,
2647
2525
diff_type=diff_type, _match_using_deltas=match_using_deltas,
2648
exclude_common_ancestry=exclude_common_ancestry, match=match_dict,
2649
signature=signatures, omit_merges=omit_merges,
2526
exclude_common_ancestry=exclude_common_ancestry,
2651
2528
Logger(b, rqst).show(lf)
2669
2546
# b is taken from revision[0].get_branch(), and
2670
2547
# show_log will use its revision_history. Having
2671
2548
# different branches will lead to weird behaviors.
2672
raise errors.BzrCommandError(gettext(
2549
raise errors.BzrCommandError(
2673
2550
"bzr %s doesn't accept two revisions in different"
2674
" branches.") % command_name)
2551
" branches." % command_name)
2675
2552
if start_spec.spec is None:
2676
2553
# Avoid loading all the history.
2677
2554
rev1 = RevisionInfo(branch, None, None)
2763
2640
null=False, kind=None, show_ids=False, path=None, directory=None):
2765
2642
if kind and kind not in ('file', 'directory', 'symlink'):
2766
raise errors.BzrCommandError(gettext('invalid kind specified'))
2643
raise errors.BzrCommandError('invalid kind specified')
2768
2645
if verbose and null:
2769
raise errors.BzrCommandError(gettext('Cannot set both --verbose and --null'))
2646
raise errors.BzrCommandError('Cannot set both --verbose and --null')
2770
2647
all = not (unknown or versioned or ignored)
2772
2649
selection = {'I':ignored, '?':unknown, 'V':versioned}
2951
2828
self.outf.write("%s\n" % pattern)
2953
2830
if not name_pattern_list:
2954
raise errors.BzrCommandError(gettext("ignore requires at least one "
2955
"NAME_PATTERN or --default-rules."))
2831
raise errors.BzrCommandError("ignore requires at least one "
2832
"NAME_PATTERN or --default-rules.")
2956
2833
name_pattern_list = [globbing.normalize_pattern(p)
2957
2834
for p in name_pattern_list]
2958
2835
bad_patterns = ''
2959
bad_patterns_count = 0
2960
2836
for p in name_pattern_list:
2961
2837
if not globbing.Globster.is_pattern_valid(p):
2962
bad_patterns_count += 1
2963
2838
bad_patterns += ('\n %s' % p)
2964
2839
if bad_patterns:
2965
msg = (ngettext('Invalid ignore pattern found. %s',
2966
'Invalid ignore patterns found. %s',
2967
bad_patterns_count) % bad_patterns)
2840
msg = ('Invalid ignore pattern(s) found. %s' % bad_patterns)
2968
2841
ui.ui_factory.show_error(msg)
2969
2842
raise errors.InvalidPattern('')
2970
2843
for name_pattern in name_pattern_list:
2971
2844
if (name_pattern[0] == '/' or
2972
2845
(len(name_pattern) > 1 and name_pattern[1] == ':')):
2973
raise errors.BzrCommandError(gettext(
2974
"NAME_PATTERN should not be an absolute path"))
2846
raise errors.BzrCommandError(
2847
"NAME_PATTERN should not be an absolute path")
2975
2848
tree, relpath = WorkingTree.open_containing(directory)
2976
2849
ignores.tree_ignores_add_patterns(tree, name_pattern_list)
2977
2850
ignored = globbing.Globster(name_pattern_list)
2984
2857
if ignored.match(filename):
2985
2858
matches.append(filename)
2986
2859
if len(matches) > 0:
2987
self.outf.write(gettext("Warning: the following files are version "
2988
"controlled and match your ignore pattern:\n%s"
2860
self.outf.write("Warning: the following files are version controlled and"
2861
" match your ignore pattern:\n%s"
2989
2862
"\nThese files will continue to be version controlled"
2990
" unless you 'bzr remove' them.\n") % ("\n".join(matches),))
2863
" unless you 'bzr remove' them.\n" % ("\n".join(matches),))
2993
2866
class cmd_ignored(Command):
3099
2972
export(rev_tree, dest, format, root, subdir, filtered=filters,
3100
2973
per_file_timestamps=per_file_timestamps)
3101
2974
except errors.NoSuchExportFormat, e:
3102
raise errors.BzrCommandError(gettext('Unsupported export format: %s') % e.format)
2975
raise errors.BzrCommandError('Unsupported export format: %s' % e.format)
3105
2978
class cmd_cat(Command):
3125
2998
def run(self, filename, revision=None, name_from_revision=False,
3126
2999
filters=False, directory=None):
3127
3000
if revision is not None and len(revision) != 1:
3128
raise errors.BzrCommandError(gettext("bzr cat --revision takes exactly"
3129
" one revision specifier"))
3001
raise errors.BzrCommandError("bzr cat --revision takes exactly"
3002
" one revision specifier")
3130
3003
tree, branch, relpath = \
3131
3004
_open_directory_or_containing_tree_or_branch(filename, directory)
3132
3005
self.add_cleanup(branch.lock_read().unlock)
3143
3016
old_file_id = rev_tree.path2id(relpath)
3145
# TODO: Split out this code to something that generically finds the
3146
# best id for a path across one or more trees; it's like
3147
# find_ids_across_trees but restricted to find just one. -- mbp
3149
3018
if name_from_revision:
3150
3019
# Try in revision if requested
3151
3020
if old_file_id is None:
3152
raise errors.BzrCommandError(gettext(
3153
"{0!r} is not present in revision {1}").format(
3021
raise errors.BzrCommandError(
3022
"%r is not present in revision %s" % (
3154
3023
filename, rev_tree.get_revision_id()))
3156
actual_file_id = old_file_id
3025
content = rev_tree.get_file_text(old_file_id)
3158
3027
cur_file_id = tree.path2id(relpath)
3159
if cur_file_id is not None and rev_tree.has_id(cur_file_id):
3160
actual_file_id = cur_file_id
3161
elif old_file_id is not None:
3162
actual_file_id = old_file_id
3164
raise errors.BzrCommandError(gettext(
3165
"{0!r} is not present in revision {1}").format(
3029
if cur_file_id is not None:
3030
# Then try with the actual file id
3032
content = rev_tree.get_file_text(cur_file_id)
3034
except errors.NoSuchId:
3035
# The actual file id didn't exist at that time
3037
if not found and old_file_id is not None:
3038
# Finally try with the old file id
3039
content = rev_tree.get_file_text(old_file_id)
3042
# Can't be found anywhere
3043
raise errors.BzrCommandError(
3044
"%r is not present in revision %s" % (
3166
3045
filename, rev_tree.get_revision_id()))
3168
from bzrlib.filter_tree import ContentFilterTree
3169
filter_tree = ContentFilterTree(rev_tree,
3170
rev_tree._content_filter_stack)
3171
content = filter_tree.get_file_text(actual_file_id)
3047
from bzrlib.filters import (
3048
ContentFilterContext,
3049
filtered_output_bytes,
3051
filters = rev_tree._content_filter_stack(relpath)
3052
chunks = content.splitlines(True)
3053
content = filtered_output_bytes(chunks, filters,
3054
ContentFilterContext(relpath, rev_tree))
3056
self.outf.writelines(content)
3173
content = rev_tree.get_file_text(actual_file_id)
3175
self.outf.write(content)
3059
self.outf.write(content)
3178
3062
class cmd_local_time_offset(Command):
3285
3169
aliases = ['ci', 'checkin']
3287
3171
def _iter_bug_fix_urls(self, fixes, branch):
3288
default_bugtracker = None
3289
3172
# Configure the properties for bug fixing attributes.
3290
3173
for fixed_bug in fixes:
3291
3174
tokens = fixed_bug.split(':')
3292
if len(tokens) == 1:
3293
if default_bugtracker is None:
3294
branch_config = branch.get_config()
3295
default_bugtracker = branch_config.get_user_option(
3297
if default_bugtracker is None:
3298
raise errors.BzrCommandError(gettext(
3299
"No tracker specified for bug %s. Use the form "
3300
"'tracker:id' or specify a default bug tracker "
3301
"using the `bugtracker` option.\nSee "
3302
"\"bzr help bugs\" for more information on this "
3303
"feature. Commit refused.") % fixed_bug)
3304
tag = default_bugtracker
3306
elif len(tokens) != 2:
3307
raise errors.BzrCommandError(gettext(
3175
if len(tokens) != 2:
3176
raise errors.BzrCommandError(
3308
3177
"Invalid bug %s. Must be in the form of 'tracker:id'. "
3309
3178
"See \"bzr help bugs\" for more information on this "
3310
"feature.\nCommit refused.") % fixed_bug)
3312
tag, bug_id = tokens
3179
"feature.\nCommit refused." % fixed_bug)
3180
tag, bug_id = tokens
3314
3182
yield bugtracker.get_bug_url(tag, branch, bug_id)
3315
3183
except errors.UnknownBugTrackerAbbreviation:
3316
raise errors.BzrCommandError(gettext(
3317
'Unrecognized bug %s. Commit refused.') % fixed_bug)
3184
raise errors.BzrCommandError(
3185
'Unrecognized bug %s. Commit refused.' % fixed_bug)
3318
3186
except errors.MalformedBugIdentifier, e:
3319
raise errors.BzrCommandError(gettext(
3320
"%s\nCommit refused.") % (str(e),))
3187
raise errors.BzrCommandError(
3188
"%s\nCommit refused." % (str(e),))
3322
3190
def run(self, message=None, file=None, verbose=False, selected_list=None,
3323
3191
unchanged=False, strict=False, local=False, fixes=None,
3380
3247
message = message.replace('\r\n', '\n')
3381
3248
message = message.replace('\r', '\n')
3383
raise errors.BzrCommandError(gettext(
3384
"please specify either --message or --file"))
3250
raise errors.BzrCommandError(
3251
"please specify either --message or --file")
3386
3253
def get_message(commit_obj):
3387
3254
"""Callback to get commit message"""
3404
3271
# make_commit_message_template_encoded returns user encoding.
3405
3272
# We probably want to be using edit_commit_message instead to
3407
my_message = set_commit_message(commit_obj)
3408
if my_message is None:
3409
start_message = generate_commit_message_template(commit_obj)
3410
my_message = edit_commit_message_encoded(text,
3411
start_message=start_message)
3412
if my_message is None:
3413
raise errors.BzrCommandError(gettext("please specify a commit"
3414
" message with either --message or --file"))
3415
if my_message == "":
3416
raise errors.BzrCommandError(gettext("Empty commit message specified."
3417
" Please specify a commit message with either"
3418
" --message or --file or leave a blank message"
3419
" with --message \"\"."))
3274
start_message = generate_commit_message_template(commit_obj)
3275
my_message = edit_commit_message_encoded(text,
3276
start_message=start_message)
3277
if my_message is None:
3278
raise errors.BzrCommandError("please specify a commit"
3279
" message with either --message or --file")
3280
if my_message == "":
3281
raise errors.BzrCommandError("empty commit message specified")
3420
3282
return my_message
3422
3284
# The API permits a commit with a filter of [] to mean 'select nothing'
3433
3295
exclude=tree.safe_relpath_files(exclude),
3435
3297
except PointlessCommit:
3436
raise errors.BzrCommandError(gettext("No changes to commit."
3298
raise errors.BzrCommandError("No changes to commit."
3437
3299
" Please 'bzr add' the files you want to commit, or use"
3438
" --unchanged to force an empty commit."))
3300
" --unchanged to force an empty commit.")
3439
3301
except ConflictsInTree:
3440
raise errors.BzrCommandError(gettext('Conflicts detected in working '
3302
raise errors.BzrCommandError('Conflicts detected in working '
3441
3303
'tree. Use "bzr conflicts" to list, "bzr resolve FILE" to'
3443
3305
except StrictCommitFailed:
3444
raise errors.BzrCommandError(gettext("Commit refused because there are"
3445
" unknown files in the working tree."))
3306
raise errors.BzrCommandError("Commit refused because there are"
3307
" unknown files in the working tree.")
3446
3308
except errors.BoundBranchOutOfDate, e:
3447
e.extra_help = (gettext("\n"
3309
e.extra_help = ("\n"
3448
3310
'To commit to master branch, run update and then commit.\n'
3449
3311
'You can also pass --local to commit to continue working '
3707
3569
def remove_alias(self, alias_name):
3708
3570
if alias_name is None:
3709
raise errors.BzrCommandError(gettext(
3710
'bzr alias --remove expects an alias to remove.'))
3571
raise errors.BzrCommandError(
3572
'bzr alias --remove expects an alias to remove.')
3711
3573
# If alias is not found, print something like:
3712
3574
# unalias: foo: not found
3713
3575
c = _mod_config.GlobalConfig()
3867
3726
first=False, list_only=False,
3868
3727
randomize=None, exclude=None, strict=False,
3869
3728
load_list=None, debugflag=None, starting_with=None, subunit=False,
3870
parallel=None, lsprof_tests=False,
3729
parallel=None, lsprof_tests=False):
3872
3730
from bzrlib import tests
3874
3732
if testspecs_list is not None:
3880
3738
from bzrlib.tests import SubUnitBzrRunner
3881
3739
except ImportError:
3882
raise errors.BzrCommandError(gettext("subunit not available. subunit "
3883
"needs to be installed to use --subunit."))
3740
raise errors.BzrCommandError("subunit not available. subunit "
3741
"needs to be installed to use --subunit.")
3884
3742
self.additional_selftest_args['runner_class'] = SubUnitBzrRunner
3885
3743
# On Windows, disable automatic conversion of '\n' to '\r\n' in
3886
3744
# stdout, which would corrupt the subunit stream.
3895
3753
self.additional_selftest_args.setdefault(
3896
3754
'suite_decorators', []).append(parallel)
3898
raise errors.BzrCommandError(gettext(
3756
raise errors.BzrCommandError(
3899
3757
"--benchmark is no longer supported from bzr 2.2; "
3900
"use bzr-usertest instead"))
3758
"use bzr-usertest instead")
3901
3759
test_suite_factory = None
3902
3760
if not exclude:
3903
3761
exclude_pattern = None
3905
3763
exclude_pattern = '(' + '|'.join(exclude) + ')'
3907
self._disable_fsync()
3908
3764
selftest_kwargs = {"verbose": verbose,
3909
3765
"pattern": pattern,
3910
3766
"stop_on_failure": one,
3933
3789
return int(not result)
3935
def _disable_fsync(self):
3936
"""Change the 'os' functionality to not synchronize."""
3937
self._orig_fsync = getattr(os, 'fsync', None)
3938
if self._orig_fsync is not None:
3939
os.fsync = lambda filedes: None
3940
self._orig_fdatasync = getattr(os, 'fdatasync', None)
3941
if self._orig_fdatasync is not None:
3942
os.fdatasync = lambda filedes: None
3945
3792
class cmd_version(Command):
3946
3793
__doc__ = """Show version of bzr."""
4029
3876
Use bzr resolve when you have fixed a problem. See also bzr conflicts.
4031
3878
If there is no default branch set, the first merge will set it (use
4032
--no-remember to avoid setting it). After that, you can omit the branch
3879
--no-remember to avoid settting it). After that, you can omit the branch
4033
3880
to use the default. To change the default, use --remember. The value will
4034
3881
only be saved if the remote location can be accessed.
4038
3885
committed to record the result of the merge.
4040
3887
merge refuses to run if there are any uncommitted changes, unless
4041
--force is given. If --force is given, then the changes from the source
4042
will be merged with the current working tree, including any uncommitted
4043
changes in the tree. The --force option can also be used to create a
3888
--force is given. The --force option can also be used to create a
4044
3889
merge revision which has more than two parents.
4046
3891
If one would like to merge changes from the working tree of the other
4122
3967
tree = WorkingTree.open_containing(directory)[0]
4123
3968
if tree.branch.revno() == 0:
4124
raise errors.BzrCommandError(gettext('Merging into empty branches not currently supported, '
4125
'https://bugs.launchpad.net/bzr/+bug/308562'))
3969
raise errors.BzrCommandError('Merging into empty branches not currently supported, '
3970
'https://bugs.launchpad.net/bzr/+bug/308562')
4128
3973
basis_tree = tree.revision_tree(tree.last_revision())
4148
3993
mergeable = None
4150
3995
if uncommitted:
4151
raise errors.BzrCommandError(gettext('Cannot use --uncommitted'
4152
' with bundles or merge directives.'))
3996
raise errors.BzrCommandError('Cannot use --uncommitted'
3997
' with bundles or merge directives.')
4154
3999
if revision is not None:
4155
raise errors.BzrCommandError(gettext(
4156
'Cannot use -r with merge directives or bundles'))
4000
raise errors.BzrCommandError(
4001
'Cannot use -r with merge directives or bundles')
4157
4002
merger, verified = _mod_merge.Merger.from_mergeable(tree,
4158
4003
mergeable, None)
4160
4005
if merger is None and uncommitted:
4161
4006
if revision is not None and len(revision) > 0:
4162
raise errors.BzrCommandError(gettext('Cannot use --uncommitted and'
4163
' --revision at the same time.'))
4007
raise errors.BzrCommandError('Cannot use --uncommitted and'
4008
' --revision at the same time.')
4164
4009
merger = self.get_merger_from_uncommitted(tree, location, None)
4165
4010
allow_pending = False
4179
4024
if merger.interesting_files:
4180
4025
if not merger.other_tree.has_filename(
4181
4026
merger.interesting_files[0]):
4182
note(gettext("merger: ") + str(merger))
4027
note("merger: " + str(merger))
4183
4028
raise errors.PathsDoNotExist([location])
4184
note(gettext('Nothing to do.'))
4029
note('Nothing to do.')
4186
4031
if pull and not preview:
4187
4032
if merger.interesting_files is not None:
4188
raise errors.BzrCommandError(gettext('Cannot pull individual files'))
4033
raise errors.BzrCommandError('Cannot pull individual files')
4189
4034
if (merger.base_rev_id == tree.last_revision()):
4190
4035
result = tree.pull(merger.other_branch, False,
4191
4036
merger.other_rev_id)
4192
4037
result.report(self.outf)
4194
4039
if merger.this_basis is None:
4195
raise errors.BzrCommandError(gettext(
4040
raise errors.BzrCommandError(
4196
4041
"This branch has no commits."
4197
" (perhaps you would prefer 'bzr pull')"))
4042
" (perhaps you would prefer 'bzr pull')")
4199
4044
return self._do_preview(merger)
4200
4045
elif interactive:
4260
4105
# Use reprocess if the merger supports it
4261
4106
merger.reprocess = merger.merge_type.supports_reprocess
4262
4107
if merger.reprocess and not merger.merge_type.supports_reprocess:
4263
raise errors.BzrCommandError(gettext("Conflict reduction is not supported"
4264
" for merge type %s.") %
4108
raise errors.BzrCommandError("Conflict reduction is not supported"
4109
" for merge type %s." %
4265
4110
merger.merge_type)
4266
4111
if merger.reprocess and merger.show_base:
4267
raise errors.BzrCommandError(gettext("Cannot do conflict reduction and"
4112
raise errors.BzrCommandError("Cannot do conflict reduction and"
4270
4115
def _get_merger_from_branch(self, tree, location, revision, remember,
4271
4116
possible_transports, pb):
4375
4220
stored_location_type = "parent"
4376
4221
mutter("%s", stored_location)
4377
4222
if stored_location is None:
4378
raise errors.BzrCommandError(gettext("No location specified or remembered"))
4223
raise errors.BzrCommandError("No location specified or remembered")
4379
4224
display_url = urlutils.unescape_for_display(stored_location, 'utf-8')
4380
note(gettext("{0} remembered {1} location {2}").format(verb_string,
4381
stored_location_type, display_url))
4225
note(u"%s remembered %s location %s", verb_string,
4226
stored_location_type, display_url)
4382
4227
return stored_location
4648
4493
type=_parse_revision_str,
4649
4494
help='Filter on local branch revisions (inclusive). '
4650
4495
'See "help revisionspec" for details.'),
4651
Option('include-merged',
4496
Option('include-merges',
4652
4497
'Show all revisions in addition to the mainline ones.'),
4653
Option('include-merges', hidden=True,
4654
help='Historical alias for --include-merged.'),
4656
4499
encoding_type = 'replace'
4660
4503
theirs_only=False,
4661
4504
log_format=None, long=False, short=False, line=False,
4662
4505
show_ids=False, verbose=False, this=False, other=False,
4663
include_merged=None, revision=None, my_revision=None,
4665
include_merges=symbol_versioning.DEPRECATED_PARAMETER):
4506
include_merges=False, revision=None, my_revision=None,
4666
4508
from bzrlib.missing import find_unmerged, iter_log_revisions
4667
4509
def message(s):
4668
4510
if not is_quiet():
4669
4511
self.outf.write(s)
4671
if symbol_versioning.deprecated_passed(include_merges):
4672
ui.ui_factory.show_user_warning(
4673
'deprecated_command_option',
4674
deprecated_name='--include-merges',
4675
recommended_name='--include-merged',
4676
deprecated_in_version='2.5',
4677
command=self.invoked_as)
4678
if include_merged is None:
4679
include_merged = include_merges
4681
raise errors.BzrCommandError(gettext(
4682
'{0} and {1} are mutually exclusive').format(
4683
'--include-merges', '--include-merged'))
4684
if include_merged is None:
4685
include_merged = False
4687
4514
mine_only = this
4727
4554
local_extra, remote_extra = find_unmerged(
4728
4555
local_branch, remote_branch, restrict,
4729
4556
backward=not reverse,
4730
include_merged=include_merged,
4557
include_merges=include_merges,
4731
4558
local_revid_range=local_revid_range,
4732
4559
remote_revid_range=remote_revid_range)
4756
4581
if remote_extra and not mine_only:
4757
4582
if printed_local is True:
4758
4583
message("\n\n\n")
4759
message(ngettext("You are missing %d revision:\n",
4760
"You are missing %d revisions:\n",
4761
len(remote_extra)) %
4584
message("You are missing %d revision(s):\n" %
4762
4585
len(remote_extra))
4763
4586
for revision in iter_log_revisions(remote_extra,
4764
4587
remote_branch.repository,
4769
4592
if mine_only and not local_extra:
4770
4593
# We checked local, and found nothing extra
4771
message(gettext('This branch has no new revisions.\n'))
4594
message('This branch is up to date.\n')
4772
4595
elif theirs_only and not remote_extra:
4773
4596
# We checked remote, and found nothing extra
4774
message(gettext('Other branch has no new revisions.\n'))
4597
message('Other branch is up to date.\n')
4775
4598
elif not (mine_only or theirs_only or local_extra or
4777
4600
# We checked both branches, and neither one had extra
4779
message(gettext("Branches are up to date.\n"))
4602
message("Branches are up to date.\n")
4780
4603
self.cleanup_now()
4781
4604
if not status_code and parent is None and other_branch is not None:
4782
4605
self.add_cleanup(local_branch.lock_write().unlock)
4944
4767
def run(self, revision_id_list=None, revision=None, directory=u'.'):
4945
4768
if revision_id_list is not None and revision is not None:
4946
raise errors.BzrCommandError(gettext('You can only supply one of revision_id or --revision'))
4769
raise errors.BzrCommandError('You can only supply one of revision_id or --revision')
4947
4770
if revision_id_list is None and revision is None:
4948
raise errors.BzrCommandError(gettext('You must supply either --revision or a revision_id'))
4771
raise errors.BzrCommandError('You must supply either --revision or a revision_id')
4949
4772
b = WorkingTree.open_containing(directory)[0].branch
4950
4773
self.add_cleanup(b.lock_write().unlock)
4951
4774
return self._run(b, revision_id_list, revision)
5021
4844
location = b.get_old_bound_location()
5022
4845
except errors.UpgradeRequired:
5023
raise errors.BzrCommandError(gettext('No location supplied. '
5024
'This format does not remember old locations.'))
4846
raise errors.BzrCommandError('No location supplied. '
4847
'This format does not remember old locations.')
5026
4849
if location is None:
5027
4850
if b.get_bound_location() is not None:
5028
raise errors.BzrCommandError(gettext('Branch is already bound'))
4851
raise errors.BzrCommandError('Branch is already bound')
5030
raise errors.BzrCommandError(gettext('No location supplied '
5031
'and no previous location known'))
4853
raise errors.BzrCommandError('No location supplied '
4854
'and no previous location known')
5032
4855
b_other = Branch.open(location)
5034
4857
b.bind(b_other)
5035
4858
except errors.DivergedBranches:
5036
raise errors.BzrCommandError(gettext('These branches have diverged.'
5037
' Try merging, and then bind again.'))
4859
raise errors.BzrCommandError('These branches have diverged.'
4860
' Try merging, and then bind again.')
5038
4861
if b.get_config().has_explicit_nickname():
5039
4862
b.nick = b_other.nick
5080
4903
takes_options = ['verbose', 'revision',
5081
4904
Option('dry-run', help='Don\'t actually make changes.'),
5082
4905
Option('force', help='Say yes to all questions.'),
5084
help='Keep tags that point to removed revisions.'),
5085
4906
Option('local',
5086
4907
help="Only remove the commits from the local branch"
5087
4908
" when in a checkout."
5092
4913
encoding_type = 'replace'
5094
def run(self, location=None, dry_run=False, verbose=False,
5095
revision=None, force=False, local=False, keep_tags=False):
4915
def run(self, location=None,
4916
dry_run=False, verbose=False,
4917
revision=None, force=False, local=False):
5096
4918
if location is None:
5097
4919
location = u'.'
5098
4920
control, relpath = bzrdir.BzrDir.open_containing(location)
5107
4929
self.add_cleanup(tree.lock_write().unlock)
5109
4931
self.add_cleanup(b.lock_write().unlock)
5110
return self._run(b, tree, dry_run, verbose, revision, force,
4932
return self._run(b, tree, dry_run, verbose, revision, force, local=local)
5113
def _run(self, b, tree, dry_run, verbose, revision, force, local,
4934
def _run(self, b, tree, dry_run, verbose, revision, force, local=False):
5115
4935
from bzrlib.log import log_formatter, show_log
5116
4936
from bzrlib.uncommit import uncommit
5147
4967
end_revision=last_revno)
5150
self.outf.write(gettext('Dry-run, pretending to remove'
5151
' the above revisions.\n'))
4970
self.outf.write('Dry-run, pretending to remove'
4971
' the above revisions.\n')
5153
self.outf.write(gettext('The above revision(s) will be removed.\n'))
4973
self.outf.write('The above revision(s) will be removed.\n')
5156
4976
if not ui.ui_factory.confirm_action(
5157
gettext(u'Uncommit these revisions'),
4977
u'Uncommit these revisions',
5158
4978
'bzrlib.builtins.uncommit',
5160
self.outf.write(gettext('Canceled\n'))
4980
self.outf.write('Canceled\n')
5163
4983
mutter('Uncommitting from {%s} to {%s}',
5164
4984
last_rev_id, rev_id)
5165
4985
uncommit(b, tree=tree, dry_run=dry_run, verbose=verbose,
5166
revno=revno, local=local, keep_tags=keep_tags)
5167
self.outf.write(gettext('You can restore the old tip by running:\n'
5168
' bzr pull . -r revid:%s\n') % last_rev_id)
4986
revno=revno, local=local)
4987
self.outf.write('You can restore the old tip by running:\n'
4988
' bzr pull . -r revid:%s\n' % last_rev_id)
5171
4991
class cmd_break_lock(Command):
5290
5108
if not allow_writes:
5291
5109
url = 'readonly+' + url
5292
5110
t = transport.get_transport(url)
5294
protocol(t, host, port, inet, client_timeout)
5295
except TypeError, e:
5296
# We use symbol_versioning.deprecated_in just so that people
5297
# grepping can find it here.
5298
# symbol_versioning.deprecated_in((2, 5, 0))
5299
symbol_versioning.warn(
5300
'Got TypeError(%s)\ntrying to call protocol: %s.%s\n'
5301
'Most likely it needs to be updated to support a'
5302
' "timeout" parameter (added in bzr 2.5.0)'
5303
% (e, protocol.__module__, protocol),
5305
protocol(t, host, port, inet)
5111
protocol(t, host, port, inet)
5308
5114
class cmd_join(Command):
5331
5137
containing_tree = WorkingTree.open_containing(parent_dir)[0]
5332
5138
repo = containing_tree.branch.repository
5333
5139
if not repo.supports_rich_root():
5334
raise errors.BzrCommandError(gettext(
5140
raise errors.BzrCommandError(
5335
5141
"Can't join trees because %s doesn't support rich root data.\n"
5336
"You can use bzr upgrade on the repository.")
5142
"You can use bzr upgrade on the repository."
5341
5147
except errors.BadReferenceTarget, e:
5342
5148
# XXX: Would be better to just raise a nicely printable
5343
5149
# exception from the real origin. Also below. mbp 20070306
5344
raise errors.BzrCommandError(
5345
gettext("Cannot join {0}. {1}").format(tree, e.reason))
5150
raise errors.BzrCommandError("Cannot join %s. %s" %
5348
5154
containing_tree.subsume(sub_tree)
5349
5155
except errors.BadSubsumeSource, e:
5350
raise errors.BzrCommandError(
5351
gettext("Cannot join {0}. {1}").format(tree, e.reason))
5156
raise errors.BzrCommandError("Cannot join %s. %s" %
5354
5160
class cmd_split(Command):
5446
5252
elif stored_public_branch is None:
5447
5253
branch.set_public_branch(public_branch)
5448
5254
if not include_bundle and public_branch is None:
5449
raise errors.BzrCommandError(gettext('No public branch specified or'
5255
raise errors.BzrCommandError('No public branch specified or'
5451
5257
base_revision_id = None
5452
5258
if revision is not None:
5453
5259
if len(revision) > 2:
5454
raise errors.BzrCommandError(gettext('bzr merge-directive takes '
5455
'at most two one revision identifiers'))
5260
raise errors.BzrCommandError('bzr merge-directive takes '
5261
'at most two one revision identifiers')
5456
5262
revision_id = revision[-1].as_revision_id(branch)
5457
5263
if len(revision) == 2:
5458
5264
base_revision_id = revision[0].as_revision_id(branch)
5460
5266
revision_id = branch.last_revision()
5461
5267
revision_id = ensure_null(revision_id)
5462
5268
if revision_id == NULL_REVISION:
5463
raise errors.BzrCommandError(gettext('No revisions to bundle.'))
5269
raise errors.BzrCommandError('No revisions to bundle.')
5464
5270
directive = merge_directive.MergeDirective2.from_objects(
5465
5271
branch.repository, revision_id, time.time(),
5466
5272
osutils.local_time_offset(), submit_branch,
5513
5319
Both the submit branch and the public branch follow the usual behavior with
5514
5320
respect to --remember: If there is no default location set, the first send
5515
will set it (use --no-remember to avoid setting it). After that, you can
5321
will set it (use --no-remember to avoid settting it). After that, you can
5516
5322
omit the location to use the default. To change the default, use
5517
5323
--remember. The value will only be saved if the location can be accessed.
5720
5526
self.add_cleanup(branch.lock_write().unlock)
5722
5528
if tag_name is None:
5723
raise errors.BzrCommandError(gettext("No tag specified to delete."))
5529
raise errors.BzrCommandError("No tag specified to delete.")
5724
5530
branch.tags.delete_tag(tag_name)
5725
note(gettext('Deleted tag %s.') % tag_name)
5531
note('Deleted tag %s.' % tag_name)
5728
5534
if len(revision) != 1:
5729
raise errors.BzrCommandError(gettext(
5535
raise errors.BzrCommandError(
5730
5536
"Tags can only be placed on a single revision, "
5732
5538
revision_id = revision[0].as_revision_id(branch)
5734
5540
revision_id = branch.last_revision()
5735
5541
if tag_name is None:
5736
5542
tag_name = branch.automatic_tag_name(revision_id)
5737
5543
if tag_name is None:
5738
raise errors.BzrCommandError(gettext(
5739
"Please specify a tag name."))
5741
existing_target = branch.tags.lookup_tag(tag_name)
5742
except errors.NoSuchTag:
5743
existing_target = None
5744
if not force and existing_target not in (None, revision_id):
5544
raise errors.BzrCommandError(
5545
"Please specify a tag name.")
5546
if (not force) and branch.tags.has_tag(tag_name):
5745
5547
raise errors.TagAlreadyExists(tag_name)
5746
if existing_target == revision_id:
5747
note(gettext('Tag %s already exists for that revision.') % tag_name)
5749
branch.tags.set_tag(tag_name, revision_id)
5750
if existing_target is None:
5751
note(gettext('Created tag %s.') % tag_name)
5753
note(gettext('Updated tag %s.') % tag_name)
5548
branch.tags.set_tag(tag_name, revision_id)
5549
note('Created tag %s.' % tag_name)
5756
5552
class cmd_tags(Command):
5783
5579
self.add_cleanup(branch.lock_read().unlock)
5785
# Restrict to the specified range
5786
tags = self._tags_for_range(branch, revision)
5581
graph = branch.repository.get_graph()
5582
rev1, rev2 = _get_revision_range(revision, branch, self.name())
5583
revid1, revid2 = rev1.rev_id, rev2.rev_id
5584
# only show revisions between revid1 and revid2 (inclusive)
5585
tags = [(tag, revid) for tag, revid in tags if
5586
graph.is_between(revid, revid1, revid2)]
5787
5587
if sort is None:
5788
5588
sort = tag_sort_methods.get()
5789
5589
sort(branch, tags)
5794
5594
revno = branch.revision_id_to_dotted_revno(revid)
5795
5595
if isinstance(revno, tuple):
5796
5596
revno = '.'.join(map(str, revno))
5797
except (errors.NoSuchRevision,
5798
errors.GhostRevisionsHaveNoRevno):
5597
except (errors.NoSuchRevision, errors.GhostRevisionsHaveNoRevno):
5799
5598
# Bad tag data/merges can lead to tagged revisions
5800
5599
# which are not in this branch. Fail gracefully ...
5804
5603
for tag, revspec in tags:
5805
5604
self.outf.write('%-20s %s\n' % (tag, revspec))
5807
def _tags_for_range(self, branch, revision):
5809
rev1, rev2 = _get_revision_range(revision, branch, self.name())
5810
revid1, revid2 = rev1.rev_id, rev2.rev_id
5811
# _get_revision_range will always set revid2 if it's not specified.
5812
# If revid1 is None, it means we want to start from the branch
5813
# origin which is always a valid ancestor. If revid1 == revid2, the
5814
# ancestry check is useless.
5815
if revid1 and revid1 != revid2:
5816
# FIXME: We really want to use the same graph than
5817
# branch.iter_merge_sorted_revisions below, but this is not
5818
# easily available -- vila 2011-09-23
5819
if branch.repository.get_graph().is_ancestor(revid2, revid1):
5820
# We don't want to output anything in this case...
5822
# only show revisions between revid1 and revid2 (inclusive)
5823
tagged_revids = branch.tags.get_reverse_tag_dict()
5825
for r in branch.iter_merge_sorted_revisions(
5826
start_revision_id=revid2, stop_revision_id=revid1,
5827
stop_rule='include'):
5828
revid_tags = tagged_revids.get(r[0], None)
5830
found.extend([(tag, r[0]) for tag in revid_tags])
5834
5607
class cmd_reconfigure(Command):
5835
5608
__doc__ = """Reconfigure the type of a bzr directory.
5849
5622
takes_args = ['location?']
5850
5623
takes_options = [
5851
5624
RegistryOption.from_kwargs(
5854
help='The relation between branch and tree.',
5626
title='Target type',
5627
help='The type to reconfigure the directory to.',
5855
5628
value_switches=True, enum_switch=False,
5856
5629
branch='Reconfigure to be an unbound branch with no working tree.',
5857
5630
tree='Reconfigure to be an unbound branch with a working tree.',
5858
5631
checkout='Reconfigure to be a bound branch with a working tree.',
5859
5632
lightweight_checkout='Reconfigure to be a lightweight'
5860
5633
' checkout (with no local history).',
5862
RegistryOption.from_kwargs(
5864
title='Repository type',
5865
help='Location fo the repository.',
5866
value_switches=True, enum_switch=False,
5867
5634
standalone='Reconfigure to be a standalone branch '
5868
5635
'(i.e. stop using shared repository).',
5869
5636
use_shared='Reconfigure to use a shared repository.',
5871
RegistryOption.from_kwargs(
5873
title='Trees in Repository',
5874
help='Whether new branches in the repository have trees.',
5875
value_switches=True, enum_switch=False,
5876
5637
with_trees='Reconfigure repository to create '
5877
5638
'working trees on branches by default.',
5878
5639
with_no_trees='Reconfigure repository to not create '
5895
def run(self, location=None, bind_to=None, force=False,
5896
tree_type=None, repository_type=None, repository_trees=None,
5897
stacked_on=None, unstacked=None):
5656
def run(self, location=None, target_type=None, bind_to=None, force=False,
5898
5659
directory = bzrdir.BzrDir.open(location)
5899
5660
if stacked_on and unstacked:
5900
raise errors.BzrCommandError(gettext("Can't use both --stacked-on and --unstacked"))
5661
raise errors.BzrCommandError("Can't use both --stacked-on and --unstacked")
5901
5662
elif stacked_on is not None:
5902
5663
reconfigure.ReconfigureStackedOn().apply(directory, stacked_on)
5903
5664
elif unstacked:
5905
5666
# At the moment you can use --stacked-on and a different
5906
5667
# reconfiguration shape at the same time; there seems no good reason
5908
if (tree_type is None and
5909
repository_type is None and
5910
repository_trees is None):
5669
if target_type is None:
5911
5670
if stacked_on or unstacked:
5914
raise errors.BzrCommandError(gettext('No target configuration '
5916
reconfiguration = None
5917
if tree_type == 'branch':
5673
raise errors.BzrCommandError('No target configuration '
5675
elif target_type == 'branch':
5918
5676
reconfiguration = reconfigure.Reconfigure.to_branch(directory)
5919
elif tree_type == 'tree':
5677
elif target_type == 'tree':
5920
5678
reconfiguration = reconfigure.Reconfigure.to_tree(directory)
5921
elif tree_type == 'checkout':
5679
elif target_type == 'checkout':
5922
5680
reconfiguration = reconfigure.Reconfigure.to_checkout(
5923
5681
directory, bind_to)
5924
elif tree_type == 'lightweight-checkout':
5682
elif target_type == 'lightweight-checkout':
5925
5683
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
5926
5684
directory, bind_to)
5928
reconfiguration.apply(force)
5929
reconfiguration = None
5930
if repository_type == 'use-shared':
5685
elif target_type == 'use-shared':
5931
5686
reconfiguration = reconfigure.Reconfigure.to_use_shared(directory)
5932
elif repository_type == 'standalone':
5687
elif target_type == 'standalone':
5933
5688
reconfiguration = reconfigure.Reconfigure.to_standalone(directory)
5935
reconfiguration.apply(force)
5936
reconfiguration = None
5937
if repository_trees == 'with-trees':
5689
elif target_type == 'with-trees':
5938
5690
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
5939
5691
directory, True)
5940
elif repository_trees == 'with-no-trees':
5692
elif target_type == 'with-no-trees':
5941
5693
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
5942
5694
directory, False)
5944
reconfiguration.apply(force)
5945
reconfiguration = None
5695
reconfiguration.apply(force)
5948
5698
class cmd_switch(Command):
6136
5886
name = current_view
6139
raise errors.BzrCommandError(gettext(
6140
"Both --delete and a file list specified"))
5889
raise errors.BzrCommandError(
5890
"Both --delete and a file list specified")
6142
raise errors.BzrCommandError(gettext(
6143
"Both --delete and --switch specified"))
5892
raise errors.BzrCommandError(
5893
"Both --delete and --switch specified")
6145
5895
tree.views.set_view_info(None, {})
6146
self.outf.write(gettext("Deleted all views.\n"))
5896
self.outf.write("Deleted all views.\n")
6147
5897
elif name is None:
6148
raise errors.BzrCommandError(gettext("No current view to delete"))
5898
raise errors.BzrCommandError("No current view to delete")
6150
5900
tree.views.delete_view(name)
6151
self.outf.write(gettext("Deleted '%s' view.\n") % name)
5901
self.outf.write("Deleted '%s' view.\n" % name)
6154
raise errors.BzrCommandError(gettext(
6155
"Both --switch and a file list specified"))
5904
raise errors.BzrCommandError(
5905
"Both --switch and a file list specified")
6157
raise errors.BzrCommandError(gettext(
6158
"Both --switch and --all specified"))
5907
raise errors.BzrCommandError(
5908
"Both --switch and --all specified")
6159
5909
elif switch == 'off':
6160
5910
if current_view is None:
6161
raise errors.BzrCommandError(gettext("No current view to disable"))
5911
raise errors.BzrCommandError("No current view to disable")
6162
5912
tree.views.set_view_info(None, view_dict)
6163
self.outf.write(gettext("Disabled '%s' view.\n") % (current_view))
5913
self.outf.write("Disabled '%s' view.\n" % (current_view))
6165
5915
tree.views.set_view_info(switch, view_dict)
6166
5916
view_str = views.view_display_str(tree.views.lookup_view())
6167
self.outf.write(gettext("Using '{0}' view: {1}\n").format(switch, view_str))
5917
self.outf.write("Using '%s' view: %s\n" % (switch, view_str))
6170
self.outf.write(gettext('Views defined:\n'))
5920
self.outf.write('Views defined:\n')
6171
5921
for view in sorted(view_dict):
6172
5922
if view == current_view:
6176
5926
view_str = views.view_display_str(view_dict[view])
6177
5927
self.outf.write('%s %-20s %s\n' % (active, view, view_str))
6179
self.outf.write(gettext('No views defined.\n'))
5929
self.outf.write('No views defined.\n')
6180
5930
elif file_list:
6181
5931
if name is None:
6182
5932
# No name given and no current view set
6184
5934
elif name == 'off':
6185
raise errors.BzrCommandError(gettext(
6186
"Cannot change the 'off' pseudo view"))
5935
raise errors.BzrCommandError(
5936
"Cannot change the 'off' pseudo view")
6187
5937
tree.views.set_view(name, sorted(file_list))
6188
5938
view_str = views.view_display_str(tree.views.lookup_view())
6189
self.outf.write(gettext("Using '{0}' view: {1}\n").format(name, view_str))
5939
self.outf.write("Using '%s' view: %s\n" % (name, view_str))
6191
5941
# list the files
6192
5942
if name is None:
6193
5943
# No name given and no current view set
6194
self.outf.write(gettext('No current view.\n'))
5944
self.outf.write('No current view.\n')
6196
5946
view_str = views.view_display_str(tree.views.lookup_view(name))
6197
self.outf.write(gettext("'{0}' view is: {1}\n").format(name, view_str))
5947
self.outf.write("'%s' view is: %s\n" % (name, view_str))
6200
5950
class cmd_hooks(Command):
6466
6216
('cmd_version_info', [], 'bzrlib.cmd_version_info'),
6467
6217
('cmd_resolve', ['resolved'], 'bzrlib.conflicts'),
6468
6218
('cmd_conflicts', [], 'bzrlib.conflicts'),
6469
('cmd_sign_my_commits', [], 'bzrlib.commit_signature_commands'),
6470
('cmd_verify_signatures', [],
6471
'bzrlib.commit_signature_commands'),
6219
('cmd_sign_my_commits', [], 'bzrlib.sign_my_commits'),
6472
6220
('cmd_test_script', [], 'bzrlib.cmd_test_script'),
6474
6222
builtin_command_registry.register_lazy(name, aliases, module_name)