436
436
raise errors.UpgradeRequired(self.base)
438
438
def last_revision(self):
439
"""Return last revision id, or None"""
440
ph = self.revision_history()
444
return _mod_revision.NULL_REVISION
439
"""Return last revision id, or NULL_REVISION."""
440
return self.last_revision_info()[1]
446
442
def last_revision_info(self):
447
443
"""Return information about the last revision.
759
755
def create_checkout(self, to_location, revision_id=None,
756
lightweight=False, accelerator_tree=None):
761
757
"""Create a checkout of a branch.
763
759
:param to_location: The url to produce the checkout at
764
760
:param revision_id: The revision to check out
765
761
:param lightweight: If True, produce a lightweight checkout, otherwise,
766
762
produce a bound branch (heavyweight checkout)
763
:param accelerator_tree: A tree which can be used for retrieving file
764
contents more quickly than the revision tree, i.e. a workingtree.
765
The revision tree will be used for cases where accelerator_tree's
766
content is different.
767
767
:return: The tree of the created checkout
769
769
t = transport.get_transport(to_location)
873
def set_reference(self, a_bzrdir, to_branch):
874
"""Set the target reference of the branch in a_bzrdir.
876
format probing must have been completed before calling
877
this method - it is assumed that the format of the branch
878
in a_bzrdir is correct.
880
:param a_bzrdir: The bzrdir to set the branch reference for.
881
:param to_branch: branch that the checkout is to reference
883
raise NotImplementedError(self.set_reference)
871
885
def get_format_string(self):
872
886
"""Return the ASCII format string that identifies this format."""
873
887
raise NotImplementedError(self.get_format_string)
1198
1212
transport = a_bzrdir.get_branch_transport(None)
1199
1213
return transport.get('location').read()
1215
def set_reference(self, a_bzrdir, to_branch):
1216
"""See BranchFormat.set_reference()."""
1217
transport = a_bzrdir.get_branch_transport(None)
1218
location = transport.put_bytes('location', to_branch.base)
1201
1220
def initialize(self, a_bzrdir, target_branch=None):
1202
1221
"""Create a branch of this format in a_bzrdir."""
1203
1222
if target_branch is None:
1439
1458
last_rev, other_branch))
1441
1460
@needs_write_lock
1442
def update_revisions(self, other, stop_revision=None):
1461
def update_revisions(self, other, stop_revision=None, overwrite=False):
1443
1462
"""See Branch.update_revisions."""
1444
1463
other.lock_read()
1465
other_last_revno, other_last_revision = other.last_revision_info()
1446
1466
if stop_revision is None:
1447
stop_revision = other.last_revision()
1448
if stop_revision is None:
1467
stop_revision = other_last_revision
1468
if _mod_revision.is_null(stop_revision):
1449
1469
# if there are no commits, we're done.
1451
1471
# whats the current last revision, before we fetch [and change it
1456
1476
# already merged can operate on the just fetched graph, which will
1457
1477
# be cached in memory.
1458
1478
self.fetch(other, stop_revision)
1459
if self.repository.get_graph().is_ancestor(stop_revision,
1462
self.generate_revision_history(stop_revision, last_rev=last_rev,
1479
# Check to see if one is an ancestor of the other
1481
heads = self.repository.get_graph().heads([stop_revision,
1483
if heads == set([last_rev]):
1484
# The current revision is a decendent of the target,
1487
elif heads == set([stop_revision, last_rev]):
1488
# These branches have diverged
1489
raise errors.DivergedBranches(self, other)
1490
assert heads == set([stop_revision])
1491
if other_last_revision == stop_revision:
1492
self.set_last_revision_info(other_last_revno,
1493
other_last_revision)
1495
# TODO: jam 2007-11-29 Is there a way to determine the
1496
# revno without searching all of history??
1498
self.generate_revision_history(stop_revision)
1500
self.generate_revision_history(stop_revision,
1501
last_rev=last_rev, other_branch=other)
1485
1523
source.lock_read()
1487
1525
result.old_revno, result.old_revid = self.last_revision_info()
1489
self.update_revisions(source, stop_revision)
1490
except DivergedBranches:
1494
if stop_revision is None:
1495
stop_revision = source.last_revision()
1496
self.generate_revision_history(stop_revision)
1526
self.update_revisions(source, stop_revision, overwrite=overwrite)
1497
1527
result.tag_conflicts = source.tags.merge_to(self.tags, overwrite)
1498
1528
result.new_revno, result.new_revid = self.last_revision_info()
1499
1529
if _hook_master:
1765
1795
# last_rev is not in the other_last_rev history, AND
1766
1796
# other_last_rev is not in our history, and do it without pulling
1767
1797
# history around
1768
last_rev = _mod_revision.ensure_null(self.last_revision())
1769
if last_rev != _mod_revision.NULL_REVISION:
1772
other_last_rev = other.last_revision()
1773
if not _mod_revision.is_null(other_last_rev):
1774
# neither branch is new, we have to do some work to
1775
# ascertain diversion.
1776
remote_graph = other.repository.get_revision_graph(
1778
local_graph = self.repository.get_revision_graph(last_rev)
1779
if (last_rev not in remote_graph and
1780
other_last_rev not in local_graph):
1781
raise errors.DivergedBranches(self, other)
1784
1798
self.set_bound_location(other.base)
1786
1800
@needs_write_lock
1809
class BzrBranchExperimental(BzrBranch5):
1810
"""Bzr experimental branch format
1813
- a revision-history file.
1815
- a lock dir guarding the branch itself
1816
- all of this stored in a branch/ subdirectory
1817
- works with shared repositories.
1818
- a tag dictionary in the branch
1820
This format is new in bzr 0.15, but shouldn't be used for real data,
1823
This class acts as it's own BranchFormat.
1826
_matchingbzrdir = bzrdir.BzrDirMetaFormat1()
1829
def get_format_string(cls):
1830
"""See BranchFormat.get_format_string()."""
1831
return "Bazaar-NG branch format experimental\n"
1834
def get_format_description(cls):
1835
"""See BranchFormat.get_format_description()."""
1836
return "Experimental branch format"
1839
def get_reference(cls, a_bzrdir):
1840
"""Get the target reference of the branch in a_bzrdir.
1842
format probing must have been completed before calling
1843
this method - it is assumed that the format of the branch
1844
in a_bzrdir is correct.
1846
:param a_bzrdir: The bzrdir to get the branch data from.
1847
:return: None if the branch is not a reference branch.
1852
def _initialize_control_files(cls, a_bzrdir, utf8_files, lock_filename,
1854
branch_transport = a_bzrdir.get_branch_transport(cls)
1855
control_files = lockable_files.LockableFiles(branch_transport,
1856
lock_filename, lock_class)
1857
control_files.create_lock()
1858
control_files.lock_write()
1860
for filename, content in utf8_files:
1861
control_files.put_utf8(filename, content)
1863
control_files.unlock()
1866
def initialize(cls, a_bzrdir):
1867
"""Create a branch of this format in a_bzrdir."""
1868
utf8_files = [('format', cls.get_format_string()),
1869
('revision-history', ''),
1870
('branch-name', ''),
1873
cls._initialize_control_files(a_bzrdir, utf8_files,
1874
'lock', lockdir.LockDir)
1875
return cls.open(a_bzrdir, _found=True)
1878
def open(cls, a_bzrdir, _found=False):
1879
"""Return the branch object for a_bzrdir
1881
_found is a private parameter, do not use it. It is used to indicate
1882
if format probing has already be done.
1885
format = BranchFormat.find_format(a_bzrdir)
1886
assert format.__class__ == cls
1887
transport = a_bzrdir.get_branch_transport(None)
1888
control_files = lockable_files.LockableFiles(transport, 'lock',
1890
return cls(_format=cls,
1891
_control_files=control_files,
1893
_repository=a_bzrdir.find_repository())
1896
def is_supported(cls):
1899
def _make_tags(self):
1900
return BasicTags(self)
1903
def supports_tags(cls):
1907
BranchFormat.register_format(BzrBranchExperimental)
1910
1823
class BzrBranch6(BzrBranch5):
1912
1825
@needs_read_lock
2098
2006
return self.new_revno - self.old_revno
2100
2008
def report(self, to_file):
2101
if self.old_revid == self.new_revid:
2102
to_file.write('No revisions to pull.\n')
2104
to_file.write('Now on revision %d.\n' % self.new_revno)
2010
if self.old_revid == self.new_revid:
2011
to_file.write('No revisions to pull.\n')
2013
to_file.write('Now on revision %d.\n' % self.new_revno)
2105
2014
self._show_tag_conficts(to_file)