23
from shutil import rmtree
28
from bzrlib.branch import Branch
29
import bzrlib.bzrdir as bzrdir
25
from bzrlib.branch import Branch, BranchReferenceFormat
26
from bzrlib import (branch, bzrdir, errors, osutils, ui, config, user_encoding,
30
28
from bzrlib.bundle.read_bundle import BundleReader
31
29
from bzrlib.bundle.apply_bundle import merge_bundle
32
30
from bzrlib.commands import Command, display_command
33
import bzrlib.errors as errors
34
31
from bzrlib.errors import (BzrError, BzrCheckError, BzrCommandError,
35
32
NotBranchError, DivergedBranches, NotConflicted,
36
33
NoSuchFile, NoWorkingTree, FileInWrongBranch,
37
34
NotVersionedError, NotABundle)
38
from bzrlib.log import show_one_log
39
35
from bzrlib.merge import Merge3Merger
40
36
from bzrlib.option import Option
42
37
from bzrlib.progress import DummyProgress, ProgressPhase
43
38
from bzrlib.revision import common_ancestor
44
39
from bzrlib.revisionspec import RevisionSpec
46
from bzrlib.trace import mutter, note, log_error, warning, is_quiet
40
from bzrlib.trace import mutter, note, log_error, warning, is_quiet, info
47
41
from bzrlib.transport.local import LocalTransport
49
42
import bzrlib.urlutils as urlutils
50
43
from bzrlib.workingtree import WorkingTree
94
87
return bzrdir.BzrDirMetaFormat1()
95
88
if typestring == "metaweave":
96
89
format = bzrdir.BzrDirMetaFormat1()
97
format.repository_format = bzrlib.repository.RepositoryFormat7()
90
format.repository_format = repository.RepositoryFormat7()
99
92
if typestring == "knit":
100
93
format = bzrdir.BzrDirMetaFormat1()
101
format.repository_format = bzrlib.repository.RepositoryFormatKnit1()
94
format.repository_format = repository.RepositoryFormatKnit1()
103
96
msg = "Unknown bzr format %s. Current formats are: default, knit,\n" \
104
97
"metaweave and weave" % typestring
607
600
def run(self, from_location, to_location=None, revision=None, basis=None):
608
601
from bzrlib.transport import get_transport
609
from bzrlib.osutils import rmtree
610
602
if revision is None:
611
603
revision = [None]
612
604
elif len(revision) > 1:
642
634
to_transport = get_transport(to_location)
644
636
to_transport.mkdir('.')
645
except bzrlib.errors.FileExists:
637
except errors.FileExists:
646
638
raise BzrCommandError('Target directory "%s" already'
647
639
' exists.' % to_location)
648
except bzrlib.errors.NoSuchFile:
640
except errors.NoSuchFile:
649
641
raise BzrCommandError('Parent of "%s" does not exist.' %
653
645
dir = br_from.bzrdir.sprout(to_transport.base,
654
646
revision_id, basis_dir)
655
647
branch = dir.open_branch()
656
except bzrlib.errors.NoSuchRevision:
648
except errors.NoSuchRevision:
657
649
to_transport.delete_tree('.')
658
650
msg = "The branch %s has no revision %s." % (from_location, revision[0])
659
651
raise BzrCommandError(msg)
660
except bzrlib.errors.UnlistableBranch:
652
except errors.UnlistableBranch:
653
osutils.rmtree(to_location)
662
654
msg = "The branch %s cannot be used as a --basis" % (basis,)
663
655
raise BzrCommandError(msg)
707
699
raise BzrCommandError(
708
700
'bzr checkout --revision takes exactly 1 revision value')
709
701
if branch_location is None:
710
branch_location = bzrlib.osutils.getcwd()
702
branch_location = osutils.getcwd()
711
703
to_location = branch_location
712
704
source = Branch.open(branch_location)
713
705
if len(revision) == 1 and revision[0] is not None:
719
711
# if the source and to_location are the same,
720
712
# and there is no working tree,
721
713
# then reconstitute a branch
722
if (bzrlib.osutils.abspath(to_location) ==
723
bzrlib.osutils.abspath(branch_location)):
714
if (osutils.abspath(to_location) ==
715
osutils.abspath(branch_location)):
725
717
source.bzrdir.open_workingtree()
726
718
except errors.NoWorkingTree:
740
old_format = bzrlib.bzrdir.BzrDirFormat.get_default_format()
741
bzrlib.bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
732
old_format = bzrdir.BzrDirFormat.get_default_format()
733
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
744
736
checkout = bzrdir.BzrDirMetaFormat1().initialize(to_location)
745
bzrlib.branch.BranchReferenceFormat().initialize(checkout, source)
737
branch.BranchReferenceFormat().initialize(checkout, source)
747
checkout_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(
739
checkout_branch = bzrdir.BzrDir.create_branch_convenience(
748
740
to_location, force_new_tree=False)
749
741
checkout = checkout_branch.bzrdir
750
742
checkout_branch.bind(source)
753
745
checkout_branch.set_revision_history(rh[:rh.index(revision_id) + 1])
754
746
checkout.create_workingtree(revision_id)
756
bzrlib.bzrdir.BzrDirFormat.set_default_format(old_format)
748
bzrdir.BzrDirFormat.set_default_format(old_format)
759
751
class cmd_renames(Command):
768
760
def run(self, dir=u'.'):
761
from bzrlib.tree import find_renames
769
762
tree = WorkingTree.open_containing(dir)[0]
770
763
old_inv = tree.basis_tree().inventory
771
764
new_inv = tree.read_working_inventory()
773
renames = list(bzrlib.tree.find_renames(old_inv, new_inv))
765
renames = list(find_renames(old_inv, new_inv))
775
767
for old_name, new_name in renames:
776
768
self.outf.write("%s => %s\n" % (old_name, new_name))
925
917
def run(self, branch="."):
926
918
from bzrlib.reconcile import reconcile
927
dir = bzrlib.bzrdir.BzrDir.open(branch)
919
dir = bzrdir.BzrDir.open(branch)
1192
1183
if file_id in basis_inv:
1194
1185
path = inv.id2path(file_id)
1195
if not os.access(bzrlib.osutils.abspath(path), os.F_OK):
1186
if not os.access(osutils.abspath(path), os.F_OK):
1197
1188
self.outf.write(path + '\n')
1307
1298
(rev2, rev1) = (rev1, rev2)
1309
1300
if (log_format == None):
1310
default = bzrlib.config.BranchConfig(b).log_format()
1301
default = config.BranchConfig(b).log_format()
1311
1302
log_format = get_log_format(long=long, short=short, line=line, default=default)
1312
1303
lf = log_formatter(log_format,
1313
1304
show_ids=show_ids,
1350
1341
b = tree.branch
1351
1342
inv = tree.read_working_inventory()
1352
1343
file_id = inv.path2id(relpath)
1353
for revno, revision_id, what in bzrlib.log.find_touching_revisions(b, file_id):
1344
for revno, revision_id, what in log.find_touching_revisions(b, file_id):
1354
1345
self.outf.write("%6d %s\n" % (revno, what))
1412
1403
"""List unknown files."""
1413
1404
@display_command
1415
from bzrlib.osutils import quotefn
1406
from osutils import quotefn
1416
1407
for f in WorkingTree.open_containing(u'.')[0].unknowns():
1417
1408
self.outf.write(quotefn(f) + '\n')
1665
1656
raise BzrCommandError("please specify either --message or --file")
1668
message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
1659
message = codecs.open(file, 'rt', user_encoding).read()
1670
1661
if message == "":
1671
raise BzrCommandError("empty commit message specified")
1662
raise BzrCommandError("empty commit message specified")
1674
1665
reporter = ReportCommitToLog()
1767
1758
def run(self, email=False):
1769
1760
b = WorkingTree.open_containing(u'.')[0].branch
1770
config = bzrlib.config.BranchConfig(b)
1761
c = config.BranchConfig(b)
1771
1762
except NotBranchError:
1772
config = bzrlib.config.GlobalConfig()
1763
c = config.GlobalConfig()
1775
print config.user_email()
1765
print c.user_email()
1777
print config.username()
1780
1770
class cmd_nick(Command):
1860
1850
# we don't want progress meters from the tests to go to the
1861
1851
# real output; and we don't want log messages cluttering up
1862
1852
# the real logs.
1863
save_ui = bzrlib.ui.ui_factory
1864
print '%10s: %s' % ('bzr', bzrlib.osutils.realpath(sys.argv[0]))
1853
save_ui = ui.ui_factory
1854
print '%10s: %s' % ('bzr', osutils.realpath(sys.argv[0]))
1865
1855
print '%10s: %s' % ('bzrlib', bzrlib.__path__[0])
1867
bzrlib.trace.info('running tests...')
1857
info('running tests...')
1869
bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
1859
ui.ui_factory = ui.SilentUIFactory()
1870
1860
if testspecs_list is not None:
1871
1861
pattern = '|'.join(testspecs_list)
1887
1877
test_suite_factory=test_suite_factory,
1888
1878
lsprof_timed=lsprof_timed)
1890
bzrlib.trace.info('tests passed')
1880
info('tests passed')
1892
bzrlib.trace.info('tests failed')
1882
info('tests failed')
1893
1883
return int(not result)
1895
bzrlib.ui.ui_factory = save_ui
1885
ui.ui_factory = save_ui
1898
1888
def _get_bzr_branch():
1899
1889
"""If bzr is run from a branch, return Branch or None"""
1900
import bzrlib.errors
1901
from bzrlib.branch import Branch
1902
from bzrlib.osutils import abspath
1903
1890
from os.path import dirname
1906
branch = Branch.open(dirname(abspath(dirname(__file__))))
1893
branch = Branch.open(dirname(osutils.abspath(dirname(__file__))))
1908
except bzrlib.errors.BzrError:
1895
except errors.BzrError:
1912
1899
def show_version():
1913
1901
print "bzr (bazaar-ng) %s" % bzrlib.__version__
1914
1902
# is bzrlib itself in a branch?
1915
1903
branch = _get_bzr_branch()
1981
1969
base_rev_id = common_ancestor(last1, last2, source)
1983
1971
print 'merge base is revision %s' % base_rev_id
1987
if base_revno is None:
1988
raise bzrlib.errors.UnrelatedBranches()
1990
print ' r%-6d in %s' % (base_revno, branch)
1992
other_revno = branch2.revision_id_to_revno(base_revid)
1994
print ' r%-6d in %s' % (other_revno, other)
1998
1974
class cmd_merge(Command):
1999
1975
"""Perform a three-way merge.
2001
The branch is the branch you will merge from. By default, it will
2002
merge the latest revision. If you specify a revision, that
2003
revision will be merged. If you specify two revisions, the first
2004
will be used as a BASE, and the second one as OTHER. Revision
2005
numbers are always relative to the specified branch.
1977
The branch is the branch you will merge from. By default, it will merge
1978
the latest revision. If you specify a revision, that revision will be
1979
merged. If you specify two revisions, the first will be used as a BASE,
1980
and the second one as OTHER. Revision numbers are always relative to the
2007
1983
By default, bzr will try to merge in all new work from the other
2008
1984
branch, automatically determining an appropriate base. If this
2100
2076
interesting_files = [path]
2102
2078
interesting_files = None
2103
pb = bzrlib.ui.ui_factory.nested_progress_bar()
2079
pb = ui.ui_factory.nested_progress_bar()
2106
2082
conflict_count = merge(other, base, check_clean=(not force),
2117
except bzrlib.errors.AmbiguousBase, e:
2093
except errors.AmbiguousBase, e:
2118
2094
m = ("sorry, bzr can't determine the right merge base yet\n"
2119
2095
"candidates are:\n "
2120
2096
+ "\n ".join(e.bases)
2253
2229
raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
2255
2231
rev_id = revision[0].in_history(tree.branch).rev_id
2256
pb = bzrlib.ui.ui_factory.nested_progress_bar()
2232
pb = ui.ui_factory.nested_progress_bar()
2258
2234
tree.revert(file_list,
2259
2235
tree.branch.repository.revision_tree(rev_id),
2307
2283
takes_args = ['from_branch', 'to_branch']
2308
2284
def run(self, from_branch, to_branch):
2309
2285
from bzrlib.fetch import Fetcher
2310
from bzrlib.branch import Branch
2311
2286
from_b = Branch.open(from_branch)
2312
2287
to_b = Branch.open(to_branch)
2313
2288
Fetcher(to_b, from_b)
2336
2311
show_ids=False, verbose=False):
2337
2312
from bzrlib.missing import find_unmerged, iter_log_data
2338
2313
from bzrlib.log import log_formatter
2339
local_branch = bzrlib.branch.Branch.open_containing(u".")[0]
2314
local_branch = Branch.open_containing(u".")[0]
2340
2315
parent = local_branch.get_parent()
2341
2316
if other_branch is None:
2342
2317
other_branch = parent
2343
2318
if other_branch is None:
2344
2319
raise BzrCommandError("No missing location known or specified.")
2345
2320
print "Using last location: " + local_branch.get_parent()
2346
remote_branch = bzrlib.branch.Branch.open(other_branch)
2321
remote_branch = Branch.open(other_branch)
2347
2322
if remote_branch.base == local_branch.base:
2348
2323
remote_branch = local_branch
2349
2324
local_branch.lock_read()
2353
2328
local_extra, remote_extra = find_unmerged(local_branch, remote_branch)
2354
2329
if (log_format == None):
2355
default = bzrlib.config.BranchConfig(local_branch).log_format()
2330
default = config.BranchConfig(local_branch).log_format()
2356
2331
log_format = get_log_format(long=long, short=short, line=line, default=default)
2357
2332
lf = log_formatter(log_format, sys.stdout,
2358
2333
show_ids=show_ids,
2487
2462
takes_options = ['revision']
2489
2464
def run(self, revision_id_list=None, revision=None):
2490
import bzrlib.config as config
2491
2465
import bzrlib.gpg as gpg
2492
2466
if revision_id_list is not None and revision is not None:
2493
2467
raise BzrCommandError('You can only supply one of revision_id or --revision')
2555
2529
raise BzrCommandError('Local branch is not bound')
2558
class cmd_uncommit(bzrlib.commands.Command):
2532
class cmd_uncommit(Command):
2559
2533
"""Remove the last committed revision.
2561
2535
--verbose will print out what is being removed.
2579
2553
def run(self, location=None,
2580
2554
dry_run=False, verbose=False,
2581
2555
revision=None, force=False):
2582
from bzrlib.branch import Branch
2583
2556
from bzrlib.log import log_formatter
2585
2558
from bzrlib.uncommit import uncommit