41
from bzrlib.branch import Branch, BranchReferenceFormat
42
from bzrlib.bundle import read_bundle_from_url
44
from bzrlib.branch import Branch
43
45
from bzrlib.bundle.apply_bundle import install_bundle, merge_bundle
44
46
from bzrlib.conflicts import ConflictList
47
from bzrlib.revision import common_ancestor
48
from bzrlib.revisionspec import RevisionSpec
49
from bzrlib.workingtree import WorkingTree
45
52
from bzrlib.commands import Command, display_command
46
from bzrlib.errors import (BzrError, BzrCheckError, BzrCommandError,
47
NotBranchError, DivergedBranches, NotConflicted,
48
NoSuchFile, NoWorkingTree, FileInWrongBranch,
49
NotVersionedError, NotABundle)
50
from bzrlib.merge import Merge3Merger
51
53
from bzrlib.option import Option
52
54
from bzrlib.progress import DummyProgress, ProgressPhase
53
from bzrlib.revision import common_ancestor
54
from bzrlib.revisionspec import RevisionSpec
55
55
from bzrlib.trace import mutter, note, log_error, warning, is_quiet, info
56
from bzrlib.transport.local import LocalTransport
57
from bzrlib.workingtree import WorkingTree
60
58
def tree_files(file_list, default_branch=u'.'):
62
60
return internal_tree_files(file_list, default_branch)
63
except FileInWrongBranch, e:
64
raise BzrCommandError("%s is not in the same branch as %s" %
65
(e.path, file_list[0]))
61
except errors.FileInWrongBranch, e:
62
raise errors.BzrCommandError("%s is not in the same branch as %s" %
63
(e.path, file_list[0]))
68
66
# XXX: Bad function name; should possibly also be a class method of
107
105
format = bzrdir.BzrDirMetaFormat1()
108
106
format.repository_format = repository.RepositoryFormatKnit1()
108
if typestring == "experimental-knit2":
109
format = bzrdir.BzrDirMetaFormat1()
110
format.repository_format = repository.RepositoryFormatKnit2()
110
112
msg = "Unknown bzr format %s. Current formats are: default, knit,\n" \
111
113
"metaweave and weave" % typestring
112
raise BzrCommandError(msg)
114
raise errors.BzrCommandError(msg)
115
117
# TODO: Make sure no commands unconditionally use the working directory as a
190
192
def run(self, revision_id=None, revision=None):
192
194
if revision_id is not None and revision is not None:
193
raise BzrCommandError('You can only supply one of revision_id or --revision')
195
raise errors.BzrCommandError('You can only supply one of'
196
' revision_id or --revision')
194
197
if revision_id is None and revision is None:
195
raise BzrCommandError('You must supply either --revision or a revision_id')
198
raise errors.BzrCommandError('You must supply either'
199
' --revision or a revision_id')
196
200
b = WorkingTree.open_containing(u'.')[0].branch
198
202
# TODO: jam 20060112 should cat-revision always output utf-8?
294
299
base_tree, base_path = WorkingTree.open_containing(
296
301
except errors.NoWorkingTree:
297
base_branch, base_path = branch.Branch.open_containing(
302
base_branch, base_path = Branch.open_containing(
299
304
base_tree = base_branch.basis_tree()
357
362
"""Show inventory of the current working copy or a revision.
359
364
It is possible to limit the output to a particular entry
360
type using the --kind option. For example; --kind file.
365
type using the --kind option. For example: --kind file.
367
It is also possible to restrict the list of files to a specific
368
set. For example: bzr inventory --show-ids this/file
363
371
takes_options = ['revision', 'show-ids', 'kind']
372
takes_args = ['file*']
366
def run(self, revision=None, show_ids=False, kind=None):
375
def run(self, revision=None, show_ids=False, kind=None, file_list=None):
367
376
if kind and kind not in ['file', 'directory', 'symlink']:
368
raise BzrCommandError('invalid kind specified')
369
tree = WorkingTree.open_containing(u'.')[0]
371
inv = tree.read_working_inventory()
377
raise errors.BzrCommandError('invalid kind specified')
379
work_tree, file_list = tree_files(file_list)
381
if revision is not None:
373
382
if len(revision) > 1:
374
raise BzrCommandError('bzr inventory --revision takes'
375
' exactly one revision identifier')
376
inv = tree.branch.repository.get_revision_inventory(
377
revision[0].in_history(tree.branch).rev_id)
379
for path, entry in inv.entries():
383
raise errors.BzrCommandError('bzr inventory --revision takes'
384
' exactly one revision identifier')
385
revision_id = revision[0].in_history(work_tree.branch).rev_id
386
tree = work_tree.branch.repository.revision_tree(revision_id)
388
# We include work_tree as well as 'tree' here
389
# So that doing '-r 10 path/foo' will lookup whatever file
390
# exists now at 'path/foo' even if it has been renamed, as
391
# well as whatever files existed in revision 10 at path/foo
392
trees = [tree, work_tree]
397
if file_list is not None:
398
file_ids = _mod_tree.find_ids_across_trees(file_list, trees,
399
require_versioned=True)
400
# find_ids_across_trees may include some paths that don't
402
entries = sorted((tree.id2path(file_id), tree.inventory[file_id])
403
for file_id in file_ids if file_id in tree)
405
entries = tree.inventory.entries()
407
for path, entry in entries:
380
408
if kind and kind != entry.kind:
418
446
self.outf.write("%s => %s\n" % pair)
420
448
if len(names_list) != 2:
421
raise BzrCommandError('to mv multiple files the destination '
422
'must be a versioned directory')
449
raise errors.BzrCommandError('to mv multiple files the destination '
450
'must be a versioned directory')
423
451
tree.rename_one(rel_names[0], rel_names[1])
424
452
self.outf.write("%s => %s\n" % (rel_names[0], rel_names[1]))
461
489
if location is not None:
463
491
reader = bundle.read_bundle_from_url(location)
492
except errors.NotABundle:
465
493
pass # Continue on considering this url a Branch
467
495
stored_loc = branch_to.get_parent()
468
496
if location is None:
469
497
if stored_loc is None:
470
raise BzrCommandError("No pull location known or specified.")
498
raise errors.BzrCommandError("No pull location known or"
472
501
display_url = urlutils.unescape_for_display(stored_loc,
473
502
self.outf.encoding)
573
602
relurl = to_transport.relpath(location_url)
574
603
mutter('creating directory %s => %s', location_url, relurl)
575
604
to_transport.mkdir(relurl)
577
raise BzrCommandError("Parent directory of %s "
578
"does not exist." % location)
605
except errors.NoSuchFile:
606
raise errors.BzrCommandError("Parent directory of %s "
607
"does not exist." % location)
580
609
current = to_transport.base
581
610
needed = [(to_transport, to_transport.relpath(location_url))]
584
613
to_transport, relpath = needed[-1]
585
614
to_transport.mkdir(relpath)
616
except errors.NoSuchFile:
588
617
new_transport = to_transport.clone('..')
589
618
needed.append((new_transport,
590
619
new_transport.relpath(to_transport.base)))
591
620
if new_transport.base == to_transport.base:
592
raise BzrCommandError("Could not create "
621
raise errors.BzrCommandError("Could not create "
594
623
dir_to = br_from.bzrdir.clone(location_url,
595
624
revision_id=br_from.last_revision())
596
625
br_to = dir_to.open_branch()
611
640
warning('This transport does not update the working '
612
641
'tree of: %s' % (br_to.base,))
613
642
count = br_to.pull(br_from, overwrite)
614
except NoWorkingTree:
643
except errors.NoWorkingTree:
615
644
count = br_to.pull(br_from, overwrite)
617
646
count = tree_to.pull(br_from, overwrite)
618
except DivergedBranches:
619
raise BzrCommandError("These branches have diverged."
620
" Try a merge then push with overwrite.")
647
except errors.DivergedBranches:
648
raise errors.BzrCommandError('These branches have diverged.'
649
' Try using "merge" and then "push".')
621
650
note('%d revision(s) pushed.' % (count,))
684
713
to_transport.mkdir('.')
685
714
except errors.FileExists:
686
raise BzrCommandError('Target directory "%s" already'
687
' exists.' % to_location)
715
raise errors.BzrCommandError('Target directory "%s" already'
716
' exists.' % to_location)
688
717
except errors.NoSuchFile:
689
raise BzrCommandError('Parent of "%s" does not exist.' %
718
raise errors.BzrCommandError('Parent of "%s" does not exist.'
692
721
# preserve whatever source format we have.
693
722
dir = br_from.bzrdir.sprout(to_transport.base,
696
725
except errors.NoSuchRevision:
697
726
to_transport.delete_tree('.')
698
727
msg = "The branch %s has no revision %s." % (from_location, revision[0])
699
raise BzrCommandError(msg)
728
raise errors.BzrCommandError(msg)
700
729
except errors.UnlistableBranch:
701
730
osutils.rmtree(to_location)
702
731
msg = "The branch %s cannot be used as a --basis" % (basis,)
703
raise BzrCommandError(msg)
732
raise errors.BzrCommandError(msg)
705
734
branch.control_files.put_utf8('branch-name', name)
706
735
note('Branched %d revision(s).' % branch.revno())
760
789
# if the source and to_location are the same,
761
790
# and there is no working tree,
762
791
# then reconstitute a branch
763
if (osutils.abspath(to_location) ==
792
if (osutils.abspath(to_location) ==
764
793
osutils.abspath(branch_location)):
766
795
source.bzrdir.open_workingtree()
771
800
os.mkdir(to_location)
772
801
except OSError, e:
773
802
if e.errno == errno.EEXIST:
774
raise BzrCommandError('Target directory "%s" already'
775
' exists.' % to_location)
803
raise errors.BzrCommandError('Target directory "%s" already'
804
' exists.' % to_location)
776
805
if e.errno == errno.ENOENT:
777
raise BzrCommandError('Parent of "%s" does not exist.' %
806
raise errors.BzrCommandError('Parent of "%s" does not exist.'
781
810
old_format = bzrdir.BzrDirFormat.get_default_format()
798
827
def run(self, dir=u'.'):
799
from bzrlib.tree import find_renames
800
828
tree = WorkingTree.open_containing(dir)[0]
801
829
old_inv = tree.basis_tree().inventory
802
830
new_inv = tree.read_working_inventory()
803
renames = list(find_renames(old_inv, new_inv))
831
renames = list(_mod_tree.find_renames(old_inv, new_inv))
805
833
for old_name, new_name in renames:
806
834
self.outf.write("%s => %s\n" % (old_name, new_name))
823
851
tree = WorkingTree.open_containing(dir)[0]
824
852
tree.lock_write()
826
existing_pending_merges = tree.pending_merges()
854
existing_pending_merges = tree.get_parent_ids()[1:]
827
855
last_rev = tree.last_revision()
828
856
if last_rev == tree.branch.last_revision():
829
857
# may be up to date, check master too.
835
863
conflicts = tree.update()
836
864
revno = tree.branch.revision_id_to_revno(tree.last_revision())
837
865
note('Updated to revision %d.' % (revno,))
838
if tree.pending_merges() != existing_pending_merges:
866
if tree.get_parent_ids()[1:] != existing_pending_merges:
839
867
note('Your local commits will now show as pending merges with '
840
868
"'bzr status', and can be committed with 'bzr commit'.")
841
869
if conflicts != 0:
885
913
tree, file_list = tree_files(file_list)
887
915
if file_list is None:
888
raise BzrCommandError('Specify one or more files to remove, or'
916
raise errors.BzrCommandError('Specify one or more files to'
917
' remove, or use --new.')
891
919
added = tree.changes_from(tree.basis_tree(),
892
920
specific_files=file_list).added
893
921
file_list = sorted([f[0] for f in added], reverse=True)
894
922
if len(file_list) == 0:
895
raise BzrCommandError('No matching files.')
923
raise errors.BzrCommandError('No matching files.')
896
924
tree.remove(file_list, verbose=verbose, to_file=self.outf)
932
960
tree, relpath = WorkingTree.open_containing(filename)
933
961
inv = tree.inventory
934
962
fid = inv.path2id(relpath)
936
raise BzrError("%r is not a versioned file" % filename)
964
raise errors.BzrError("%r is not a versioned file" % filename)
937
965
for fip in inv.get_idpath(fid):
938
966
self.outf.write(fip + '\n')
1055
1083
existing_bzrdir = bzrdir.BzrDir.open(location)
1056
except NotBranchError:
1084
except errors.NotBranchError:
1057
1085
# really a NotBzrDir error...
1058
1086
bzrdir.BzrDir.create_branch_convenience(location, format=format)
1088
from bzrlib.transport.local import LocalTransport
1060
1089
if existing_bzrdir.has_branch():
1061
1090
if (isinstance(to_transport, LocalTransport)
1062
1091
and not existing_bzrdir.has_workingtree()):
1174
except FileInWrongBranch:
1204
except errors.FileInWrongBranch:
1175
1205
if len(file_list) != 2:
1176
raise BzrCommandError("Files are in different branches")
1206
raise errors.BzrCommandError("Files are in different branches")
1178
1208
tree1, file1 = WorkingTree.open_containing(file_list[0])
1179
1209
tree2, file2 = WorkingTree.open_containing(file_list[1])
1180
1210
if file1 != "" or file2 != "":
1181
1211
# FIXME diff those two files. rbc 20051123
1182
raise BzrCommandError("Files are in different branches")
1212
raise errors.BzrCommandError("Files are in different branches")
1183
1213
file_list = None
1184
except NotBranchError:
1214
except errors.NotBranchError:
1185
1215
if (revision is not None and len(revision) == 2
1186
1216
and not revision[0].needs_branch()
1187
1217
and not revision[1].needs_branch()):
1202
1232
revision[0], revision[1],
1203
1233
old_label=old_label, new_label=new_label)
1205
raise BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
1235
raise errors.BzrCommandError('bzr diff --revision takes exactly'
1236
' one or two revision identifiers')
1207
1238
if tree2 is not None:
1208
1239
return show_diff_trees(tree1, tree2, sys.stdout,
1347
1380
# local dir only
1348
1381
# FIXME ? log the current subdir only RBC 20060203
1349
dir, relpath = bzrdir.BzrDir.open_containing('.')
1382
if revision is not None \
1383
and len(revision) > 0 and revision[0].get_branch():
1384
location = revision[0].get_branch()
1387
dir, relpath = bzrdir.BzrDir.open_containing(location)
1350
1388
b = dir.open_branch()
1352
1390
if revision is None:
1355
1393
elif len(revision) == 1:
1356
1394
rev1 = rev2 = revision[0].in_history(b).revno
1357
1395
elif len(revision) == 2:
1396
if revision[1].get_branch() != revision[0].get_branch():
1397
# b is taken from revision[0].get_branch(), and
1398
# show_log will use its revision_history. Having
1399
# different branches will lead to weird behaviors.
1400
raise errors.BzrCommandError(
1401
"Log doesn't accept two revisions in different branches.")
1358
1402
if revision[0].spec is None:
1359
1403
# missing begin-range means first revision
1368
1412
rev2 = revision[1].in_history(b).revno
1370
raise BzrCommandError('bzr log --revision takes one or two values.')
1414
raise errors.BzrCommandError('bzr log --revision takes one or two values.')
1372
1416
# By this point, the revision numbers are converted to the +ve
1373
1417
# form if they were supplied in the -ve form, so we can do
1461
1505
tree = tree.branch.repository.revision_tree(
1462
1506
revision[0].in_history(tree.branch).rev_id)
1464
for fp, fc, kind, fid, entry in tree.list_files():
1508
for fp, fc, kind, fid, entry in tree.list_files(include_root=False):
1465
1509
if fp.startswith(relpath):
1466
1510
fp = fp[len(relpath):]
1467
1511
if non_recursive and '/' in fp:
1620
1664
rev_id = b.last_revision()
1622
1666
if len(revision) != 1:
1623
raise BzrError('bzr export --revision takes exactly 1 argument')
1667
raise errors.BzrError('bzr export --revision takes exactly'
1624
1669
rev_id = revision[0].in_history(b).rev_id
1625
1670
t = b.repository.revision_tree(rev_id)
1627
1672
export(t, dest, format, root)
1628
1673
except errors.NoSuchExportFormat, e:
1629
raise BzrCommandError('Unsupported export format: %s' % e.format)
1674
raise errors.BzrCommandError('Unsupported export format: %s' % e.format)
1632
1677
class cmd_cat(Command):
1638
1683
@display_command
1639
1684
def run(self, filename, revision=None):
1640
1685
if revision is not None and len(revision) != 1:
1641
raise BzrCommandError("bzr cat --revision takes exactly one number")
1686
raise errors.BzrCommandError("bzr cat --revision takes exactly one number")
1644
1689
tree, relpath = WorkingTree.open_containing(filename)
1645
1690
b = tree.branch
1646
except NotBranchError:
1691
except errors.NotBranchError:
1649
1694
if tree is None:
1650
1695
b, relpath = Branch.open_containing(filename)
1696
if revision is not None and revision[0].get_branch() is not None:
1697
b = Branch.open(revision[0].get_branch())
1651
1698
if revision is None:
1652
1699
revision_id = b.last_revision()
1735
1782
template = make_commit_message_template(tree, selected_list)
1736
1783
message = edit_commit_message(template)
1737
1784
if message is None:
1738
raise BzrCommandError("please specify a commit message"
1739
" with either --message or --file")
1785
raise errors.BzrCommandError("please specify a commit message"
1786
" with either --message or --file")
1740
1787
elif message and file:
1741
raise BzrCommandError("please specify either --message or --file")
1788
raise errors.BzrCommandError("please specify either --message or --file")
1744
1791
message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
1746
1793
if message == "":
1747
raise BzrCommandError("empty commit message specified")
1794
raise errors.BzrCommandError("empty commit message specified")
1750
1797
reporter = ReportCommitToLog()
1758
1805
except PointlessCommit:
1759
1806
# FIXME: This should really happen before the file is read in;
1760
1807
# perhaps prepare the commit; get the message; then actually commit
1761
raise BzrCommandError("no changes to commit."
1762
" use --unchanged to commit anyhow")
1808
raise errors.BzrCommandError("no changes to commit."
1809
" use --unchanged to commit anyhow")
1763
1810
except ConflictsInTree:
1764
raise BzrCommandError("Conflicts detected in working tree. "
1811
raise errors.BzrCommandError("Conflicts detected in working tree. "
1765
1812
'Use "bzr conflicts" to list, "bzr resolve FILE" to resolve.')
1766
1813
except StrictCommitFailed:
1767
raise BzrCommandError("Commit refused because there are unknown "
1768
"files in the working tree.")
1814
raise errors.BzrCommandError("Commit refused because there are unknown "
1815
"files in the working tree.")
1769
1816
except errors.BoundBranchOutOfDate, e:
1770
raise BzrCommandError(str(e) + "\n"
1817
raise errors.BzrCommandError(str(e) + "\n"
1771
1818
'To commit to master branch, run update and then commit.\n'
1772
1819
'You can also pass --local to commit to continue working '
1773
1820
'disconnected.')
1868
1915
# display a warning if an email address isn't included in the given name.
1870
1917
config.extract_email_address(name)
1918
except errors.NoEmailInUsername, e:
1872
1919
warning('"%s" does not seem to contain an email address. '
1873
1920
'This is allowed, but not recommended.', name)
2041
2089
@display_command
2042
2090
def run(self, branch, other):
2043
from bzrlib.revision import common_ancestor, MultipleRevisionSources
2091
from bzrlib.revision import MultipleRevisionSources
2045
2093
branch1 = Branch.open_containing(branch)[0]
2046
2094
branch2 = Branch.open_containing(other)[0]
2108
2156
' from a working copy, instead of branch changes')]
2110
2158
def help(self):
2111
from merge import merge_type_help
2112
2159
from inspect import getdoc
2113
return getdoc(self) + '\n' + merge_type_help()
2160
return getdoc(self) + '\n' + _mod_merge.merge_type_help()
2115
2162
def run(self, branch=None, revision=None, force=False, merge_type=None,
2116
2163
show_base=False, reprocess=False, remember=False,
2117
2164
uncommitted=False):
2118
2165
if merge_type is None:
2119
merge_type = Merge3Merger
2166
merge_type = _mod_merge.Merge3Merger
2121
2168
tree = WorkingTree.open_containing(u'.')[0]
2123
2170
if branch is not None:
2125
2172
reader = bundle.read_bundle_from_url(branch)
2173
except errors.NotABundle:
2127
2174
pass # Continue on considering this url a Branch
2129
2176
conflicts = merge_bundle(reader, tree, not force, merge_type,
2145
2194
other_branch, path = Branch.open_containing(branch)
2147
2196
if uncommitted:
2148
raise BzrCommandError('Cannot use --uncommitted and --revision'
2149
' at the same time.')
2197
raise errors.BzrCommandError('Cannot use --uncommitted and'
2198
' --revision at the same time.')
2199
branch = revision[0].get_branch() or branch
2150
2200
if len(revision) == 1:
2151
2201
base = [None, None]
2152
2202
other_branch, path = Branch.open_containing(branch)
2156
2206
assert len(revision) == 2
2157
2207
if None in revision:
2158
raise BzrCommandError(
2159
"Merge doesn't permit that revision specifier.")
2160
other_branch, path = Branch.open_containing(branch)
2208
raise errors.BzrCommandError(
2209
"Merge doesn't permit empty revision specifier.")
2210
base_branch, path = Branch.open_containing(branch)
2211
branch1 = revision[1].get_branch() or branch
2212
other_branch, path1 = Branch.open_containing(branch1)
2213
if revision[0].get_branch() is not None:
2214
# then path was obtained from it, and is None.
2162
base = [branch, revision[0].in_history(other_branch).revno]
2163
other = [branch, revision[1].in_history(other_branch).revno]
2217
base = [branch, revision[0].in_history(base_branch).revno]
2218
other = [branch1, revision[1].in_history(other_branch).revno]
2165
2220
if tree.branch.get_parent() is None or remember:
2166
2221
tree.branch.set_parent(other_branch.base)
2172
2227
pb = ui.ui_factory.nested_progress_bar()
2175
conflict_count = merge(other, base, check_clean=(not force),
2176
merge_type=merge_type,
2177
reprocess=reprocess,
2178
show_base=show_base,
2179
pb=pb, file_list=interesting_files)
2230
conflict_count = _merge_helper(
2231
other, base, check_clean=(not force),
2232
merge_type=merge_type,
2233
reprocess=reprocess,
2234
show_base=show_base,
2235
pb=pb, file_list=interesting_files)
2182
2238
if conflict_count != 0:
2203
2259
stored_location = tree.branch.get_parent()
2204
2260
mutter("%s", stored_location)
2205
2261
if stored_location is None:
2206
raise BzrCommandError("No location specified or remembered")
2262
raise errors.BzrCommandError("No location specified or remembered")
2207
2263
display_url = urlutils.unescape_for_display(stored_location, self.outf.encoding)
2208
2264
self.outf.write("%s remembered location %s\n" % (verb_string, display_url))
2209
2265
return stored_location
2238
2294
def help(self):
2239
from merge import merge_type_help
2240
2295
from inspect import getdoc
2241
return getdoc(self) + '\n' + merge_type_help()
2296
return getdoc(self) + '\n' + _mod_merge.merge_type_help()
2243
2298
def run(self, file_list=None, merge_type=None, show_base=False,
2244
2299
reprocess=False):
2245
from bzrlib.merge import merge_inner, transform_tree
2246
2300
if merge_type is None:
2247
merge_type = Merge3Merger
2301
merge_type = _mod_merge.Merge3Merger
2248
2302
tree, file_list = tree_files(file_list)
2249
2303
tree.lock_write()
2251
2305
parents = tree.get_parent_ids()
2252
2306
if len(parents) != 2:
2253
raise BzrCommandError("Sorry, remerge only works after normal"
2254
" merges. Not cherrypicking or"
2307
raise errors.BzrCommandError("Sorry, remerge only works after normal"
2308
" merges. Not cherrypicking or"
2256
2310
repository = tree.branch.repository
2257
2311
base_revision = common_ancestor(parents[0],
2258
2312
parents[1], repository)
2274
2328
for name, ie in tree.inventory.iter_entries(file_id):
2275
2329
interesting_ids.add(ie.file_id)
2276
2330
new_conflicts = conflicts.select_conflicts(tree, file_list)[0]
2277
transform_tree(tree, tree.basis_tree(), interesting_ids)
2331
_mod_merge.transform_tree(tree, tree.basis_tree(), interesting_ids)
2278
2332
tree.set_conflicts(ConflictList(new_conflicts))
2279
2333
if file_list is None:
2280
2334
restore_files = list(tree.iter_conflicts())
2283
2337
for filename in restore_files:
2285
2339
restore(tree.abspath(filename))
2286
except NotConflicted:
2340
except errors.NotConflicted:
2288
conflicts = merge_inner(tree.branch, other_tree, base_tree,
2290
interesting_ids=interesting_ids,
2291
other_rev_id=parents[1],
2292
merge_type=merge_type,
2293
show_base=show_base,
2294
reprocess=reprocess)
2342
conflicts = _mod_merge.merge_inner(
2343
tree.branch, other_tree, base_tree,
2345
interesting_ids=interesting_ids,
2346
other_rev_id=parents[1],
2347
merge_type=merge_type,
2348
show_base=show_base,
2349
reprocess=reprocess)
2297
2352
if conflicts > 0:
2302
2357
class cmd_revert(Command):
2303
"""Reverse all changes since the last commit.
2305
Only versioned files are affected. Specify filenames to revert only
2306
those files. By default, any files that are changed will be backed up
2307
first. Backup files have a '~' appended to their name.
2358
"""Revert files to a previous revision.
2360
Giving a list of files will revert only those files. Otherwise, all files
2361
will be reverted. If the revision is not specified with '--revision', the
2362
last committed revision is used.
2364
To remove only some changes, without reverting to a prior version, use
2365
merge instead. For example, "merge . --r-2..-3" will remove the changes
2366
introduced by -2, without affecting the changes introduced by -1. Or
2367
to remove certain changes on a hunk-by-hunk basis, see the Shelf plugin.
2369
By default, any files that have been manually changed will be backed up
2370
first. (Files changed only by merge are not backed up.) Backup files have
2371
'.~#~' appended to their name, where # is a number.
2373
When you provide files, you can use their current pathname or the pathname
2374
from the target revision. So you can use revert to "undelete" a file by
2375
name. If you name a directory, all the contents of that directory will be
2309
2378
takes_options = ['revision', 'no-backup']
2310
2379
takes_args = ['file*']
2311
2380
aliases = ['merge-revert']
2313
2382
def run(self, revision=None, no_backup=False, file_list=None):
2314
from bzrlib.commands import parse_spec
2315
2383
if file_list is not None:
2316
2384
if len(file_list) == 0:
2317
raise BzrCommandError("No files specified")
2385
raise errors.BzrCommandError("No files specified")
2323
2391
# FIXME should be tree.last_revision
2324
2392
rev_id = tree.last_revision()
2325
2393
elif len(revision) != 1:
2326
raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
2394
raise errors.BzrCommandError('bzr revert --revision takes exactly 1 argument')
2328
2396
rev_id = revision[0].in_history(tree.branch).rev_id
2329
2397
pb = ui.ui_factory.nested_progress_bar()
2425
2493
remote_branch.lock_read()
2427
2495
local_extra, remote_extra = find_unmerged(local_branch, remote_branch)
2428
if (log_format == None):
2496
if (log_format is None):
2429
2497
default = local_branch.get_config().log_format()
2430
2498
log_format = get_log_format(long=long, short=short,
2431
2499
line=line, default=default)
2479
2547
import bzrlib.plugin
2480
2548
from inspect import getdoc
2481
2549
for name, plugin in bzrlib.plugin.all_plugins().items():
2482
if hasattr(plugin, '__path__'):
2550
if getattr(plugin, '__path__', None) is not None:
2483
2551
print plugin.__path__[0]
2484
elif hasattr(plugin, '__file__'):
2552
elif getattr(plugin, '__file__', None) is not None:
2485
2553
print plugin.__file__
2489
2557
d = getdoc(plugin)
2572
2640
def run(self, revision_id_list=None, revision=None):
2573
2641
import bzrlib.gpg as gpg
2574
2642
if revision_id_list is not None and revision is not None:
2575
raise BzrCommandError('You can only supply one of revision_id or --revision')
2643
raise errors.BzrCommandError('You can only supply one of revision_id or --revision')
2576
2644
if revision_id_list is None and revision is None:
2577
raise BzrCommandError('You must supply either --revision or a revision_id')
2645
raise errors.BzrCommandError('You must supply either --revision or a revision_id')
2578
2646
b = WorkingTree.open_containing(u'.')[0].branch
2579
2647
gpg_strategy = gpg.GPGStrategy(b.get_config())
2580
2648
if revision_id_list is not None:
2593
2661
if to_revid is None:
2594
2662
to_revno = b.revno()
2595
2663
if from_revno is None or to_revno is None:
2596
raise BzrCommandError('Cannot sign a range of non-revision-history revisions')
2664
raise errors.BzrCommandError('Cannot sign a range of non-revision-history revisions')
2597
2665
for revno in range(from_revno, to_revno + 1):
2598
2666
b.repository.sign_revision(b.get_rev_id(revno),
2601
raise BzrCommandError('Please supply either one revision, or a range.')
2669
raise errors.BzrCommandError('Please supply either one revision, or a range.')
2604
2672
class cmd_bind(Command):
2616
2684
b_other = Branch.open(location)
2618
2686
b.bind(b_other)
2619
except DivergedBranches:
2620
raise BzrCommandError('These branches have diverged.'
2621
' Try merging, and then bind again.')
2687
except errors.DivergedBranches:
2688
raise errors.BzrCommandError('These branches have diverged.'
2689
' Try merging, and then bind again.')
2624
2692
class cmd_unbind(Command):
2813
class cmd_wait_until_signalled(Command):
2814
"""Test helper for test_start_and_stop_bzr_subprocess_send_signal.
2816
This just prints a line to signal when it is ready, then blocks on stdin.
2822
sys.stdout.write("running\n")
2824
sys.stdin.readline()
2827
class cmd_serve(Command):
2828
"""Run the bzr server."""
2830
aliases = ['server']
2834
help='serve on stdin/out for use from inetd or sshd'),
2836
help='listen for connections on nominated port of the form '
2837
'[hostname:]portnumber. Passing 0 as the port number will '
2838
'result in a dynamically allocated port.',
2841
help='serve contents of directory',
2843
Option('allow-writes',
2844
help='By default the server is a readonly server. Supplying '
2845
'--allow-writes enables write access to the contents of '
2846
'the served directory and below. '
2850
def run(self, port=None, inet=False, directory=None, allow_writes=False):
2851
from bzrlib.transport import smart
2852
from bzrlib.transport import get_transport
2853
if directory is None:
2854
directory = os.getcwd()
2855
url = urlutils.local_path_to_url(directory)
2856
if not allow_writes:
2857
url = 'readonly+' + url
2858
t = get_transport(url)
2860
server = smart.SmartServerPipeStreamMedium(sys.stdin, sys.stdout, t)
2861
elif port is not None:
2863
host, port = port.split(':')
2866
server = smart.SmartTCPServer(t, host=host, port=int(port))
2867
print 'listening on port: ', server.port
2870
raise errors.BzrCommandError("bzr serve requires one of --inet or --port")
2746
2874
# command-line interpretation helper for merge-related commands
2747
def merge(other_revision, base_revision,
2748
check_clean=True, ignore_zero=False,
2749
this_dir=None, backup_files=False, merge_type=Merge3Merger,
2750
file_list=None, show_base=False, reprocess=False,
2751
pb=DummyProgress()):
2875
def _merge_helper(other_revision, base_revision,
2876
check_clean=True, ignore_zero=False,
2877
this_dir=None, backup_files=False,
2879
file_list=None, show_base=False, reprocess=False,
2880
pb=DummyProgress()):
2752
2881
"""Merge changes into a tree.
2776
2905
clients might prefer to call merge.merge_inner(), which has less magic
2779
from bzrlib.merge import Merger
2908
# Loading it late, so that we don't always have to import bzrlib.merge
2909
if merge_type is None:
2910
merge_type = _mod_merge.Merge3Merger
2780
2911
if this_dir is None:
2781
2912
this_dir = u'.'
2782
2913
this_tree = WorkingTree.open_containing(this_dir)[0]
2783
if show_base and not merge_type is Merge3Merger:
2784
raise BzrCommandError("Show-base is not supported for this merge"
2785
" type. %s" % merge_type)
2914
if show_base and not merge_type is _mod_merge.Merge3Merger:
2915
raise errors.BzrCommandError("Show-base is not supported for this merge"
2916
" type. %s" % merge_type)
2786
2917
if reprocess and not merge_type.supports_reprocess:
2787
raise BzrCommandError("Conflict reduction is not supported for merge"
2788
" type %s." % merge_type)
2918
raise errors.BzrCommandError("Conflict reduction is not supported for merge"
2919
" type %s." % merge_type)
2789
2920
if reprocess and show_base:
2790
raise BzrCommandError("Cannot do conflict reduction and show base.")
2921
raise errors.BzrCommandError("Cannot do conflict reduction and show base.")
2792
merger = Merger(this_tree.branch, this_tree=this_tree, pb=pb)
2923
merger = _mod_merge.Merger(this_tree.branch, this_tree=this_tree,
2793
2925
merger.pp = ProgressPhase("Merge phase", 5, pb)
2794
2926
merger.pp.next_phase()
2795
2927
merger.check_basis(check_clean)
2812
2944
return conflicts
2948
merge = _merge_helper
2815
2951
# these get imported and then picked up by the scan for cmd_*
2816
2952
# TODO: Some more consistent way to split command definitions across files;
2817
2953
# we do need to load at least some information about them to know of
2818
2954
# aliases. ideally we would avoid loading the implementation until the
2819
2955
# details were needed.
2956
from bzrlib.cmd_version_info import cmd_version_info
2820
2957
from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore
2821
2958
from bzrlib.bundle.commands import cmd_bundle_revisions
2822
2959
from bzrlib.sign_my_commits import cmd_sign_my_commits