36
36
from bzrlib.log import show_one_log
37
37
from bzrlib.merge import Merge3Merger
38
38
from bzrlib.option import Option
39
from bzrlib.progress import DummyProgress
39
from bzrlib.progress import DummyProgress, ProgressPhase
40
40
from bzrlib.revisionspec import RevisionSpec
41
41
import bzrlib.trace
42
42
from bzrlib.trace import mutter, note, log_error, warning, is_quiet
70
70
return tree, new_list
73
def get_format_type(typestring):
74
"""Parse and return a format specifier."""
75
if typestring == "metadir":
76
return bzrdir.BzrDirMetaFormat1()
77
if typestring == "knit":
78
format = bzrdir.BzrDirMetaFormat1()
79
format.repository_format = bzrlib.repository.RepositoryFormatKnit1()
81
msg = "No known bzr-dir format %s. Supported types are: metadir\n" %\
83
raise BzrCommandError(msg)
73
86
# TODO: Make sure no commands unconditionally use the working directory as a
74
87
# branch. If a filename argument is used, the first of them should be used to
75
88
# specify the branch. (Perhaps this can be factored out into some kind of
507
521
if new_transport.base == transport.base:
508
522
raise BzrCommandError("Could not creeate "
510
br_to = bzrlib.bzrdir.BzrDir.create_branch_convenience(location)
524
dir_to = br_from.bzrdir.clone(location)
525
br_to = dir_to.open_branch()
511
526
old_rh = br_to.revision_history()
514
tree_to = br_to.working_tree()
515
except NoWorkingTree:
529
tree_to = dir_to.open_workingtree()
530
except errors.NotLocalUrl:
516
531
# TODO: This should be updated for branches which don't have a
517
532
# working tree, as opposed to ones where we just couldn't
518
533
# update the tree.
519
534
warning('Unable to update the working tree of: %s' % (br_to.base,))
520
535
count = br_to.pull(br_from, overwrite)
536
except NoWorkingTree:
537
count = br_to.pull(br_from, overwrite)
522
539
count = tree_to.pull(br_from, overwrite)
523
540
except DivergedBranches:
862
879
bzr commit -m 'imported project'
864
881
takes_args = ['location?']
865
def run(self, location=None):
884
help='Create a specific format rather than the'
885
' current default format. Currently this '
886
' option only accepts =metadir',
887
type=get_format_type),
889
def run(self, location=None, format=None):
866
890
from bzrlib.branch import Branch
867
891
if location is None:
874
898
# locations if the user supplies an extended path
875
899
if not os.path.exists(location):
876
900
os.mkdir(location)
877
bzrdir.BzrDir.create_standalone_workingtree(location)
903
bzrdir.BzrDir.create_standalone_workingtree(location)
905
new_dir = format.initialize(location)
906
new_dir.create_repository()
907
new_dir.create_branch()
908
# TODO: ask the bzrdir format for the right classs
909
import bzrlib.workingtree
910
bzrlib.workingtree.WorkingTreeFormat3().initialize(new_dir)
880
913
class cmd_diff(Command):
1523
def get_format_type(typestring):
1524
"""Parse and return a format specifier."""
1525
if typestring == "metadir":
1526
return bzrdir.BzrDirMetaFormat1()
1527
if typestring == "knit":
1528
format = bzrdir.BzrDirMetaFormat1()
1529
format.repository_format = bzrlib.repository.RepositoryFormatKnit1()
1531
msg = "No known bzr-dir format %s. Supported types are: metadir\n" %\
1533
raise BzrCommandError(msg)
1536
1556
class cmd_upgrade(Command):
1537
1557
"""Upgrade branch storage to current format.
1766
1786
will be used as a BASE, and the second one as OTHER. Revision
1767
1787
numbers are always relative to the specified branch.
1769
By default bzr will try to merge in all new work from the other
1789
By default, bzr will try to merge in all new work from the other
1770
1790
branch, automatically determining an appropriate base. If this
1771
1791
fails, you may need to give an explicit base.
1793
Merge will do its best to combine the changes in two branches, but there
1794
are some kinds of problems only a human can fix. When it encounters those,
1795
it will mark a conflict. A conflict means that you need to fix something,
1796
before you should commit.
1798
Use bzr resolve when you have fixed a problem. See also bzr conflicts.
1775
1802
To merge the latest revision from bzr.dev
1818
1845
base = [branch, revision[0].in_history(b).revno]
1819
1846
other = [branch, revision[1].in_history(b).revno]
1847
pb = bzrlib.ui.ui_factory.nested_progress_bar()
1822
conflict_count = merge(other, base, check_clean=(not force),
1823
merge_type=merge_type, reprocess=reprocess,
1824
show_base=show_base,
1825
pb=bzrlib.ui.ui_factory.progress_bar())
1850
conflict_count = merge(other, base, check_clean=(not force),
1851
merge_type=merge_type,
1852
reprocess=reprocess,
1853
show_base=show_base,
1826
1857
if conflict_count != 0:
1886
1917
restore(tree.abspath(filename))
1887
1918
except NotConflicted:
1889
conflicts = merge_inner(tree.branch, other_tree, base_tree,
1920
conflicts = merge_inner(tree.branch, other_tree, base_tree,
1890
1922
interesting_ids = interesting_ids,
1891
1923
other_rev_id=pending_merges[0],
1892
1924
merge_type=merge_type,
1921
1953
tree, file_list = tree_files(file_list)
1922
1954
if revision is None:
1923
1955
# FIXME should be tree.last_revision
1924
rev_id = tree.branch.last_revision()
1956
rev_id = tree.last_revision()
1925
1957
elif len(revision) != 1:
1926
1958
raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
1928
1960
rev_id = revision[0].in_history(tree.branch).rev_id
1929
tree.revert(file_list, tree.branch.repository.revision_tree(rev_id),
1930
not no_backup, bzrlib.ui.ui_factory.progress_bar())
1961
pb = bzrlib.ui.ui_factory.nested_progress_bar()
1963
tree.revert(file_list,
1964
tree.branch.repository.revision_tree(rev_id),
1933
1970
class cmd_assert_fail(Command):
2012
2049
raise BzrCommandError("No missing location known or specified.")
2013
2050
print "Using last location: " + local_branch.get_parent()
2014
2051
remote_branch = bzrlib.branch.Branch.open(other_branch)
2015
local_extra, remote_extra = find_unmerged(local_branch, remote_branch)
2016
if (log_format == None):
2017
default = bzrlib.config.BranchConfig(local_branch).log_format()
2018
log_format = get_log_format(long=long, short=short, line=line, default=default)
2019
lf = log_formatter(log_format, sys.stdout,
2021
show_timezone='original')
2022
if reverse is False:
2023
local_extra.reverse()
2024
remote_extra.reverse()
2025
if local_extra and not theirs_only:
2026
print "You have %d extra revision(s):" % len(local_extra)
2027
for data in iter_log_data(local_extra, local_branch.repository,
2030
printed_local = True
2032
printed_local = False
2033
if remote_extra and not mine_only:
2034
if printed_local is True:
2036
print "You are missing %d revision(s):" % len(remote_extra)
2037
for data in iter_log_data(remote_extra, remote_branch.repository,
2040
if not remote_extra and not local_extra:
2042
print "Branches are up to date."
2045
if parent is None and other_branch is not None:
2046
local_branch.set_parent(other_branch)
2052
remote_branch.lock_read()
2054
local_branch.lock_write()
2056
local_extra, remote_extra = find_unmerged(local_branch, remote_branch)
2057
if (log_format == None):
2058
default = bzrlib.config.BranchConfig(local_branch).log_format()
2059
log_format = get_log_format(long=long, short=short, line=line, default=default)
2060
lf = log_formatter(log_format, sys.stdout,
2062
show_timezone='original')
2063
if reverse is False:
2064
local_extra.reverse()
2065
remote_extra.reverse()
2066
if local_extra and not theirs_only:
2067
print "You have %d extra revision(s):" % len(local_extra)
2068
for data in iter_log_data(local_extra, local_branch.repository,
2071
printed_local = True
2073
printed_local = False
2074
if remote_extra and not mine_only:
2075
if printed_local is True:
2077
print "You are missing %d revision(s):" % len(remote_extra)
2078
for data in iter_log_data(remote_extra, remote_branch.repository,
2081
if not remote_extra and not local_extra:
2083
print "Branches are up to date."
2086
if parent is None and other_branch is not None:
2087
local_branch.set_parent(other_branch)
2090
local_branch.unlock()
2092
remote_branch.unlock()
2050
2095
class cmd_plugins(Command):
2337
2382
" type. %s" % merge_type)
2338
2383
if reprocess and show_base:
2339
2384
raise BzrCommandError("Cannot reprocess and show base.")
2340
merger = Merger(this_tree.branch, this_tree=this_tree, pb=pb)
2341
merger.check_basis(check_clean)
2342
merger.set_other(other_revision)
2343
merger.set_base(base_revision)
2344
if merger.base_rev_id == merger.other_rev_id:
2345
note('Nothing to do.')
2347
merger.backup_files = backup_files
2348
merger.merge_type = merge_type
2349
merger.set_interesting_files(file_list)
2350
merger.show_base = show_base
2351
merger.reprocess = reprocess
2352
conflicts = merger.do_merge()
2353
merger.set_pending()
2386
merger = Merger(this_tree.branch, this_tree=this_tree, pb=pb)
2387
merger.pp = ProgressPhase("Merge phase", 5, pb)
2388
merger.pp.next_phase()
2389
merger.check_basis(check_clean)
2390
merger.set_other(other_revision)
2391
merger.pp.next_phase()
2392
merger.set_base(base_revision)
2393
if merger.base_rev_id == merger.other_rev_id:
2394
note('Nothing to do.')
2396
merger.backup_files = backup_files
2397
merger.merge_type = merge_type
2398
merger.set_interesting_files(file_list)
2399
merger.show_base = show_base
2400
merger.reprocess = reprocess
2401
conflicts = merger.do_merge()
2402
merger.set_pending()
2354
2405
return conflicts