783
521
takes_args = ['names*']
784
522
takes_options = [Option("after", help="Move only the bzr identifier"
785
523
" of the file, because the file has already been moved."),
786
Option('auto', help='Automatically guess renames.'),
787
Option('dry-run', help='Avoid making changes when guessing renames.'),
789
525
aliases = ['move', 'rename']
790
526
encoding_type = 'replace'
792
def run(self, names_list, after=False, auto=False, dry_run=False):
794
return self.run_auto(names_list, after, dry_run)
796
raise errors.BzrCommandError('--dry-run requires --auto.')
528
def run(self, names_list, after=False):
797
529
if names_list is None:
799
532
if len(names_list) < 2:
800
533
raise errors.BzrCommandError("missing file argument")
801
tree, rel_names = tree_files(names_list, canonicalize=False)
802
tree.lock_tree_write()
803
self.add_cleanup(tree.unlock)
804
self._run(tree, names_list, rel_names, after)
806
def run_auto(self, names_list, after, dry_run):
807
if names_list is not None and len(names_list) > 1:
808
raise errors.BzrCommandError('Only one path may be specified to'
811
raise errors.BzrCommandError('--after cannot be specified with'
813
work_tree, file_list = tree_files(names_list, default_branch='.')
814
work_tree.lock_tree_write()
815
self.add_cleanup(work_tree.unlock)
816
rename_map.RenameMap.guess_renames(work_tree, dry_run)
818
def _run(self, tree, names_list, rel_names, after):
819
into_existing = osutils.isdir(names_list[-1])
820
if into_existing and len(names_list) == 2:
822
# a. case-insensitive filesystem and change case of dir
823
# b. move directory after the fact (if the source used to be
824
# a directory, but now doesn't exist in the working tree
825
# and the target is an existing directory, just rename it)
826
if (not tree.case_sensitive
827
and rel_names[0].lower() == rel_names[1].lower()):
828
into_existing = False
831
# 'fix' the case of a potential 'from'
832
from_id = tree.path2id(
833
tree.get_canonical_inventory_path(rel_names[0]))
834
if (not osutils.lexists(names_list[0]) and
835
from_id and inv.get_file_kind(from_id) == "directory"):
836
into_existing = False
534
tree, rel_names = tree_files(names_list)
536
if os.path.isdir(names_list[-1]):
839
537
# move into existing directory
840
# All entries reference existing inventory items, so fix them up
841
# for cicp file-systems.
842
rel_names = tree.get_canonical_inventory_paths(rel_names)
843
for src, dest in tree.move(rel_names[:-1], rel_names[-1], after=after):
845
self.outf.write("%s => %s\n" % (src, dest))
538
for pair in tree.move(rel_names[:-1], rel_names[-1], after=after):
539
self.outf.write("%s => %s\n" % pair)
847
541
if len(names_list) != 2:
848
542
raise errors.BzrCommandError('to mv multiple files the'
849
543
' destination must be a versioned'
852
# for cicp file-systems: the src references an existing inventory
854
src = tree.get_canonical_inventory_path(rel_names[0])
855
# Find the canonical version of the destination: In all cases, the
856
# parent of the target must be in the inventory, so we fetch the
857
# canonical version from there (we do not always *use* the
858
# canonicalized tail portion - we may be attempting to rename the
860
canon_dest = tree.get_canonical_inventory_path(rel_names[1])
861
dest_parent = osutils.dirname(canon_dest)
862
spec_tail = osutils.basename(rel_names[1])
863
# For a CICP file-system, we need to avoid creating 2 inventory
864
# entries that differ only by case. So regardless of the case
865
# we *want* to use (ie, specified by the user or the file-system),
866
# we must always choose to use the case of any existing inventory
867
# items. The only exception to this is when we are attempting a
868
# case-only rename (ie, canonical versions of src and dest are
870
dest_id = tree.path2id(canon_dest)
871
if dest_id is None or tree.path2id(src) == dest_id:
872
# No existing item we care about, so work out what case we
873
# are actually going to use.
875
# If 'after' is specified, the tail must refer to a file on disk.
877
dest_parent_fq = osutils.pathjoin(tree.basedir, dest_parent)
879
# pathjoin with an empty tail adds a slash, which breaks
881
dest_parent_fq = tree.basedir
883
dest_tail = osutils.canonical_relpath(
885
osutils.pathjoin(dest_parent_fq, spec_tail))
887
# not 'after', so case as specified is used
888
dest_tail = spec_tail
890
# Use the existing item so 'mv' fails with AlreadyVersioned.
891
dest_tail = os.path.basename(canon_dest)
892
dest = osutils.pathjoin(dest_parent, dest_tail)
893
mutter("attempting to move %s => %s", src, dest)
894
tree.rename_one(src, dest, after=after)
896
self.outf.write("%s => %s\n" % (src, dest))
545
tree.rename_one(rel_names[0], rel_names[1], after=after)
546
self.outf.write("%s => %s\n" % (rel_names[0], rel_names[1]))
899
549
class cmd_pull(Command):
900
550
"""Turn this branch into a mirror of another branch.
902
By default, this command only works on branches that have not diverged.
903
Branches are considered diverged if the destination branch's most recent
904
commit is one that has not been merged (directly or indirectly) into the
552
This command only works on branches that have not diverged. Branches are
553
considered diverged if the destination branch's most recent commit is one
554
that has not been merged (directly or indirectly) into the parent.
907
556
If branches have diverged, you can use 'bzr merge' to integrate the changes
908
557
from one into the other. Once one branch has merged, the other should
909
558
be able to pull it again.
911
If you want to replace your local changes and just want your branch to
912
match the remote one, use pull --overwrite. This will work even if the two
913
branches have diverged.
560
If you want to forget your local changes and just update your branch to
561
match the remote one, use pull --overwrite.
915
563
If there is no default location set, the first pull will set it. After
916
564
that, you can omit the location to use the default. To change the
917
565
default, use --remember. The value will only be saved if the remote
918
566
location can be accessed.
920
Note: The location can be specified either in the form of a branch,
921
or in the form of a path to a file containing a merge directive generated
925
_see_also = ['push', 'update', 'status-flags', 'send']
926
takes_options = ['remember', 'overwrite', 'revision',
927
custom_help('verbose',
928
help='Show logs of pulled revisions.'),
569
_see_also = ['push', 'update', 'status-flags']
570
takes_options = ['remember', 'overwrite', 'revision', 'verbose',
929
571
Option('directory',
930
572
help='Branch to pull into, '
931
573
'rather than the one containing the working directory.',
936
help="Perform a local pull in a bound "
937
"branch. Local pulls are not applied to "
941
578
takes_args = ['location?']
942
579
encoding_type = 'replace'
944
581
def run(self, location=None, remember=False, overwrite=False,
945
582
revision=None, verbose=False,
946
directory=None, local=False):
584
from bzrlib.tag import _merge_tags_if_possible
947
585
# FIXME: too much stuff is in the command class
948
586
revision_id = None
1064
691
' directory exists, but does not already'
1065
692
' have a control directory. This flag will'
1066
693
' allow push to proceed.'),
1068
help='Create a stacked branch that references the public location '
1069
'of the parent branch.'),
1070
Option('stacked-on',
1071
help='Create a stacked branch that refers to another branch '
1072
'for the commit history. Only the work not present in the '
1073
'referenced branch is included in the branch created.',
1076
help='Refuse to push if there are uncommitted changes in'
1077
' the working tree, --no-strict disables the check.'),
1079
695
takes_args = ['location?']
1080
696
encoding_type = 'replace'
1082
698
def run(self, location=None, remember=False, overwrite=False,
1083
create_prefix=False, verbose=False, revision=None,
1084
use_existing_dir=False, directory=None, stacked_on=None,
1085
stacked=False, strict=None):
1086
from bzrlib.push import _show_push_branch
699
create_prefix=False, verbose=False,
700
use_existing_dir=False,
702
# FIXME: Way too big! Put this into a function called from the
1088
704
if directory is None:
1090
# Get the source branch
1092
_unused) = bzrdir.BzrDir.open_containing_tree_or_branch(directory)
1094
strict = br_from.get_config().get_user_option_as_bool('push_strict')
1095
if strict is None: strict = True # default value
1096
# Get the tip's revision_id
1097
revision = _get_one_revision('push', revision)
1098
if revision is not None:
1099
revision_id = revision.in_history(br_from).rev_id
1102
if strict and tree is not None and revision_id is None:
1103
if (tree.has_changes()):
1104
raise errors.UncommittedChanges(
1105
tree, more='Use --no-strict to force the push.')
1106
if tree.last_revision() != tree.branch.last_revision():
1107
# The tree has lost sync with its branch, there is little
1108
# chance that the user is aware of it but he can still force
1109
# the push with --no-strict
1110
raise errors.OutOfDateTree(
1111
tree, more='Use --no-strict to force the push.')
1113
# Get the stacked_on branch, if any
1114
if stacked_on is not None:
1115
stacked_on = urlutils.normalize_url(stacked_on)
1117
parent_url = br_from.get_parent()
1119
parent = Branch.open(parent_url)
1120
stacked_on = parent.get_public_branch()
1122
# I considered excluding non-http url's here, thus forcing
1123
# 'public' branches only, but that only works for some
1124
# users, so it's best to just depend on the user spotting an
1125
# error by the feedback given to them. RBC 20080227.
1126
stacked_on = parent_url
1128
raise errors.BzrCommandError(
1129
"Could not determine branch to refer to.")
1131
# Get the destination location
706
br_from = Branch.open_containing(directory)[0]
707
stored_loc = br_from.get_push_location()
1132
708
if location is None:
1133
stored_loc = br_from.get_push_location()
1134
709
if stored_loc is None:
1135
raise errors.BzrCommandError(
1136
"No push location known or specified.")
710
raise errors.BzrCommandError("No push location known or specified.")
1138
712
display_url = urlutils.unescape_for_display(stored_loc,
1139
713
self.outf.encoding)
1140
self.outf.write("Using saved push location: %s\n" % display_url)
714
self.outf.write("Using saved location: %s\n" % display_url)
1141
715
location = stored_loc
1143
_show_push_branch(br_from, revision_id, location, self.outf,
1144
verbose=verbose, overwrite=overwrite, remember=remember,
1145
stacked_on=stacked_on, create_prefix=create_prefix,
1146
use_existing_dir=use_existing_dir)
717
to_transport = transport.get_transport(location)
719
br_to = repository_to = dir_to = None
721
dir_to = bzrdir.BzrDir.open_from_transport(to_transport)
722
except errors.NotBranchError:
723
pass # Didn't find anything
725
# If we can open a branch, use its direct repository, otherwise see
726
# if there is a repository without a branch.
728
br_to = dir_to.open_branch()
729
except errors.NotBranchError:
730
# Didn't find a branch, can we find a repository?
732
repository_to = dir_to.find_repository()
733
except errors.NoRepositoryPresent:
736
# Found a branch, so we must have found a repository
737
repository_to = br_to.repository
741
# The destination doesn't exist; create it.
742
# XXX: Refactor the create_prefix/no_create_prefix code into a
743
# common helper function
745
to_transport.mkdir('.')
746
except errors.FileExists:
747
if not use_existing_dir:
748
raise errors.BzrCommandError("Target directory %s"
749
" already exists, but does not have a valid .bzr"
750
" directory. Supply --use-existing-dir to push"
751
" there anyway." % location)
752
except errors.NoSuchFile:
753
if not create_prefix:
754
raise errors.BzrCommandError("Parent directory of %s"
756
"\nYou may supply --create-prefix to create all"
757
" leading parent directories."
759
_create_prefix(to_transport)
761
# Now the target directory exists, but doesn't have a .bzr
762
# directory. So we need to create it, along with any work to create
763
# all of the dependent branches, etc.
764
dir_to = br_from.bzrdir.clone_on_transport(to_transport,
765
revision_id=br_from.last_revision())
766
br_to = dir_to.open_branch()
767
# TODO: Some more useful message about what was copied
768
note('Created new branch.')
769
# We successfully created the target, remember it
770
if br_from.get_push_location() is None or remember:
771
br_from.set_push_location(br_to.base)
772
elif repository_to is None:
773
# we have a bzrdir but no branch or repository
774
# XXX: Figure out what to do other than complain.
775
raise errors.BzrCommandError("At %s you have a valid .bzr control"
776
" directory, but not a branch or repository. This is an"
777
" unsupported configuration. Please move the target directory"
778
" out of the way and try again."
781
# We have a repository but no branch, copy the revisions, and then
783
last_revision_id = br_from.last_revision()
784
repository_to.fetch(br_from.repository,
785
revision_id=last_revision_id)
786
br_to = br_from.clone(dir_to, revision_id=last_revision_id)
787
note('Created new branch.')
788
if br_from.get_push_location() is None or remember:
789
br_from.set_push_location(br_to.base)
790
else: # We have a valid to branch
791
# We were able to connect to the remote location, so remember it
792
# we don't need to successfully push because of possible divergence.
793
if br_from.get_push_location() is None or remember:
794
br_from.set_push_location(br_to.base)
795
old_rh = br_to.revision_history()
798
tree_to = dir_to.open_workingtree()
799
except errors.NotLocalUrl:
800
warning("This transport does not update the working "
801
"tree of: %s. See 'bzr help working-trees' for "
802
"more information." % br_to.base)
803
push_result = br_from.push(br_to, overwrite)
804
except errors.NoWorkingTree:
805
push_result = br_from.push(br_to, overwrite)
809
push_result = br_from.push(tree_to.branch, overwrite)
813
except errors.DivergedBranches:
814
raise errors.BzrCommandError('These branches have diverged.'
815
' Try using "merge" and then "push".')
816
if push_result is not None:
817
push_result.report(self.outf)
819
new_rh = br_to.revision_history()
822
from bzrlib.log import show_changed_revisions
823
show_changed_revisions(br_to, old_rh, new_rh,
826
# we probably did a clone rather than a push, so a message was
1149
831
class cmd_branch(Command):
1150
"""Create a new branch that is a copy of an existing branch.
832
"""Create a new copy of a branch.
1152
834
If the TO_LOCATION is omitted, the last component of the FROM_LOCATION will
1153
835
be used. In other words, "branch ../foo/bar" will attempt to create ./bar.
1163
845
_see_also = ['checkout']
1164
846
takes_args = ['from_location', 'to_location?']
1165
takes_options = ['revision', Option('hardlink',
1166
help='Hard-link working tree files where possible.'),
1168
help="Create a branch without a working-tree."),
1170
help="Switch the checkout in the current directory "
1171
"to the new branch."),
1173
help='Create a stacked branch referring to the source branch. '
1174
'The new branch will depend on the availability of the source '
1175
'branch for all operations.'),
1176
Option('standalone',
1177
help='Do not use a shared repository, even if available.'),
1178
Option('use-existing-dir',
1179
help='By default branch will fail if the target'
1180
' directory exists, but does not already'
1181
' have a control directory. This flag will'
1182
' allow branch to proceed.'),
1184
help="Bind new branch to from location."),
847
takes_options = ['revision']
1186
848
aliases = ['get', 'clone']
1188
def run(self, from_location, to_location=None, revision=None,
1189
hardlink=False, stacked=False, standalone=False, no_tree=False,
1190
use_existing_dir=False, switch=False, bind=False):
1191
from bzrlib import switch as _mod_switch
850
def run(self, from_location, to_location=None, revision=None):
1192
851
from bzrlib.tag import _merge_tags_if_possible
1193
accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
1195
revision = _get_one_revision('branch', revision)
854
elif len(revision) > 1:
855
raise errors.BzrCommandError(
856
'bzr branch --revision takes exactly 1 revision value')
858
br_from = Branch.open(from_location)
1196
859
br_from.lock_read()
1197
self.add_cleanup(br_from.unlock)
1198
if revision is not None:
1199
revision_id = revision.as_revision_id(br_from)
1201
# FIXME - wt.last_revision, fallback to branch, fall back to
1202
# None or perhaps NULL_REVISION to mean copy nothing
1204
revision_id = br_from.last_revision()
1205
if to_location is None:
1206
to_location = urlutils.derive_to_location(from_location)
1207
to_transport = transport.get_transport(to_location)
1209
to_transport.mkdir('.')
1210
except errors.FileExists:
1211
if not use_existing_dir:
1212
raise errors.BzrCommandError('Target directory "%s" '
1213
'already exists.' % to_location)
1216
bzrdir.BzrDir.open_from_transport(to_transport)
1217
except errors.NotBranchError:
1220
raise errors.AlreadyBranchError(to_location)
1221
except errors.NoSuchFile:
1222
raise errors.BzrCommandError('Parent of "%s" does not exist.'
1225
# preserve whatever source format we have.
1226
dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
1227
possible_transports=[to_transport],
1228
accelerator_tree=accelerator_tree,
1229
hardlink=hardlink, stacked=stacked,
1230
force_new_repo=standalone,
1231
create_tree_if_local=not no_tree,
1232
source_branch=br_from)
1233
branch = dir.open_branch()
1234
except errors.NoSuchRevision:
1235
to_transport.delete_tree('.')
1236
msg = "The branch %s has no revision %s." % (from_location,
1238
raise errors.BzrCommandError(msg)
1239
_merge_tags_if_possible(br_from, branch)
1240
# If the source branch is stacked, the new branch may
1241
# be stacked whether we asked for that explicitly or not.
1242
# We therefore need a try/except here and not just 'if stacked:'
1244
note('Created new stacked branch referring to %s.' %
1245
branch.get_stacked_on_url())
1246
except (errors.NotStacked, errors.UnstackableBranchFormat,
1247
errors.UnstackableRepositoryFormat), e:
861
if len(revision) == 1 and revision[0] is not None:
862
revision_id = revision[0].in_history(br_from)[1]
864
# FIXME - wt.last_revision, fallback to branch, fall back to
865
# None or perhaps NULL_REVISION to mean copy nothing
867
revision_id = br_from.last_revision()
868
if to_location is None:
869
to_location = urlutils.derive_to_location(from_location)
872
name = os.path.basename(to_location) + '\n'
874
to_transport = transport.get_transport(to_location)
876
to_transport.mkdir('.')
877
except errors.FileExists:
878
raise errors.BzrCommandError('Target directory "%s" already'
879
' exists.' % to_location)
880
except errors.NoSuchFile:
881
raise errors.BzrCommandError('Parent of "%s" does not exist.'
884
# preserve whatever source format we have.
885
dir = br_from.bzrdir.sprout(to_transport.base, revision_id)
886
branch = dir.open_branch()
887
except errors.NoSuchRevision:
888
to_transport.delete_tree('.')
889
msg = "The branch %s has no revision %s." % (from_location, revision[0])
890
raise errors.BzrCommandError(msg)
892
branch.control_files.put_utf8('branch-name', name)
893
_merge_tags_if_possible(br_from, branch)
1248
894
note('Branched %d revision(s).' % branch.revno())
1250
# Bind to the parent
1251
parent_branch = Branch.open(from_location)
1252
branch.bind(parent_branch)
1253
note('New branch bound to %s' % from_location)
1255
# Switch to the new branch
1256
wt, _ = WorkingTree.open_containing('.')
1257
_mod_switch.switch(wt.bzrdir, branch)
1258
note('Switched to branch: %s',
1259
urlutils.unescape_for_display(branch.base, 'utf-8'))
1262
899
class cmd_checkout(Command):
1341
984
def run(self, dir=u'.'):
1342
985
tree = WorkingTree.open_containing(dir)[0]
1343
986
tree.lock_read()
1344
self.add_cleanup(tree.unlock)
1345
new_inv = tree.inventory
1346
old_tree = tree.basis_tree()
1347
old_tree.lock_read()
1348
self.add_cleanup(old_tree.unlock)
1349
old_inv = old_tree.inventory
1351
iterator = tree.iter_changes(old_tree, include_unchanged=True)
1352
for f, paths, c, v, p, n, k, e in iterator:
1353
if paths[0] == paths[1]:
1357
renames.append(paths)
1359
for old_name, new_name in renames:
1360
self.outf.write("%s => %s\n" % (old_name, new_name))
988
new_inv = tree.inventory
989
old_tree = tree.basis_tree()
992
old_inv = old_tree.inventory
993
renames = list(_mod_tree.find_renames(old_inv, new_inv))
995
for old_name, new_name in renames:
996
self.outf.write("%s => %s\n" % (old_name, new_name))
1363
1003
class cmd_update(Command):
1364
1004
"""Update a tree to have the latest code committed to its branch.
1366
1006
This will perform a merge into the working tree, and may generate
1367
conflicts. If you have any local changes, you will still
1007
conflicts. If you have any local changes, you will still
1368
1008
need to commit them after the update for the update to be complete.
1370
If you want to discard your local changes, you can just do a
1010
If you want to discard your local changes, you can just do a
1371
1011
'bzr revert' instead of 'bzr commit' after the update.
1373
If the tree's branch is bound to a master branch, it will also update
1374
the branch from the master.
1377
_see_also = ['pull', 'working-trees', 'status-flags']
1014
_see_also = ['pull', 'working-trees']
1378
1015
takes_args = ['dir?']
1379
takes_options = ['revision']
1380
1016
aliases = ['up']
1382
def run(self, dir='.', revision=None):
1383
if revision is not None and len(revision) != 1:
1384
raise errors.BzrCommandError(
1385
"bzr update --revision takes exactly one revision")
1018
def run(self, dir='.'):
1386
1019
tree = WorkingTree.open_containing(dir)[0]
1387
branch = tree.branch
1388
possible_transports = []
1389
master = branch.get_master_branch(
1390
possible_transports=possible_transports)
1020
master = tree.branch.get_master_branch()
1391
1021
if master is not None:
1392
1022
tree.lock_write()
1393
branch_location = master.base
1395
1024
tree.lock_tree_write()
1396
branch_location = tree.branch.base
1397
self.add_cleanup(tree.unlock)
1398
# get rid of the final '/' and be ready for display
1399
branch_location = urlutils.unescape_for_display(branch_location[:-1],
1401
existing_pending_merges = tree.get_parent_ids()[1:]
1405
# may need to fetch data into a heavyweight checkout
1406
# XXX: this may take some time, maybe we should display a
1408
old_tip = branch.update(possible_transports)
1409
if revision is not None:
1410
revision_id = revision[0].as_revision_id(branch)
1412
revision_id = branch.last_revision()
1413
if revision_id == _mod_revision.ensure_null(tree.last_revision()):
1414
revno = branch.revision_id_to_revno(revision_id)
1415
note("Tree is up to date at revision %d of branch %s" %
1416
(revno, branch_location))
1418
view_info = _get_view_info_for_change_reporter(tree)
1419
change_reporter = delta._ChangeReporter(
1420
unversioned_filter=tree.is_ignored,
1421
view_info=view_info)
1423
conflicts = tree.update(
1425
possible_transports=possible_transports,
1426
revision=revision_id,
1428
except errors.NoSuchRevision, e:
1429
raise errors.BzrCommandError(
1430
"branch has no revision %s\n"
1431
"bzr update --revision only works"
1432
" for a revision in the branch history"
1434
revno = tree.branch.revision_id_to_revno(
1435
_mod_revision.ensure_null(tree.last_revision()))
1436
note('Updated to revision %d of branch %s' %
1437
(revno, branch_location))
1438
if tree.get_parent_ids()[1:] != existing_pending_merges:
1439
note('Your local commits will now show as pending merges with '
1440
"'bzr status', and can be committed with 'bzr commit'.")
1026
existing_pending_merges = tree.get_parent_ids()[1:]
1027
last_rev = _mod_revision.ensure_null(tree.last_revision())
1028
if last_rev == _mod_revision.ensure_null(
1029
tree.branch.last_revision()):
1030
# may be up to date, check master too.
1031
master = tree.branch.get_master_branch()
1032
if master is None or last_rev == _mod_revision.ensure_null(
1033
master.last_revision()):
1034
revno = tree.branch.revision_id_to_revno(last_rev)
1035
note("Tree is up to date at revision %d." % (revno,))
1037
conflicts = tree.update(delta._ChangeReporter(
1038
unversioned_filter=tree.is_ignored))
1039
revno = tree.branch.revision_id_to_revno(
1040
_mod_revision.ensure_null(tree.last_revision()))
1041
note('Updated to revision %d.' % (revno,))
1042
if tree.get_parent_ids()[1:] != existing_pending_merges:
1043
note('Your local commits will now show as pending merges with '
1044
"'bzr status', and can be committed with 'bzr commit'.")
1447
1053
class cmd_info(Command):
1448
1054
"""Show information about a working tree, branch or repository.
1450
1056
This command will show all known locations and formats associated to the
1451
tree, branch or repository.
1453
In verbose mode, statistical information is included with each report.
1454
To see extended statistic information, use a verbosity level of 2 or
1455
higher by specifying the verbose option multiple times, e.g. -vv.
1057
tree, branch or repository. Statistical information is included with
1457
1060
Branches and working trees will also report any missing revisions.
1461
Display information on the format and related locations:
1465
Display the above together with extended format information and
1466
basic statistics (like the number of files in the working tree and
1467
number of revisions in the branch and repository):
1471
Display the above together with number of committers to the branch:
1475
1062
_see_also = ['revno', 'working-trees', 'repositories']
1476
1063
takes_args = ['location?']
1477
1064
takes_options = ['verbose']
1478
encoding_type = 'replace'
1480
1066
@display_command
1481
def run(self, location=None, verbose=False):
1483
noise_level = get_verbosity_level()
1067
def run(self, location=None, verbose=0):
1486
1068
from bzrlib.info import show_bzrdir_info
1487
1069
show_bzrdir_info(bzrdir.BzrDir.open_containing(location)[0],
1488
verbose=noise_level, outfile=self.outf)
1491
1073
class cmd_remove(Command):
1492
1074
"""Remove files or directories.
1494
This makes bzr stop tracking changes to the specified files. bzr will delete
1495
them if they can easily be recovered using revert. If no options or
1496
parameters are given bzr will scan for files that are being tracked by bzr
1497
but missing in your tree and stop tracking them for you.
1076
This makes bzr stop tracking changes to the specified files and
1077
delete them if they can easily be recovered using revert.
1079
You can specify one or more files, and/or --new. If you specify --new,
1080
only 'added' files will be removed. If you specify both, then new files
1081
in the specified directories will be removed. If the directories are
1082
also new, they will also be removed.
1499
1084
takes_args = ['file*']
1500
1085
takes_options = ['verbose',
1501
Option('new', help='Only remove files that have never been committed.'),
1086
Option('new', help='Remove newly-added files.'),
1502
1087
RegistryOption.from_kwargs('file-deletion-strategy',
1503
'The file deletion mode to be used.',
1088
'The file deletion mode to be used',
1504
1089
title='Deletion Strategy', value_switches=True, enum_switch=False,
1505
1090
safe='Only delete files if they can be'
1506
1091
' safely recovered (default).',
1507
keep='Delete from bzr but leave the working copy.',
1092
keep="Don't delete any files.",
1508
1093
force='Delete all the specified files, even if they can not be '
1509
1094
'recovered and even if they are non-empty directories.')]
1510
aliases = ['rm', 'del']
1511
1096
encoding_type = 'replace'
1513
1098
def run(self, file_list, verbose=False, new=False,
2065
1583
raise errors.BzrCommandError(msg)
2068
def _parse_levels(s):
2072
msg = "The levels argument must be an integer."
2073
raise errors.BzrCommandError(msg)
2076
1586
class cmd_log(Command):
2077
"""Show historical log for a branch or subset of a branch.
2079
log is bzr's default tool for exploring the history of a branch.
2080
The branch to use is taken from the first parameter. If no parameters
2081
are given, the branch containing the working directory is logged.
2082
Here are some simple examples::
2084
bzr log log the current branch
2085
bzr log foo.py log a file in its branch
2086
bzr log http://server/branch log a branch on a server
2088
The filtering, ordering and information shown for each revision can
2089
be controlled as explained below. By default, all revisions are
2090
shown sorted (topologically) so that newer revisions appear before
2091
older ones and descendants always appear before ancestors. If displayed,
2092
merged revisions are shown indented under the revision in which they
2097
The log format controls how information about each revision is
2098
displayed. The standard log formats are called ``long``, ``short``
2099
and ``line``. The default is long. See ``bzr help log-formats``
2100
for more details on log formats.
2102
The following options can be used to control what information is
2105
-l N display a maximum of N revisions
2106
-n N display N levels of revisions (0 for all, 1 for collapsed)
2107
-v display a status summary (delta) for each revision
2108
-p display a diff (patch) for each revision
2109
--show-ids display revision-ids (and file-ids), not just revnos
2111
Note that the default number of levels to display is a function of the
2112
log format. If the -n option is not used, the standard log formats show
2113
just the top level (mainline).
2115
Status summaries are shown using status flags like A, M, etc. To see
2116
the changes explained using words like ``added`` and ``modified``
2117
instead, use the -vv option.
2121
To display revisions from oldest to newest, use the --forward option.
2122
In most cases, using this option will have little impact on the total
2123
time taken to produce a log, though --forward does not incrementally
2124
display revisions like --reverse does when it can.
2126
:Revision filtering:
2128
The -r option can be used to specify what revision or range of revisions
2129
to filter against. The various forms are shown below::
2131
-rX display revision X
2132
-rX.. display revision X and later
2133
-r..Y display up to and including revision Y
2134
-rX..Y display from X to Y inclusive
2136
See ``bzr help revisionspec`` for details on how to specify X and Y.
2137
Some common examples are given below::
2139
-r-1 show just the tip
2140
-r-10.. show the last 10 mainline revisions
2141
-rsubmit:.. show what's new on this branch
2142
-rancestor:path.. show changes since the common ancestor of this
2143
branch and the one at location path
2144
-rdate:yesterday.. show changes since yesterday
2146
When logging a range of revisions using -rX..Y, log starts at
2147
revision Y and searches back in history through the primary
2148
("left-hand") parents until it finds X. When logging just the
2149
top level (using -n1), an error is reported if X is not found
2150
along the way. If multi-level logging is used (-n0), X may be
2151
a nested merge revision and the log will be truncated accordingly.
2155
If parameters are given and the first one is not a branch, the log
2156
will be filtered to show only those revisions that changed the
2157
nominated files or directories.
2159
Filenames are interpreted within their historical context. To log a
2160
deleted file, specify a revision range so that the file existed at
2161
the end or start of the range.
2163
Historical context is also important when interpreting pathnames of
2164
renamed files/directories. Consider the following example:
2166
* revision 1: add tutorial.txt
2167
* revision 2: modify tutorial.txt
2168
* revision 3: rename tutorial.txt to guide.txt; add tutorial.txt
2172
* ``bzr log guide.txt`` will log the file added in revision 1
2174
* ``bzr log tutorial.txt`` will log the new file added in revision 3
2176
* ``bzr log -r2 -p tutorial.txt`` will show the changes made to
2177
the original file in revision 2.
2179
* ``bzr log -r2 -p guide.txt`` will display an error message as there
2180
was no file called guide.txt in revision 2.
2182
Renames are always followed by log. By design, there is no need to
2183
explicitly ask for this (and no way to stop logging a file back
2184
until it was last renamed).
2188
The --message option can be used for finding revisions that match a
2189
regular expression in a commit message.
2193
GUI tools and IDEs are often better at exploring history than command
2194
line tools: you may prefer qlog or viz from qbzr or bzr-gtk, the
2195
bzr-explorer shell, or the Loggerhead web interface. See the Plugin
2196
Guide <http://doc.bazaar.canonical.com/plugins/en/> and
2197
<http://wiki.bazaar.canonical.com/IDEIntegration>.
2199
You may find it useful to add the aliases below to ``bazaar.conf``::
2203
top = log -l10 --line
2206
``bzr tip`` will then show the latest revision while ``bzr top``
2207
will show the last 10 mainline revisions. To see the details of a
2208
particular revision X, ``bzr show -rX``.
2210
If you are interested in looking deeper into a particular merge X,
2211
use ``bzr log -n0 -rX``.
2213
``bzr log -v`` on a branch with lots of history is currently
2214
very slow. A fix for this issue is currently under development.
2215
With or without that fix, it is recommended that a revision range
2216
be given when using the -v option.
2218
bzr has a generic full-text matching plugin, bzr-search, that can be
2219
used to find revisions matching user names, commit messages, etc.
2220
Among other features, this plugin can find all revisions containing
2221
a list of words but not others.
2223
When exploring non-mainline history on large projects with deep
2224
history, the performance of log can be greatly improved by installing
2225
the historycache plugin. This plugin buffers historical information
2226
trading disk space for faster speed.
1587
"""Show log of a branch, file, or directory.
1589
By default show the log of the branch containing the working directory.
1591
To request a range of logs, you can use the command -r begin..end
1592
-r revision requests a specific revision, -r ..end or -r begin.. are
1598
bzr log -r -10.. http://server/branch
2228
takes_args = ['file*']
2229
_see_also = ['log-formats', 'revisionspec']
1601
# TODO: Make --revision support uuid: and hash: [future tag:] notation.
1603
takes_args = ['location?']
2230
1604
takes_options = [
2231
1605
Option('forward',
2232
1606
help='Show from oldest to newest.'),
2234
custom_help('verbose',
1609
help='Display timezone as local, original, or utc.'),
2235
1612
help='Show files changed in each revision.'),
2239
type=bzrlib.option._parse_revision_str,
2241
help='Show just the specified revision.'
2242
' See also "help revisionspec".'),
2246
help='Number of levels to display - 0 for all, 1 for flat.',
2248
type=_parse_levels),
2249
1616
Option('message',
2250
1617
short_name='m',
2251
1618
help='Show revisions whose message matches this '
2252
1619
'regular expression.',
2254
1621
Option('limit',
2256
1622
help='Limit the output to the first N revisions.',
2258
1624
type=_parse_limit),
2261
help='Show changes made in each revision as a patch.'),
2262
Option('include-merges',
2263
help='Show merged revisions like --levels 0 does.'),
2265
1626
encoding_type = 'replace'
2267
1628
@display_command
2268
def run(self, file_list=None, timezone='original',
1629
def run(self, location=None, timezone='original',
2270
1631
show_ids=False,
2274
1634
log_format=None,
2279
include_merges=False):
2280
from bzrlib.log import (
2282
make_log_request_dict,
2283
_get_info_for_log_files,
1637
from bzrlib.log import show_log
1638
assert message is None or isinstance(message, basestring), \
1639
"invalid message argument %r" % message
2285
1640
direction = (forward and 'forward') or 'reverse'
2290
raise errors.BzrCommandError(
2291
'--levels and --include-merges are mutually exclusive')
2293
if change is not None:
2295
raise errors.RangeInChangeOption()
2296
if revision is not None:
2297
raise errors.BzrCommandError(
2298
'--revision and --change are mutually exclusive')
2303
filter_by_dir = False
2305
# find the file ids to log and check for directory filtering
2306
b, file_info_list, rev1, rev2 = _get_info_for_log_files(
2307
revision, file_list)
2308
self.add_cleanup(b.unlock)
2309
for relpath, file_id, kind in file_info_list:
1645
# find the file id to log:
1647
tree, b, fp = bzrdir.BzrDir.open_containing_tree_or_branch(
1651
tree = b.basis_tree()
1652
file_id = tree.path2id(fp)
2310
1653
if file_id is None:
2311
1654
raise errors.BzrCommandError(
2312
"Path unknown at end or start of revision range: %s" %
2314
# If the relpath is the top of the tree, we log everything
2319
file_ids.append(file_id)
2320
filter_by_dir = filter_by_dir or (
2321
kind in ['directory', 'tree-reference'])
1655
"Path does not have any revision history: %s" %
2324
# FIXME ? log the current subdir only RBC 20060203
1659
# FIXME ? log the current subdir only RBC 20060203
2325
1660
if revision is not None \
2326
1661
and len(revision) > 0 and revision[0].get_branch():
2327
1662
location = revision[0].get_branch()
3722
2630
short_name='d',
3725
Option('preview', help='Instead of merging, show a diff of the'
3727
Option('interactive', help='Select changes interactively.',
3731
def run(self, location=None, revision=None, force=False,
3732
merge_type=None, show_base=False, reprocess=None, remember=False,
2635
def run(self, branch=None, revision=None, force=False, merge_type=None,
2636
show_base=False, reprocess=False, remember=False,
3733
2637
uncommitted=False, pull=False,
3734
2638
directory=None,
2640
from bzrlib.tag import _merge_tags_if_possible
2641
other_revision_id = None
2642
base_revision_id = None
3738
2643
if merge_type is None:
3739
2644
merge_type = _mod_merge.Merge3Merger
3741
2646
if directory is None: directory = u'.'
3742
possible_transports = []
3744
allow_pending = True
3745
verified = 'inapplicable'
2647
# XXX: jam 20070225 WorkingTree should be locked before you extract its
2648
# inventory. Because merge is a mutating operation, it really
2649
# should be a lock_write() for the whole cmd_merge operation.
2650
# However, cmd_merge open's its own tree in _merge_helper, which
2651
# means if we lock here, the later lock_write() will always block.
2652
# Either the merge helper code should be updated to take a tree,
2653
# (What about tree.merge_from_branch?)
3746
2654
tree = WorkingTree.open_containing(directory)[0]
3749
basis_tree = tree.revision_tree(tree.last_revision())
3750
except errors.NoSuchRevision:
3751
basis_tree = tree.basis_tree()
3753
# die as quickly as possible if there are uncommitted changes
3755
if tree.has_changes():
3756
raise errors.UncommittedChanges(tree)
3758
view_info = _get_view_info_for_change_reporter(tree)
3759
2655
change_reporter = delta._ChangeReporter(
3760
unversioned_filter=tree.is_ignored, view_info=view_info)
3761
pb = ui.ui_factory.nested_progress_bar()
3762
self.add_cleanup(pb.finished)
3764
self.add_cleanup(tree.unlock)
3765
if location is not None:
2656
unversioned_filter=tree.is_ignored)
2658
if branch is not None:
3767
mergeable = bundle.read_mergeable_from_url(location,
3768
possible_transports=possible_transports)
2660
mergeable = bundle.read_mergeable_from_url(
3769
2662
except errors.NotABundle:
2663
pass # Continue on considering this url a Branch
3773
raise errors.BzrCommandError('Cannot use --uncommitted'
3774
' with bundles or merge directives.')
3776
2665
if revision is not None:
3777
2666
raise errors.BzrCommandError(
3778
2667
'Cannot use -r with merge directives or bundles')
3779
merger, verified = _mod_merge.Merger.from_mergeable(tree,
3782
if merger is None and uncommitted:
3783
if revision is not None and len(revision) > 0:
3784
raise errors.BzrCommandError('Cannot use --uncommitted and'
3785
' --revision at the same time.')
3786
merger = self.get_merger_from_uncommitted(tree, location, None)
3787
allow_pending = False
3790
merger, allow_pending = self._get_merger_from_branch(tree,
3791
location, revision, remember, possible_transports, None)
3793
merger.merge_type = merge_type
3794
merger.reprocess = reprocess
3795
merger.show_base = show_base
3796
self.sanity_check_merger(merger)
3797
if (merger.base_rev_id == merger.other_rev_id and
3798
merger.other_rev_id is not None):
3799
note('Nothing to do.')
3802
if merger.interesting_files is not None:
3803
raise errors.BzrCommandError('Cannot pull individual files')
3804
if (merger.base_rev_id == tree.last_revision()):
3805
result = tree.pull(merger.other_branch, False,
3806
merger.other_rev_id)
3807
result.report(self.outf)
3809
if merger.this_basis is None:
3810
raise errors.BzrCommandError(
3811
"This branch has no commits."
3812
" (perhaps you would prefer 'bzr pull')")
3814
return self._do_preview(merger)
3816
return self._do_interactive(merger)
3818
return self._do_merge(merger, change_reporter, allow_pending,
3821
def _get_preview(self, merger):
3822
tree_merger = merger.make_merger()
3823
tt = tree_merger.make_preview_transform()
3824
self.add_cleanup(tt.finalize)
3825
result_tree = tt.get_preview_tree()
3828
def _do_preview(self, merger):
3829
from bzrlib.diff import show_diff_trees
3830
result_tree = self._get_preview(merger)
3831
show_diff_trees(merger.this_tree, result_tree, self.outf,
3832
old_label='', new_label='')
3834
def _do_merge(self, merger, change_reporter, allow_pending, verified):
3835
merger.change_reporter = change_reporter
3836
conflict_count = merger.do_merge()
3838
merger.set_pending()
3839
if verified == 'failed':
3840
warning('Preview patch does not match changes')
3841
if conflict_count != 0:
3846
def _do_interactive(self, merger):
3847
"""Perform an interactive merge.
3849
This works by generating a preview tree of the merge, then using
3850
Shelver to selectively remove the differences between the working tree
3851
and the preview tree.
3853
from bzrlib import shelf_ui
3854
result_tree = self._get_preview(merger)
3855
writer = bzrlib.option.diff_writer_registry.get()
3856
shelver = shelf_ui.Shelver(merger.this_tree, result_tree, destroy=True,
3857
reporter=shelf_ui.ApplyReporter(),
3858
diff_writer=writer(sys.stdout))
3864
def sanity_check_merger(self, merger):
3865
if (merger.show_base and
3866
not merger.merge_type is _mod_merge.Merge3Merger):
3867
raise errors.BzrCommandError("Show-base is not supported for this"
3868
" merge type. %s" % merger.merge_type)
3869
if merger.reprocess is None:
3870
if merger.show_base:
3871
merger.reprocess = False
3873
# Use reprocess if the merger supports it
3874
merger.reprocess = merger.merge_type.supports_reprocess
3875
if merger.reprocess and not merger.merge_type.supports_reprocess:
3876
raise errors.BzrCommandError("Conflict reduction is not supported"
3877
" for merge type %s." %
3879
if merger.reprocess and merger.show_base:
3880
raise errors.BzrCommandError("Cannot do conflict reduction and"
3883
def _get_merger_from_branch(self, tree, location, revision, remember,
3884
possible_transports, pb):
3885
"""Produce a merger from a location, assuming it refers to a branch."""
3886
from bzrlib.tag import _merge_tags_if_possible
3887
# find the branch locations
3888
other_loc, user_location = self._select_branch_location(tree, location,
3890
if revision is not None and len(revision) == 2:
3891
base_loc, _unused = self._select_branch_location(tree,
3892
location, revision, 0)
3894
base_loc = other_loc
3896
other_branch, other_path = Branch.open_containing(other_loc,
3897
possible_transports)
3898
if base_loc == other_loc:
3899
base_branch = other_branch
3901
base_branch, base_path = Branch.open_containing(base_loc,
3902
possible_transports)
3903
# Find the revision ids
3904
other_revision_id = None
3905
base_revision_id = None
3906
if revision is not None:
3907
if len(revision) >= 1:
3908
other_revision_id = revision[-1].as_revision_id(other_branch)
3909
if len(revision) == 2:
3910
base_revision_id = revision[0].as_revision_id(base_branch)
2668
mergeable.install_revisions(tree.branch.repository)
2669
base_revision_id, other_revision_id, verified =\
2670
mergeable.get_merge_request(tree.branch.repository)
2671
if base_revision_id in tree.branch.repository.get_ancestry(
2672
tree.branch.last_revision(), topo_sorted=False):
2673
base_revision_id = None
3911
2679
if other_revision_id is None:
3912
other_revision_id = _mod_revision.ensure_null(
3913
other_branch.last_revision())
3914
# Remember where we merge from
3915
if ((remember or tree.branch.get_submit_branch() is None) and
3916
user_location is not None):
3917
tree.branch.set_submit_branch(other_branch.base)
3918
_merge_tags_if_possible(other_branch, tree.branch)
3919
merger = _mod_merge.Merger.from_revision_ids(pb, tree,
3920
other_revision_id, base_revision_id, other_branch, base_branch)
3921
if other_path != '':
3922
allow_pending = False
3923
merger.interesting_files = [other_path]
3925
allow_pending = True
3926
return merger, allow_pending
3928
def get_merger_from_uncommitted(self, tree, location, pb):
3929
"""Get a merger for uncommitted changes.
3931
:param tree: The tree the merger should apply to.
3932
:param location: The location containing uncommitted changes.
3933
:param pb: The progress bar to use for showing progress.
3935
location = self._select_branch_location(tree, location)[0]
3936
other_tree, other_path = WorkingTree.open_containing(location)
3937
merger = _mod_merge.Merger.from_uncommitted(tree, other_tree, pb)
3938
if other_path != '':
3939
merger.interesting_files = [other_path]
3942
def _select_branch_location(self, tree, user_location, revision=None,
3944
"""Select a branch location, according to possible inputs.
3946
If provided, branches from ``revision`` are preferred. (Both
3947
``revision`` and ``index`` must be supplied.)
3949
Otherwise, the ``location`` parameter is used. If it is None, then the
3950
``submit`` or ``parent`` location is used, and a note is printed.
3952
:param tree: The working tree to select a branch for merging into
3953
:param location: The location entered by the user
3954
:param revision: The revision parameter to the command
3955
:param index: The index to use for the revision parameter. Negative
3956
indices are permitted.
3957
:return: (selected_location, user_location). The default location
3958
will be the user-entered location.
3960
if (revision is not None and index is not None
3961
and revision[index] is not None):
3962
branch = revision[index].get_branch()
3963
if branch is not None:
3964
return branch, branch
3965
if user_location is None:
3966
location = self._get_remembered(tree, 'Merging from')
3968
location = user_location
3969
return location, user_location
3971
def _get_remembered(self, tree, verb_string):
2680
verified = 'inapplicable'
2681
if revision is None \
2682
or len(revision) < 1 or revision[0].needs_branch():
2683
branch = self._get_remembered_parent(tree, branch,
2686
if revision is None or len(revision) < 1:
2689
other = [branch, None]
2692
other = [branch, -1]
2693
other_branch, path = Branch.open_containing(branch)
2696
raise errors.BzrCommandError('Cannot use --uncommitted and'
2697
' --revision at the same time.')
2698
branch = revision[0].get_branch() or branch
2699
if len(revision) == 1:
2701
other_branch, path = Branch.open_containing(branch)
2702
revno = revision[0].in_history(other_branch).revno
2703
other = [branch, revno]
2705
assert len(revision) == 2
2706
if None in revision:
2707
raise errors.BzrCommandError(
2708
"Merge doesn't permit empty revision specifier.")
2709
base_branch, path = Branch.open_containing(branch)
2710
branch1 = revision[1].get_branch() or branch
2711
other_branch, path1 = Branch.open_containing(branch1)
2712
if revision[0].get_branch() is not None:
2713
# then path was obtained from it, and is None.
2716
base = [branch, revision[0].in_history(base_branch).revno]
2718
revision[1].in_history(other_branch).revno]
2720
if ((tree.branch.get_parent() is None or remember) and
2721
other_branch is not None):
2722
tree.branch.set_parent(other_branch.base)
2724
# pull tags now... it's a bit inconsistent to do it ahead of copying
2725
# the history but that's done inside the merge code
2726
if other_branch is not None:
2727
_merge_tags_if_possible(other_branch, tree.branch)
2730
interesting_files = [path]
2732
interesting_files = None
2733
pb = ui.ui_factory.nested_progress_bar()
2736
conflict_count = _merge_helper(
2737
other, base, other_rev_id=other_revision_id,
2738
base_rev_id=base_revision_id,
2739
check_clean=(not force),
2740
merge_type=merge_type,
2741
reprocess=reprocess,
2742
show_base=show_base,
2745
pb=pb, file_list=interesting_files,
2746
change_reporter=change_reporter)
2749
if verified == 'failed':
2750
warning('Preview patch does not match changes')
2751
if conflict_count != 0:
2755
except errors.AmbiguousBase, e:
2756
m = ("sorry, bzr can't determine the right merge base yet\n"
2757
"candidates are:\n "
2758
+ "\n ".join(e.bases)
2760
"please specify an explicit base with -r,\n"
2761
"and (if you want) report this to the bzr developers\n")
2764
# TODO: move up to common parent; this isn't merge-specific anymore.
2765
def _get_remembered_parent(self, tree, supplied_location, verb_string):
3972
2766
"""Use tree.branch's parent if none was supplied.
3974
2768
Report if the remembered location was used.
3976
stored_location = tree.branch.get_submit_branch()
3977
stored_location_type = "submit"
3978
if stored_location is None:
3979
stored_location = tree.branch.get_parent()
3980
stored_location_type = "parent"
2770
if supplied_location is not None:
2771
return supplied_location
2772
stored_location = tree.branch.get_parent()
3981
2773
mutter("%s", stored_location)
3982
2774
if stored_location is None:
3983
2775
raise errors.BzrCommandError("No location specified or remembered")
3984
display_url = urlutils.unescape_for_display(stored_location, 'utf-8')
3985
note(u"%s remembered %s location %s", verb_string,
3986
stored_location_type, display_url)
2776
display_url = urlutils.unescape_for_display(stored_location, self.outf.encoding)
2777
self.outf.write("%s remembered location %s\n" % (verb_string, display_url))
3987
2778
return stored_location
4190
2960
takes_args = ['context?']
4191
2961
aliases = ['s-c']
4194
2964
@display_command
4195
2965
def run(self, context=None):
4196
2966
import shellcomplete
4197
2967
shellcomplete.shellcomplete(context)
2970
class cmd_fetch(Command):
2971
"""Copy in history from another branch but don't merge it.
2973
This is an internal method used for pull and merge.
2976
takes_args = ['from_branch', 'to_branch']
2977
def run(self, from_branch, to_branch):
2978
from bzrlib.fetch import Fetcher
2979
from_b = Branch.open(from_branch)
2980
to_b = Branch.open(to_branch)
2981
Fetcher(to_b, from_b)
4200
2984
class cmd_missing(Command):
4201
2985
"""Show unmerged/unpulled revisions between two branches.
4203
2987
OTHER_BRANCH may be local or remote.
4205
To filter on a range of revisions, you can use the command -r begin..end
4206
-r revision requests a specific revision, -r ..end or -r begin.. are
4210
1 - some missing revisions
4211
0 - no missing revisions
4215
Determine the missing revisions between this and the branch at the
4216
remembered pull location::
4220
Determine the missing revisions between this and another branch::
4222
bzr missing http://server/branch
4224
Determine the missing revisions up to a specific revision on the other
4227
bzr missing -r ..-10
4229
Determine the missing revisions up to a specific revision on this
4232
bzr missing --my-revision ..-10
4235
2990
_see_also = ['merge', 'pull']
4236
2991
takes_args = ['other_branch?']
4237
2992
takes_options = [
4238
Option('reverse', 'Reverse the order of revisions.'),
4240
'Display changes in the local branch only.'),
4241
Option('this' , 'Same as --mine-only.'),
4242
Option('theirs-only',
4243
'Display changes in the remote branch only.'),
4244
Option('other', 'Same as --theirs-only.'),
4248
custom_help('revision',
4249
help='Filter on other branch revisions (inclusive). '
4250
'See "help revisionspec" for details.'),
4251
Option('my-revision',
4252
type=_parse_revision_str,
4253
help='Filter on local branch revisions (inclusive). '
4254
'See "help revisionspec" for details.'),
4255
Option('include-merges',
4256
'Show all revisions in addition to the mainline ones.'),
2993
Option('reverse', 'Reverse the order of revisions.'),
2995
'Display changes in the local branch only.'),
2996
Option('this' , 'Same as --mine-only.'),
2997
Option('theirs-only',
2998
'Display changes in the remote branch only.'),
2999
Option('other', 'Same as --theirs-only.'),
4258
3004
encoding_type = 'replace'
4260
3006
@display_command
4261
3007
def run(self, other_branch=None, reverse=False, mine_only=False,
4263
log_format=None, long=False, short=False, line=False,
4264
show_ids=False, verbose=False, this=False, other=False,
4265
include_merges=False, revision=None, my_revision=None):
3008
theirs_only=False, log_format=None, long=False, short=False, line=False,
3009
show_ids=False, verbose=False, this=False, other=False):
4266
3010
from bzrlib.missing import find_unmerged, iter_log_revisions
3011
from bzrlib.log import log_formatter
4275
# TODO: We should probably check that we don't have mine-only and
4276
# theirs-only set, but it gets complicated because we also have
4277
# this and other which could be used.
4284
3018
local_branch = Branch.open_containing(u".")[0]
4285
3019
parent = local_branch.get_parent()
4286
3020
if other_branch is None:
4287
3021
other_branch = parent
4288
3022
if other_branch is None:
4289
raise errors.BzrCommandError("No peer location known"
3023
raise errors.BzrCommandError("No peer location known or specified.")
4291
3024
display_url = urlutils.unescape_for_display(parent,
4292
3025
self.outf.encoding)
4293
message("Using saved parent location: "
4294
+ display_url + "\n")
3026
print "Using last location: " + display_url
4296
3028
remote_branch = Branch.open(other_branch)
4297
3029
if remote_branch.base == local_branch.base:
4298
3030
remote_branch = local_branch
4300
3031
local_branch.lock_read()
4301
self.add_cleanup(local_branch.unlock)
4302
local_revid_range = _revision_range_to_revid_range(
4303
_get_revision_range(my_revision, local_branch,
4306
remote_branch.lock_read()
4307
self.add_cleanup(remote_branch.unlock)
4308
remote_revid_range = _revision_range_to_revid_range(
4309
_get_revision_range(revision,
4310
remote_branch, self.name()))
4312
local_extra, remote_extra = find_unmerged(
4313
local_branch, remote_branch, restrict,
4314
backward=not reverse,
4315
include_merges=include_merges,
4316
local_revid_range=local_revid_range,
4317
remote_revid_range=remote_revid_range)
4319
if log_format is None:
4320
registry = log.log_formatter_registry
4321
log_format = registry.get_default(local_branch)
4322
lf = log_format(to_file=self.outf,
4324
show_timezone='original')
4327
if local_extra and not theirs_only:
4328
message("You have %d extra revision(s):\n" %
4330
for revision in iter_log_revisions(local_extra,
4331
local_branch.repository,
4333
lf.log_revision(revision)
4334
printed_local = True
4337
printed_local = False
4339
if remote_extra and not mine_only:
4340
if printed_local is True:
4342
message("You are missing %d revision(s):\n" %
4344
for revision in iter_log_revisions(remote_extra,
4345
remote_branch.repository,
4347
lf.log_revision(revision)
4350
if mine_only and not local_extra:
4351
# We checked local, and found nothing extra
4352
message('This branch is up to date.\n')
4353
elif theirs_only and not remote_extra:
4354
# We checked remote, and found nothing extra
4355
message('Other branch is up to date.\n')
4356
elif not (mine_only or theirs_only or local_extra or
4358
# We checked both branches, and neither one had extra
4360
message("Branches are up to date.\n")
3033
remote_branch.lock_read()
3035
local_extra, remote_extra = find_unmerged(local_branch, remote_branch)
3036
if (log_format is None):
3037
log_format = log.log_formatter_registry.get_default(
3039
lf = log_format(to_file=self.outf,
3041
show_timezone='original')
3042
if reverse is False:
3043
local_extra.reverse()
3044
remote_extra.reverse()
3045
if local_extra and not theirs_only:
3046
print "You have %d extra revision(s):" % len(local_extra)
3047
for revision in iter_log_revisions(local_extra,
3048
local_branch.repository,
3050
lf.log_revision(revision)
3051
printed_local = True
3053
printed_local = False
3054
if remote_extra and not mine_only:
3055
if printed_local is True:
3057
print "You are missing %d revision(s):" % len(remote_extra)
3058
for revision in iter_log_revisions(remote_extra,
3059
remote_branch.repository,
3061
lf.log_revision(revision)
3062
if not remote_extra and not local_extra:
3064
print "Branches are up to date."
3068
remote_branch.unlock()
3070
local_branch.unlock()
4362
3071
if not status_code and parent is None and other_branch is not None:
4363
3072
local_branch.lock_write()
4364
self.add_cleanup(local_branch.unlock)
4365
# handle race conditions - a parent might be set while we run.
4366
if local_branch.get_parent() is None:
4367
local_branch.set_parent(remote_branch.base)
3074
# handle race conditions - a parent might be set while we run.
3075
if local_branch.get_parent() is None:
3076
local_branch.set_parent(remote_branch.base)
3078
local_branch.unlock()
4368
3079
return status_code
5021
3647
s.send_email(message)
5024
class cmd_send(Command):
5025
"""Mail or create a merge-directive for submitting changes.
5027
A merge directive provides many things needed for requesting merges:
5029
* A machine-readable description of the merge to perform
5031
* An optional patch that is a preview of the changes requested
5033
* An optional bundle of revision data, so that the changes can be applied
5034
directly from the merge directive, without retrieving data from a
5037
`bzr send` creates a compact data set that, when applied using bzr
5038
merge, has the same effect as merging from the source branch.
5040
By default the merge directive is self-contained and can be applied to any
5041
branch containing submit_branch in its ancestory without needing access to
5044
If --no-bundle is specified, then Bazaar doesn't send the contents of the
5045
revisions, but only a structured request to merge from the
5046
public_location. In that case the public_branch is needed and it must be
5047
up-to-date and accessible to the recipient. The public_branch is always
5048
included if known, so that people can check it later.
5050
The submit branch defaults to the parent of the source branch, but can be
5051
overridden. Both submit branch and public branch will be remembered in
5052
branch.conf the first time they are used for a particular branch. The
5053
source branch defaults to that containing the working directory, but can
5054
be changed using --from.
5056
In order to calculate those changes, bzr must analyse the submit branch.
5057
Therefore it is most efficient for the submit branch to be a local mirror.
5058
If a public location is known for the submit_branch, that location is used
5059
in the merge directive.
5061
The default behaviour is to send the merge directive by mail, unless -o is
5062
given, in which case it is sent to a file.
5064
Mail is sent using your preferred mail program. This should be transparent
5065
on Windows (it uses MAPI). On Linux, it requires the xdg-email utility.
5066
If the preferred client can't be found (or used), your editor will be used.
5068
To use a specific mail program, set the mail_client configuration option.
5069
(For Thunderbird 1.5, this works around some bugs.) Supported values for
5070
specific clients are "claws", "evolution", "kmail", "mail.app" (MacOS X's
5071
Mail.app), "mutt", and "thunderbird"; generic options are "default",
5072
"editor", "emacsclient", "mapi", and "xdg-email". Plugins may also add
5075
If mail is being sent, a to address is required. This can be supplied
5076
either on the commandline, by setting the submit_to configuration
5077
option in the branch itself or the child_submit_to configuration option
5078
in the submit branch.
5080
Two formats are currently supported: "4" uses revision bundle format 4 and
5081
merge directive format 2. It is significantly faster and smaller than
5082
older formats. It is compatible with Bazaar 0.19 and later. It is the
5083
default. "0.9" uses revision bundle format 0.9 and merge directive
5084
format 1. It is compatible with Bazaar 0.12 - 0.18.
5086
The merge directives created by bzr send may be applied using bzr merge or
5087
bzr pull by specifying a file containing a merge directive as the location.
5089
bzr send makes extensive use of public locations to map local locations into
5090
URLs that can be used by other people. See `bzr help configuration` to
5091
set them, and use `bzr info` to display them.
5094
encoding_type = 'exact'
5096
_see_also = ['merge', 'pull']
5098
takes_args = ['submit_branch?', 'public_branch?']
5102
help='Do not include a bundle in the merge directive.'),
5103
Option('no-patch', help='Do not include a preview patch in the merge'
5106
help='Remember submit and public branch.'),
5108
help='Branch to generate the submission from, '
5109
'rather than the one containing the working directory.',
5112
Option('output', short_name='o',
5113
help='Write merge directive to this file; '
5114
'use - for stdout.',
5117
help='Refuse to send if there are uncommitted changes in'
5118
' the working tree, --no-strict disables the check.'),
5119
Option('mail-to', help='Mail the request to this address.',
5123
Option('body', help='Body for the email.', type=unicode),
5124
RegistryOption('format',
5125
help='Use the specified output format.',
5126
lazy_registry=('bzrlib.send', 'format_registry')),
5129
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
5130
no_patch=False, revision=None, remember=False, output=None,
5131
format=None, mail_to=None, message=None, body=None,
5132
strict=None, **kwargs):
5133
from bzrlib.send import send
5134
return send(submit_branch, revision, public_branch, remember,
5135
format, no_bundle, no_patch, output,
5136
kwargs.get('from', '.'), mail_to, message, body,
5141
class cmd_bundle_revisions(cmd_send):
5142
"""Create a merge-directive for submitting changes.
5144
A merge directive provides many things needed for requesting merges:
5146
* A machine-readable description of the merge to perform
5148
* An optional patch that is a preview of the changes requested
5150
* An optional bundle of revision data, so that the changes can be applied
3650
class cmd_submit(Command):
3651
"""Create a merge-directive for submiting changes.
3653
A merge directive provides many things needed for requesting merges:
3654
- A machine-readable description of the merge to perform
3655
- An optional patch that is a preview of the changes requested
3656
- An optional bundle of revision data, so that the changes can be applied
5151
3657
directly from the merge directive, without retrieving data from a
5285
3832
short_name='d',
5288
RegistryOption.from_kwargs('sort',
5289
'Sort tags by different criteria.', title='Sorting',
5290
alpha='Sort tags lexicographically (default).',
5291
time='Sort tags chronologically.',
5297
3837
@display_command
5304
3841
branch, relpath = Branch.open_containing(directory)
5306
tags = branch.tags.get_tag_dict().items()
5311
self.add_cleanup(branch.unlock)
5313
graph = branch.repository.get_graph()
5314
rev1, rev2 = _get_revision_range(revision, branch, self.name())
5315
revid1, revid2 = rev1.rev_id, rev2.rev_id
5316
# only show revisions between revid1 and revid2 (inclusive)
5317
tags = [(tag, revid) for tag, revid in tags if
5318
graph.is_between(revid, revid1, revid2)]
5321
elif sort == 'time':
5323
for tag, revid in tags:
5325
revobj = branch.repository.get_revision(revid)
5326
except errors.NoSuchRevision:
5327
timestamp = sys.maxint # place them at the end
5329
timestamp = revobj.timestamp
5330
timestamps[revid] = timestamp
5331
tags.sort(key=lambda x: timestamps[x[1]])
5333
# [ (tag, revid), ... ] -> [ (tag, dotted_revno), ... ]
5334
for index, (tag, revid) in enumerate(tags):
5336
revno = branch.revision_id_to_dotted_revno(revid)
5337
if isinstance(revno, tuple):
5338
revno = '.'.join(map(str, revno))
5339
except errors.NoSuchRevision:
5340
# Bad tag data/merges can lead to tagged revisions
5341
# which are not in this branch. Fail gracefully ...
5343
tags[index] = (tag, revno)
5345
for tag, revspec in tags:
5346
self.outf.write('%-20s %s\n' % (tag, revspec))
5349
class cmd_reconfigure(Command):
5350
"""Reconfigure the type of a bzr directory.
5352
A target configuration must be specified.
5354
For checkouts, the bind-to location will be auto-detected if not specified.
5355
The order of preference is
5356
1. For a lightweight checkout, the current bound location.
5357
2. For branches that used to be checkouts, the previously-bound location.
5358
3. The push location.
5359
4. The parent location.
5360
If none of these is available, --bind-to must be specified.
5363
_see_also = ['branches', 'checkouts', 'standalone-trees', 'working-trees']
5364
takes_args = ['location?']
5366
RegistryOption.from_kwargs(
5368
title='Target type',
5369
help='The type to reconfigure the directory to.',
5370
value_switches=True, enum_switch=False,
5371
branch='Reconfigure to be an unbound branch with no working tree.',
5372
tree='Reconfigure to be an unbound branch with a working tree.',
5373
checkout='Reconfigure to be a bound branch with a working tree.',
5374
lightweight_checkout='Reconfigure to be a lightweight'
5375
' checkout (with no local history).',
5376
standalone='Reconfigure to be a standalone branch '
5377
'(i.e. stop using shared repository).',
5378
use_shared='Reconfigure to use a shared repository.',
5379
with_trees='Reconfigure repository to create '
5380
'working trees on branches by default.',
5381
with_no_trees='Reconfigure repository to not create '
5382
'working trees on branches by default.'
5384
Option('bind-to', help='Branch to bind checkout to.', type=str),
5386
help='Perform reconfiguration even if local changes'
5388
Option('stacked-on',
5389
help='Reconfigure a branch to be stacked on another branch.',
5393
help='Reconfigure a branch to be unstacked. This '
5394
'may require copying substantial data into it.',
5398
def run(self, location=None, target_type=None, bind_to=None, force=False,
5401
directory = bzrdir.BzrDir.open(location)
5402
if stacked_on and unstacked:
5403
raise BzrCommandError("Can't use both --stacked-on and --unstacked")
5404
elif stacked_on is not None:
5405
reconfigure.ReconfigureStackedOn().apply(directory, stacked_on)
5407
reconfigure.ReconfigureUnstacked().apply(directory)
5408
# At the moment you can use --stacked-on and a different
5409
# reconfiguration shape at the same time; there seems no good reason
5411
if target_type is None:
5412
if stacked_on or unstacked:
5415
raise errors.BzrCommandError('No target configuration '
5417
elif target_type == 'branch':
5418
reconfiguration = reconfigure.Reconfigure.to_branch(directory)
5419
elif target_type == 'tree':
5420
reconfiguration = reconfigure.Reconfigure.to_tree(directory)
5421
elif target_type == 'checkout':
5422
reconfiguration = reconfigure.Reconfigure.to_checkout(
5424
elif target_type == 'lightweight-checkout':
5425
reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
5427
elif target_type == 'use-shared':
5428
reconfiguration = reconfigure.Reconfigure.to_use_shared(directory)
5429
elif target_type == 'standalone':
5430
reconfiguration = reconfigure.Reconfigure.to_standalone(directory)
5431
elif target_type == 'with-trees':
5432
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
5434
elif target_type == 'with-no-trees':
5435
reconfiguration = reconfigure.Reconfigure.set_repository_trees(
5437
reconfiguration.apply(force)
5440
class cmd_switch(Command):
5441
"""Set the branch of a checkout and update.
5443
For lightweight checkouts, this changes the branch being referenced.
5444
For heavyweight checkouts, this checks that there are no local commits
5445
versus the current bound branch, then it makes the local branch a mirror
5446
of the new location and binds to it.
5448
In both cases, the working tree is updated and uncommitted changes
5449
are merged. The user can commit or revert these as they desire.
5451
Pending merges need to be committed or reverted before using switch.
5453
The path to the branch to switch to can be specified relative to the parent
5454
directory of the current branch. For example, if you are currently in a
5455
checkout of /path/to/branch, specifying 'newbranch' will find a branch at
5458
Bound branches use the nickname of its master branch unless it is set
5459
locally, in which case switching will update the local nickname to be
5463
takes_args = ['to_location?']
5464
takes_options = [Option('force',
5465
help='Switch even if local commits will be lost.'),
5467
Option('create-branch', short_name='b',
5468
help='Create the target branch from this one before'
5469
' switching to it.'),
5472
def run(self, to_location=None, force=False, create_branch=False,
5474
from bzrlib import switch
5476
revision = _get_one_revision('switch', revision)
5477
control_dir = bzrdir.BzrDir.open_containing(tree_location)[0]
5478
if to_location is None:
5479
if revision is None:
5480
raise errors.BzrCommandError('You must supply either a'
5481
' revision or a location')
5484
branch = control_dir.open_branch()
5485
had_explicit_nick = branch.get_config().has_explicit_nickname()
5486
except errors.NotBranchError:
5488
had_explicit_nick = False
5491
raise errors.BzrCommandError('cannot create branch without'
5493
to_location = directory_service.directories.dereference(
5495
if '/' not in to_location and '\\' not in to_location:
5496
# This path is meant to be relative to the existing branch
5497
this_url = self._get_branch_location(control_dir)
5498
to_location = urlutils.join(this_url, '..', to_location)
5499
to_branch = branch.bzrdir.sprout(to_location,
5500
possible_transports=[branch.bzrdir.root_transport],
5501
source_branch=branch).open_branch()
5504
to_branch = Branch.open(to_location)
5505
except errors.NotBranchError:
5506
this_url = self._get_branch_location(control_dir)
5507
to_branch = Branch.open(
5508
urlutils.join(this_url, '..', to_location))
5509
if revision is not None:
5510
revision = revision.as_revision_id(to_branch)
5511
switch.switch(control_dir, to_branch, force, revision_id=revision)
5512
if had_explicit_nick:
5513
branch = control_dir.open_branch() #get the new branch!
5514
branch.nick = to_branch.nick
5515
note('Switched to branch: %s',
5516
urlutils.unescape_for_display(to_branch.base, 'utf-8'))
5518
def _get_branch_location(self, control_dir):
5519
"""Return location of branch for this control dir."""
5521
this_branch = control_dir.open_branch()
5522
# This may be a heavy checkout, where we want the master branch
5523
master_location = this_branch.get_bound_location()
5524
if master_location is not None:
5525
return master_location
5526
# If not, use a local sibling
5527
return this_branch.base
5528
except errors.NotBranchError:
5529
format = control_dir.find_branch_format()
5530
if getattr(format, 'get_reference', None) is not None:
5531
return format.get_reference(control_dir)
5533
return control_dir.root_transport.base
5536
class cmd_view(Command):
5537
"""Manage filtered views.
5539
Views provide a mask over the tree so that users can focus on
5540
a subset of a tree when doing their work. After creating a view,
5541
commands that support a list of files - status, diff, commit, etc -
5542
effectively have that list of files implicitly given each time.
5543
An explicit list of files can still be given but those files
5544
must be within the current view.
5546
In most cases, a view has a short life-span: it is created to make
5547
a selected change and is deleted once that change is committed.
5548
At other times, you may wish to create one or more named views
5549
and switch between them.
5551
To disable the current view without deleting it, you can switch to
5552
the pseudo view called ``off``. This can be useful when you need
5553
to see the whole tree for an operation or two (e.g. merge) but
5554
want to switch back to your view after that.
5557
To define the current view::
5559
bzr view file1 dir1 ...
5561
To list the current view::
5565
To delete the current view::
5569
To disable the current view without deleting it::
5571
bzr view --switch off
5573
To define a named view and switch to it::
5575
bzr view --name view-name file1 dir1 ...
5577
To list a named view::
5579
bzr view --name view-name
5581
To delete a named view::
5583
bzr view --name view-name --delete
5585
To switch to a named view::
5587
bzr view --switch view-name
5589
To list all views defined::
5593
To delete all views::
5595
bzr view --delete --all
5599
takes_args = ['file*']
5602
help='Apply list or delete action to all views.',
5605
help='Delete the view.',
5608
help='Name of the view to define, list or delete.',
5612
help='Name of the view to switch to.',
5617
def run(self, file_list,
5623
tree, file_list = tree_files(file_list, apply_view=False)
5624
current_view, view_dict = tree.views.get_view_info()
5629
raise errors.BzrCommandError(
5630
"Both --delete and a file list specified")
5632
raise errors.BzrCommandError(
5633
"Both --delete and --switch specified")
5635
tree.views.set_view_info(None, {})
5636
self.outf.write("Deleted all views.\n")
5638
raise errors.BzrCommandError("No current view to delete")
5640
tree.views.delete_view(name)
5641
self.outf.write("Deleted '%s' view.\n" % name)
5644
raise errors.BzrCommandError(
5645
"Both --switch and a file list specified")
5647
raise errors.BzrCommandError(
5648
"Both --switch and --all specified")
5649
elif switch == 'off':
5650
if current_view is None:
5651
raise errors.BzrCommandError("No current view to disable")
5652
tree.views.set_view_info(None, view_dict)
5653
self.outf.write("Disabled '%s' view.\n" % (current_view))
5655
tree.views.set_view_info(switch, view_dict)
5656
view_str = views.view_display_str(tree.views.lookup_view())
5657
self.outf.write("Using '%s' view: %s\n" % (switch, view_str))
5660
self.outf.write('Views defined:\n')
5661
for view in sorted(view_dict):
5662
if view == current_view:
5666
view_str = views.view_display_str(view_dict[view])
5667
self.outf.write('%s %-20s %s\n' % (active, view, view_str))
5669
self.outf.write('No views defined.\n')
5672
# No name given and no current view set
5675
raise errors.BzrCommandError(
5676
"Cannot change the 'off' pseudo view")
5677
tree.views.set_view(name, sorted(file_list))
5678
view_str = views.view_display_str(tree.views.lookup_view())
5679
self.outf.write("Using '%s' view: %s\n" % (name, view_str))
5683
# No name given and no current view set
5684
self.outf.write('No current view.\n')
5686
view_str = views.view_display_str(tree.views.lookup_view(name))
5687
self.outf.write("'%s' view is: %s\n" % (name, view_str))
5690
class cmd_hooks(Command):
5696
for hook_key in sorted(hooks.known_hooks.keys()):
5697
some_hooks = hooks.known_hooks_key_to_object(hook_key)
5698
self.outf.write("%s:\n" % type(some_hooks).__name__)
5699
for hook_name, hook_point in sorted(some_hooks.items()):
5700
self.outf.write(" %s:\n" % (hook_name,))
5701
found_hooks = list(hook_point)
5703
for hook in found_hooks:
5704
self.outf.write(" %s\n" %
5705
(some_hooks.get_hook_name(hook),))
5707
self.outf.write(" <no hooks installed>\n")
5710
class cmd_shelve(Command):
5711
"""Temporarily set aside some changes from the current tree.
5713
Shelve allows you to temporarily put changes you've made "on the shelf",
5714
ie. out of the way, until a later time when you can bring them back from
5715
the shelf with the 'unshelve' command. The changes are stored alongside
5716
your working tree, and so they aren't propagated along with your branch nor
5717
will they survive its deletion.
5719
If shelve --list is specified, previously-shelved changes are listed.
5721
Shelve is intended to help separate several sets of changes that have
5722
been inappropriately mingled. If you just want to get rid of all changes
5723
and you don't need to restore them later, use revert. If you want to
5724
shelve all text changes at once, use shelve --all.
5726
If filenames are specified, only the changes to those files will be
5727
shelved. Other files will be left untouched.
5729
If a revision is specified, changes since that revision will be shelved.
5731
You can put multiple items on the shelf, and by default, 'unshelve' will
5732
restore the most recently shelved changes.
5735
takes_args = ['file*']
5739
Option('all', help='Shelve all changes.'),
5741
RegistryOption('writer', 'Method to use for writing diffs.',
5742
bzrlib.option.diff_writer_registry,
5743
value_switches=True, enum_switch=False),
5745
Option('list', help='List shelved changes.'),
5747
help='Destroy removed changes instead of shelving them.'),
5749
_see_also = ['unshelve']
5751
def run(self, revision=None, all=False, file_list=None, message=None,
5752
writer=None, list=False, destroy=False):
5754
return self.run_for_list()
5755
from bzrlib.shelf_ui import Shelver
5757
writer = bzrlib.option.diff_writer_registry.get()
5759
shelver = Shelver.from_args(writer(sys.stdout), revision, all,
5760
file_list, message, destroy=destroy)
5765
except errors.UserAbort:
5768
def run_for_list(self):
5769
tree = WorkingTree.open_containing('.')[0]
5771
self.add_cleanup(tree.unlock)
5772
manager = tree.get_shelf_manager()
5773
shelves = manager.active_shelves()
5774
if len(shelves) == 0:
5775
note('No shelved changes.')
5777
for shelf_id in reversed(shelves):
5778
message = manager.get_metadata(shelf_id).get('message')
5780
message = '<no message>'
5781
self.outf.write('%3d: %s\n' % (shelf_id, message))
5785
class cmd_unshelve(Command):
5786
"""Restore shelved changes.
5788
By default, the most recently shelved changes are restored. However if you
5789
specify a shelf by id those changes will be restored instead. This works
5790
best when the changes don't depend on each other.
5793
takes_args = ['shelf_id?']
5795
RegistryOption.from_kwargs(
5796
'action', help="The action to perform.",
5797
enum_switch=False, value_switches=True,
5798
apply="Apply changes and remove from the shelf.",
5799
dry_run="Show changes, but do not apply or remove them.",
5800
preview="Instead of unshelving the changes, show the diff that "
5801
"would result from unshelving.",
5802
delete_only="Delete changes without applying them.",
5803
keep="Apply changes but don't delete them.",
5806
_see_also = ['shelve']
5808
def run(self, shelf_id=None, action='apply'):
5809
from bzrlib.shelf_ui import Unshelver
5810
unshelver = Unshelver.from_args(shelf_id, action)
5814
unshelver.tree.unlock()
5817
class cmd_clean_tree(Command):
5818
"""Remove unwanted files from working tree.
5820
By default, only unknown files, not ignored files, are deleted. Versioned
5821
files are never deleted.
5823
Another class is 'detritus', which includes files emitted by bzr during
5824
normal operations and selftests. (The value of these files decreases with
5827
If no options are specified, unknown files are deleted. Otherwise, option
5828
flags are respected, and may be combined.
5830
To check what clean-tree will do, use --dry-run.
5832
takes_options = [Option('ignored', help='Delete all ignored files.'),
5833
Option('detritus', help='Delete conflict files, merge'
5834
' backups, and failed selftest dirs.'),
5836
help='Delete files unknown to bzr (default).'),
5837
Option('dry-run', help='Show files to delete instead of'
5839
Option('force', help='Do not prompt before deleting.')]
5840
def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
5842
from bzrlib.clean_tree import clean_tree
5843
if not (unknown or ignored or detritus):
5847
clean_tree('.', unknown=unknown, ignored=ignored, detritus=detritus,
5848
dry_run=dry_run, no_prompt=force)
5851
class cmd_reference(Command):
5852
"""list, view and set branch locations for nested trees.
5854
If no arguments are provided, lists the branch locations for nested trees.
5855
If one argument is provided, display the branch location for that tree.
5856
If two arguments are provided, set the branch location for that tree.
5861
takes_args = ['path?', 'location?']
5863
def run(self, path=None, location=None):
5865
if path is not None:
5867
tree, branch, relpath =(
5868
bzrdir.BzrDir.open_containing_tree_or_branch(branchdir))
5869
if path is not None:
5872
tree = branch.basis_tree()
5874
info = branch._get_all_reference_info().iteritems()
5875
self._display_reference_info(tree, branch, info)
5877
file_id = tree.path2id(path)
5879
raise errors.NotVersionedError(path)
5880
if location is None:
5881
info = [(file_id, branch.get_reference_info(file_id))]
5882
self._display_reference_info(tree, branch, info)
5884
branch.set_reference_info(file_id, path, location)
5886
def _display_reference_info(self, tree, branch, info):
5888
for file_id, (path, location) in info:
5890
path = tree.id2path(file_id)
5891
except errors.NoSuchId:
5893
ref_list.append((path, location))
5894
for path, location in sorted(ref_list):
5895
self.outf.write('%s %s\n' % (path, location))
3842
for tag_name, target in sorted(branch.tags.get_tag_dict().items()):
3843
self.outf.write('%-20s %s\n' % (tag_name, target))
3846
# command-line interpretation helper for merge-related commands
3847
def _merge_helper(other_revision, base_revision,
3848
check_clean=True, ignore_zero=False,
3849
this_dir=None, backup_files=False,
3851
file_list=None, show_base=False, reprocess=False,
3854
change_reporter=None,
3855
other_rev_id=None, base_rev_id=None):
3856
"""Merge changes into a tree.
3859
list(path, revno) Base for three-way merge.
3860
If [None, None] then a base will be automatically determined.
3862
list(path, revno) Other revision for three-way merge.
3864
Directory to merge changes into; '.' by default.
3866
If true, this_dir must have no uncommitted changes before the
3868
ignore_zero - If true, suppress the "zero conflicts" message when
3869
there are no conflicts; should be set when doing something we expect
3870
to complete perfectly.
3871
file_list - If supplied, merge only changes to selected files.
3873
All available ancestors of other_revision and base_revision are
3874
automatically pulled into the branch.
3876
The revno may be -1 to indicate the last revision on the branch, which is
3879
This function is intended for use from the command line; programmatic
3880
clients might prefer to call merge.merge_inner(), which has less magic
3883
# Loading it late, so that we don't always have to import bzrlib.merge
3884
if merge_type is None:
3885
merge_type = _mod_merge.Merge3Merger
3886
if this_dir is None:
3888
this_tree = WorkingTree.open_containing(this_dir)[0]
3889
if show_base and not merge_type is _mod_merge.Merge3Merger:
3890
raise errors.BzrCommandError("Show-base is not supported for this merge"
3891
" type. %s" % merge_type)
3892
if reprocess and not merge_type.supports_reprocess:
3893
raise errors.BzrCommandError("Conflict reduction is not supported for merge"
3894
" type %s." % merge_type)
3895
if reprocess and show_base:
3896
raise errors.BzrCommandError("Cannot do conflict reduction and show base.")
3897
# TODO: jam 20070226 We should really lock these trees earlier. However, we
3898
# only want to take out a lock_tree_write() if we don't have to pull
3899
# any ancestry. But merge might fetch ancestry in the middle, in
3900
# which case we would need a lock_write().
3901
# Because we cannot upgrade locks, for now we live with the fact that
3902
# the tree will be locked multiple times during a merge. (Maybe
3903
# read-only some of the time, but it means things will get read
3906
merger = _mod_merge.Merger(this_tree.branch, this_tree=this_tree,
3907
pb=pb, change_reporter=change_reporter)
3908
merger.pp = ProgressPhase("Merge phase", 5, pb)
3909
merger.pp.next_phase()
3910
merger.check_basis(check_clean)
3911
if other_rev_id is not None:
3912
merger.set_other_revision(other_rev_id, this_tree.branch)
3914
merger.set_other(other_revision)
3915
merger.pp.next_phase()
3916
if base_rev_id is not None:
3917
merger.set_base_revision(base_rev_id, this_tree.branch)
3918
elif base_revision is not None:
3919
merger.set_base(base_revision)
3922
if merger.base_rev_id == merger.other_rev_id:
3923
note('Nothing to do.')
3925
if file_list is None:
3926
if pull and merger.base_rev_id == merger.this_rev_id:
3927
# FIXME: deduplicate with pull
3928
result = merger.this_tree.pull(merger.this_branch,
3929
False, merger.other_rev_id)
3930
if result.old_revid == result.new_revid:
3931
note('No revisions to pull.')
3933
note('Now on revision %d.' % result.new_revno)
3935
merger.backup_files = backup_files
3936
merger.merge_type = merge_type
3937
merger.set_interesting_files(file_list)
3938
merger.show_base = show_base
3939
merger.reprocess = reprocess
3940
conflicts = merger.do_merge()
3941
if file_list is None:
3942
merger.set_pending()
3948
def _create_prefix(cur_transport):
3949
needed = [cur_transport]
3950
# Recurse upwards until we can create a directory successfully
3952
new_transport = cur_transport.clone('..')
3953
if new_transport.base == cur_transport.base:
3954
raise errors.BzrCommandError(
3955
"Failed to create path prefix for %s."
3956
% cur_transport.base)
3958
new_transport.mkdir('.')
3959
except errors.NoSuchFile:
3960
needed.append(new_transport)
3961
cur_transport = new_transport
3964
# Now we only need to create child directories
3966
cur_transport = needed.pop()
3967
cur_transport.ensure_base()
3971
merge = _merge_helper
5898
3974
# these get imported and then picked up by the scan for cmd_*
5899
3975
# TODO: Some more consistent way to split command definitions across files;
5900
# we do need to load at least some information about them to know of
3976
# we do need to load at least some information about them to know of
5901
3977
# aliases. ideally we would avoid loading the implementation until the
5902
3978
# details were needed.
5903
3979
from bzrlib.cmd_version_info import cmd_version_info