23
from shutil import rmtree
26
from bzrlib.branch import Branch, BranchReferenceFormat
27
from bzrlib import (bundle, branch, bzrdir, errors, osutils, ui, config,
28
from bzrlib.branch import Branch
29
import bzrlib.bzrdir as bzrdir
30
from bzrlib.bundle import read_bundle_from_url
29
31
from bzrlib.bundle.read_bundle import BundleReader
30
32
from bzrlib.bundle.apply_bundle import install_bundle, merge_bundle
31
33
from bzrlib.commands import Command, display_command
34
import bzrlib.errors as errors
32
35
from bzrlib.errors import (BzrError, BzrCheckError, BzrCommandError,
33
36
NotBranchError, DivergedBranches, NotConflicted,
34
37
NoSuchFile, NoWorkingTree, FileInWrongBranch,
35
38
NotVersionedError, NotABundle)
39
from bzrlib.log import show_one_log
36
40
from bzrlib.merge import Merge3Merger
37
41
from bzrlib.option import Option
38
43
from bzrlib.progress import DummyProgress, ProgressPhase
39
44
from bzrlib.revision import common_ancestor
40
45
from bzrlib.revisionspec import RevisionSpec
41
from bzrlib.trace import mutter, note, log_error, warning, is_quiet, info
47
from bzrlib.trace import mutter, note, log_error, warning, is_quiet
42
48
from bzrlib.transport.local import LocalTransport
43
50
import bzrlib.urlutils as urlutils
44
51
from bzrlib.workingtree import WorkingTree
88
95
return bzrdir.BzrDirMetaFormat1()
89
96
if typestring == "metaweave":
90
97
format = bzrdir.BzrDirMetaFormat1()
91
format.repository_format = repository.RepositoryFormat7()
98
format.repository_format = bzrlib.repository.RepositoryFormat7()
93
100
if typestring == "knit":
94
101
format = bzrdir.BzrDirMetaFormat1()
95
format.repository_format = repository.RepositoryFormatKnit1()
102
format.repository_format = bzrlib.repository.RepositoryFormatKnit1()
97
104
msg = "Unknown bzr format %s. Current formats are: default, knit,\n" \
98
105
"metaweave and weave" % typestring
410
417
If there is no default location set, the first pull will set it. After
411
418
that, you can omit the location to use the default. To change the
412
default, use --remember. The value will only be saved if the remote
413
location can be accessed.
419
default, use --remember.
416
422
takes_options = ['remember', 'overwrite', 'revision', 'verbose']
501
507
If there is no default push location set, the first push will set it.
502
508
After that, you can omit the location to use the default. To change the
503
default, use --remember. The value will only be saved if the remote
504
location can be accessed.
509
default, use --remember.
507
512
takes_options = ['remember', 'overwrite', 'verbose',
526
531
display_url = urlutils.unescape_for_display(stored_loc,
527
532
self.outf.encoding)
528
self.outf.write("Using saved location: %s\n" % display_url)
533
self.outf.write("Using saved location: %s" % display_url)
529
534
location = stored_loc
531
536
transport = get_transport(location)
532
537
location_url = transport.base
538
if br_from.get_push_location() is None or remember:
539
br_from.set_push_location(location_url)
536
dir_to = bzrdir.BzrDir.open(location_url)
543
dir_to = bzrlib.bzrdir.BzrDir.open(location_url)
537
544
br_to = dir_to.open_branch()
538
545
except NotBranchError:
539
546
# create a branch.
565
572
revision_id=br_from.last_revision())
566
573
br_to = dir_to.open_branch()
567
574
count = len(br_to.revision_history())
568
# We successfully created the target, remember it
569
if br_from.get_push_location() is None or remember:
570
br_from.set_push_location(br_to.base)
572
# We were able to connect to the remote location, so remember it
573
# we don't need to successfully push because of possible divergence.
574
if br_from.get_push_location() is None or remember:
575
br_from.set_push_location(br_to.base)
576
576
old_rh = br_to.revision_history()
619
619
def run(self, from_location, to_location=None, revision=None, basis=None):
620
620
from bzrlib.transport import get_transport
621
from bzrlib.osutils import rmtree
621
622
if revision is None:
622
623
revision = [None]
623
624
elif len(revision) > 1:
653
654
to_transport = get_transport(to_location)
655
656
to_transport.mkdir('.')
656
except errors.FileExists:
657
except bzrlib.errors.FileExists:
657
658
raise BzrCommandError('Target directory "%s" already'
658
659
' exists.' % to_location)
659
except errors.NoSuchFile:
660
except bzrlib.errors.NoSuchFile:
660
661
raise BzrCommandError('Parent of "%s" does not exist.' %
664
665
dir = br_from.bzrdir.sprout(to_transport.base,
665
666
revision_id, basis_dir)
666
667
branch = dir.open_branch()
667
except errors.NoSuchRevision:
668
except bzrlib.errors.NoSuchRevision:
668
669
to_transport.delete_tree('.')
669
670
msg = "The branch %s has no revision %s." % (from_location, revision[0])
670
671
raise BzrCommandError(msg)
671
except errors.UnlistableBranch:
672
osutils.rmtree(to_location)
672
except bzrlib.errors.UnlistableBranch:
673
674
msg = "The branch %s cannot be used as a --basis" % (basis,)
674
675
raise BzrCommandError(msg)
718
719
raise BzrCommandError(
719
720
'bzr checkout --revision takes exactly 1 revision value')
720
721
if branch_location is None:
721
branch_location = osutils.getcwd()
722
branch_location = bzrlib.osutils.getcwd()
722
723
to_location = branch_location
723
724
source = Branch.open(branch_location)
724
725
if len(revision) == 1 and revision[0] is not None:
730
731
# if the source and to_location are the same,
731
732
# and there is no working tree,
732
733
# then reconstitute a branch
733
if (osutils.abspath(to_location) ==
734
osutils.abspath(branch_location)):
734
if (bzrlib.osutils.abspath(to_location) ==
735
bzrlib.osutils.abspath(branch_location)):
736
737
source.bzrdir.open_workingtree()
737
738
except errors.NoWorkingTree:
751
old_format = bzrdir.BzrDirFormat.get_default_format()
752
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
752
old_format = bzrlib.bzrdir.BzrDirFormat.get_default_format()
753
bzrlib.bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
755
756
checkout = bzrdir.BzrDirMetaFormat1().initialize(to_location)
756
branch.BranchReferenceFormat().initialize(checkout, source)
757
bzrlib.branch.BranchReferenceFormat().initialize(checkout, source)
758
checkout_branch = bzrdir.BzrDir.create_branch_convenience(
759
checkout_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(
759
760
to_location, force_new_tree=False)
760
761
checkout = checkout_branch.bzrdir
761
762
checkout_branch.bind(source)
764
765
checkout_branch.set_revision_history(rh[:rh.index(revision_id) + 1])
765
766
checkout.create_workingtree(revision_id)
767
bzrdir.BzrDirFormat.set_default_format(old_format)
768
bzrlib.bzrdir.BzrDirFormat.set_default_format(old_format)
770
771
class cmd_renames(Command):
779
780
def run(self, dir=u'.'):
780
from bzrlib.tree import find_renames
781
781
tree = WorkingTree.open_containing(dir)[0]
782
782
old_inv = tree.basis_tree().inventory
783
783
new_inv = tree.read_working_inventory()
784
renames = list(find_renames(old_inv, new_inv))
785
renames = list(bzrlib.tree.find_renames(old_inv, new_inv))
786
787
for old_name, new_name in renames:
787
788
self.outf.write("%s => %s\n" % (old_name, new_name))
936
937
def run(self, branch="."):
937
938
from bzrlib.reconcile import reconcile
938
dir = bzrdir.BzrDir.open(branch)
939
dir = bzrlib.bzrdir.BzrDir.open(branch)
942
943
class cmd_revision_history(Command):
943
"""Display the list of revision ids on a branch."""
944
takes_args = ['location?']
944
"""Display list of revision ids on this branch."""
949
def run(self, location="."):
950
branch = Branch.open_containing(location)[0]
951
for revid in branch.revision_history():
952
self.outf.write(revid)
949
branch = WorkingTree.open_containing(u'.')[0].branch
950
for patchid in branch.revision_history():
951
self.outf.write(patchid)
953
952
self.outf.write('\n')
956
955
class cmd_ancestry(Command):
957
956
"""List all revisions merged into this branch."""
958
takes_args = ['location?']
963
def run(self, location="."):
965
wt = WorkingTree.open_containing(location)[0]
966
except errors.NoWorkingTree:
967
b = Branch.open(location)
968
last_revision = b.last_revision()
971
last_revision = wt.last_revision()
973
revision_ids = b.repository.get_ancestry(last_revision)
961
tree = WorkingTree.open_containing(u'.')[0]
963
# FIXME. should be tree.last_revision
964
revision_ids = b.repository.get_ancestry(b.last_revision())
974
965
assert revision_ids[0] == None
975
966
revision_ids.pop(0)
976
967
for revision_id in revision_ids:
1212
1204
if file_id in basis_inv:
1214
1206
path = inv.id2path(file_id)
1215
if not os.access(osutils.abspath(path), os.F_OK):
1207
if not os.access(bzrlib.osutils.abspath(path), os.F_OK):
1217
1209
self.outf.write(path + '\n')
1327
1319
(rev2, rev1) = (rev1, rev2)
1329
1321
if (log_format == None):
1330
default = config.BranchConfig(b).log_format()
1322
default = bzrlib.config.BranchConfig(b).log_format()
1331
1323
log_format = get_log_format(long=long, short=short, line=line, default=default)
1332
1324
lf = log_formatter(log_format,
1333
1325
show_ids=show_ids,
1370
1362
b = tree.branch
1371
1363
inv = tree.read_working_inventory()
1372
1364
file_id = inv.path2id(relpath)
1373
for revno, revision_id, what in log.find_touching_revisions(b, file_id):
1365
for revno, revision_id, what in bzrlib.log.find_touching_revisions(b, file_id):
1374
1366
self.outf.write("%6d %s\n" % (revno, what))
1432
1424
"""List unknown files."""
1433
1425
@display_command
1427
from bzrlib.osutils import quotefn
1435
1428
for f in WorkingTree.open_containing(u'.')[0].unknowns():
1436
self.outf.write(osutils.quotefn(f) + '\n')
1429
self.outf.write(quotefn(f) + '\n')
1439
1432
class cmd_ignore(Command):
1687
1680
message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
1689
1682
if message == "":
1690
raise BzrCommandError("empty commit message specified")
1683
raise BzrCommandError("empty commit message specified")
1693
1686
reporter = ReportCommitToLog()
1786
1779
def run(self, email=False):
1788
1781
b = WorkingTree.open_containing(u'.')[0].branch
1789
c = config.BranchConfig(b)
1782
config = bzrlib.config.BranchConfig(b)
1790
1783
except NotBranchError:
1791
c = config.GlobalConfig()
1784
config = bzrlib.config.GlobalConfig()
1793
print c.user_email()
1787
print config.user_email()
1789
print config.username()
1798
1792
class cmd_nick(Command):
1878
1872
# we don't want progress meters from the tests to go to the
1879
1873
# real output; and we don't want log messages cluttering up
1880
1874
# the real logs.
1881
save_ui = ui.ui_factory
1882
print '%10s: %s' % ('bzr', osutils.realpath(sys.argv[0]))
1875
save_ui = bzrlib.ui.ui_factory
1876
print '%10s: %s' % ('bzr', bzrlib.osutils.realpath(sys.argv[0]))
1883
1877
print '%10s: %s' % ('bzrlib', bzrlib.__path__[0])
1885
info('running tests...')
1879
bzrlib.trace.info('running tests...')
1887
ui.ui_factory = ui.SilentUIFactory()
1881
bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
1888
1882
if testspecs_list is not None:
1889
1883
pattern = '|'.join(testspecs_list)
1905
1899
test_suite_factory=test_suite_factory,
1906
1900
lsprof_timed=lsprof_timed)
1908
info('tests passed')
1902
bzrlib.trace.info('tests passed')
1910
info('tests failed')
1904
bzrlib.trace.info('tests failed')
1911
1905
return int(not result)
1913
ui.ui_factory = save_ui
1907
bzrlib.ui.ui_factory = save_ui
1916
1910
def _get_bzr_branch():
1917
1911
"""If bzr is run from a branch, return Branch or None"""
1912
import bzrlib.errors
1913
from bzrlib.branch import Branch
1914
from bzrlib.osutils import abspath
1918
1915
from os.path import dirname
1921
branch = Branch.open(dirname(osutils.abspath(dirname(__file__))))
1918
branch = Branch.open(dirname(abspath(dirname(__file__))))
1923
except errors.BzrError:
1920
except bzrlib.errors.BzrError:
1927
1924
def show_version():
1929
1925
print "bzr (bazaar-ng) %s" % bzrlib.__version__
1930
1926
# is bzrlib itself in a branch?
1931
1927
branch = _get_bzr_branch()
1997
1993
base_rev_id = common_ancestor(last1, last2, source)
1999
1995
print 'merge base is revision %s' % base_rev_id
1999
if base_revno is None:
2000
raise bzrlib.errors.UnrelatedBranches()
2002
print ' r%-6d in %s' % (base_revno, branch)
2004
other_revno = branch2.revision_id_to_revno(base_revid)
2006
print ' r%-6d in %s' % (other_revno, other)
2002
2010
class cmd_merge(Command):
2003
2011
"""Perform a three-way merge.
2005
The branch is the branch you will merge from. By default, it will merge
2006
the latest revision. If you specify a revision, that revision will be
2007
merged. If you specify two revisions, the first will be used as a BASE,
2008
and the second one as OTHER. Revision numbers are always relative to the
2013
The branch is the branch you will merge from. By default, it will
2014
merge the latest revision. If you specify a revision, that
2015
revision will be merged. If you specify two revisions, the first
2016
will be used as a BASE, and the second one as OTHER. Revision
2017
numbers are always relative to the specified branch.
2011
2019
By default, bzr will try to merge in all new work from the other
2012
2020
branch, automatically determining an appropriate base. If this
2022
2030
If there is no default branch set, the first merge will set it. After
2023
2031
that, you can omit the branch to use the default. To change the
2024
default, use --remember. The value will only be saved if the remote
2025
location can be accessed.
2032
default, use --remember.
2099
2106
interesting_files = [path]
2101
2108
interesting_files = None
2102
pb = ui.ui_factory.nested_progress_bar()
2109
pb = bzrlib.ui.ui_factory.nested_progress_bar()
2105
2112
conflict_count = merge(other, base, check_clean=(not force),
2252
2259
raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
2254
2261
rev_id = revision[0].in_history(tree.branch).rev_id
2255
pb = ui.ui_factory.nested_progress_bar()
2262
pb = bzrlib.ui.ui_factory.nested_progress_bar()
2257
2264
tree.revert(file_list,
2258
2265
tree.branch.repository.revision_tree(rev_id),
2306
2313
takes_args = ['from_branch', 'to_branch']
2307
2314
def run(self, from_branch, to_branch):
2308
2315
from bzrlib.fetch import Fetcher
2316
from bzrlib.branch import Branch
2309
2317
from_b = Branch.open(from_branch)
2310
2318
to_b = Branch.open(to_branch)
2311
2319
Fetcher(to_b, from_b)
2334
2342
show_ids=False, verbose=False):
2335
2343
from bzrlib.missing import find_unmerged, iter_log_data
2336
2344
from bzrlib.log import log_formatter
2337
local_branch = Branch.open_containing(u".")[0]
2345
local_branch = bzrlib.branch.Branch.open_containing(u".")[0]
2338
2346
parent = local_branch.get_parent()
2339
2347
if other_branch is None:
2340
2348
other_branch = parent
2341
2349
if other_branch is None:
2342
2350
raise BzrCommandError("No missing location known or specified.")
2343
2351
print "Using last location: " + local_branch.get_parent()
2344
remote_branch = Branch.open(other_branch)
2352
remote_branch = bzrlib.branch.Branch.open(other_branch)
2345
2353
if remote_branch.base == local_branch.base:
2346
2354
remote_branch = local_branch
2347
2355
local_branch.lock_read()
2351
2359
local_extra, remote_extra = find_unmerged(local_branch, remote_branch)
2352
2360
if (log_format == None):
2353
default = config.BranchConfig(local_branch).log_format()
2361
default = bzrlib.config.BranchConfig(local_branch).log_format()
2354
2362
log_format = get_log_format(long=long, short=short, line=line, default=default)
2355
2363
lf = log_formatter(log_format, sys.stdout,
2356
2364
show_ids=show_ids,
2416
2424
class cmd_testament(Command):
2417
2425
"""Show testament (signing-form) of a revision."""
2418
takes_options = ['revision', 'long',
2419
Option('strict', help='Produce a strict testament')]
2426
takes_options = ['revision', 'long']
2420
2427
takes_args = ['branch?']
2421
2428
@display_command
2422
def run(self, branch=u'.', revision=None, long=False, strict=False):
2423
from bzrlib.testament import Testament, StrictTestament
2425
testament_class = StrictTestament
2427
testament_class = Testament
2429
def run(self, branch=u'.', revision=None, long=False):
2430
from bzrlib.testament import Testament
2428
2431
b = WorkingTree.open_containing(branch)[0].branch
2432
2435
rev_id = b.last_revision()
2434
2437
rev_id = revision[0].in_history(b).rev_id
2435
t = testament_class.from_revision(b.repository, rev_id)
2438
t = Testament.from_revision(b.repository, rev_id)
2437
2440
sys.stdout.writelines(t.as_text_lines())
2490
2493
takes_options = ['revision']
2492
2495
def run(self, revision_id_list=None, revision=None):
2496
import bzrlib.config as config
2493
2497
import bzrlib.gpg as gpg
2494
2498
if revision_id_list is not None and revision is not None:
2495
2499
raise BzrCommandError('You can only supply one of revision_id or --revision')
2557
2561
raise BzrCommandError('Local branch is not bound')
2560
class cmd_uncommit(Command):
2564
class cmd_uncommit(bzrlib.commands.Command):
2561
2565
"""Remove the last committed revision.
2563
2567
--verbose will print out what is being removed.
2581
2585
def run(self, location=None,
2582
2586
dry_run=False, verbose=False,
2583
2587
revision=None, force=False):
2588
from bzrlib.branch import Branch
2584
2589
from bzrlib.log import log_formatter
2586
2591
from bzrlib.uncommit import uncommit