/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Robert Collins
  • Date: 2008-02-13 03:30:01 UTC
  • mfrom: (3221 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3224.
  • Revision ID: robertc@robertcollins.net-20080213033001-rw70ul0zb02ph856
Merge to fix conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
                                      zero_eight, zero_nine, zero_sixteen,
63
63
                                      zero_ninetyone,
64
64
                                      )
65
 
from bzrlib.trace import mutter, mutter_callsite, note
 
65
from bzrlib.trace import mutter, mutter_callsite, note, is_quiet
66
66
 
67
67
 
68
68
BZR_BRANCH_FORMAT_4 = "Bazaar-NG branch, format 0.0.4\n"
425
425
        That is equivalent to the number of revisions committed to
426
426
        this branch.
427
427
        """
428
 
        return len(self.revision_history())
 
428
        return self.last_revision_info()[0]
429
429
 
430
430
    def unbind(self):
431
431
        """Older format branches cannot bind or unbind."""
436
436
        raise errors.UpgradeRequired(self.base)
437
437
 
438
438
    def last_revision(self):
439
 
        """Return last revision id, or None"""
440
 
        ph = self.revision_history()
441
 
        if ph:
442
 
            return ph[-1]
443
 
        else:
444
 
            return _mod_revision.NULL_REVISION
 
439
        """Return last revision id, or NULL_REVISION."""
 
440
        return self.last_revision_info()[1]
445
441
 
446
442
    def last_revision_info(self):
447
443
        """Return information about the last revision.
757
753
        return format
758
754
 
759
755
    def create_checkout(self, to_location, revision_id=None,
760
 
                        lightweight=False):
 
756
                        lightweight=False, accelerator_tree=None):
761
757
        """Create a checkout of a branch.
762
758
        
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
768
768
        """
769
769
        t = transport.get_transport(to_location)
783
783
            checkout_branch.pull(self, stop_revision=revision_id)
784
784
            from_branch=None
785
785
        tree = checkout.create_workingtree(revision_id,
786
 
                                           from_branch=from_branch)
 
786
                                           from_branch=from_branch,
 
787
                                           accelerator_tree=accelerator_tree)
787
788
        basis_tree = tree.basis_tree()
788
789
        basis_tree.lock_read()
789
790
        try:
868
869
        """
869
870
        return None
870
871
 
 
872
    @classmethod
 
873
    def set_reference(self, a_bzrdir, to_branch):
 
874
        """Set the target reference of the branch in a_bzrdir.
 
875
 
 
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.
 
879
 
 
880
        :param a_bzrdir: The bzrdir to set the branch reference for.
 
881
        :param to_branch: branch that the checkout is to reference
 
882
        """
 
883
        raise NotImplementedError(self.set_reference)
 
884
 
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()
1200
1214
 
 
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)
 
1219
 
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))
1440
1459
 
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()
1445
1464
        try:
 
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.
1450
1470
                    return
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,
1460
 
                                                       last_rev):
1461
 
                return
1462
 
            self.generate_revision_history(stop_revision, last_rev=last_rev,
1463
 
                other_branch=other)
 
1479
            # Check to see if one is an ancestor of the other
 
1480
            if not overwrite:
 
1481
                heads = self.repository.get_graph().heads([stop_revision,
 
1482
                                                           last_rev])
 
1483
                if heads == set([last_rev]):
 
1484
                    # The current revision is a decendent of the target,
 
1485
                    # nothing to do
 
1486
                    return
 
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)
 
1494
            else:
 
1495
                # TODO: jam 2007-11-29 Is there a way to determine the
 
1496
                #       revno without searching all of history??
 
1497
                if overwrite:
 
1498
                    self.generate_revision_history(stop_revision)
 
1499
                else:
 
1500
                    self.generate_revision_history(stop_revision,
 
1501
                        last_rev=last_rev, other_branch=other)
1464
1502
        finally:
1465
1503
            other.unlock()
1466
1504
 
1485
1523
        source.lock_read()
1486
1524
        try:
1487
1525
            result.old_revno, result.old_revid = self.last_revision_info()
1488
 
            try:
1489
 
                self.update_revisions(source, stop_revision)
1490
 
            except DivergedBranches:
1491
 
                if not overwrite:
1492
 
                    raise
1493
 
            if overwrite:
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:
1770
 
            other.lock_read()
1771
 
            try:
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(
1777
 
                        other_last_rev)
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)
1782
 
            finally:
1783
 
                other.unlock()
1784
1798
        self.set_bound_location(other.base)
1785
1799
 
1786
1800
    @needs_write_lock
1806
1820
        return None
1807
1821
 
1808
1822
 
1809
 
class BzrBranchExperimental(BzrBranch5):
1810
 
    """Bzr experimental branch format
1811
 
 
1812
 
    This format has:
1813
 
     - a revision-history file.
1814
 
     - a format string
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
1819
 
 
1820
 
    This format is new in bzr 0.15, but shouldn't be used for real data, 
1821
 
    only for testing.
1822
 
 
1823
 
    This class acts as it's own BranchFormat.
1824
 
    """
1825
 
 
1826
 
    _matchingbzrdir = bzrdir.BzrDirMetaFormat1()
1827
 
 
1828
 
    @classmethod
1829
 
    def get_format_string(cls):
1830
 
        """See BranchFormat.get_format_string()."""
1831
 
        return "Bazaar-NG branch format experimental\n"
1832
 
 
1833
 
    @classmethod
1834
 
    def get_format_description(cls):
1835
 
        """See BranchFormat.get_format_description()."""
1836
 
        return "Experimental branch format"
1837
 
 
1838
 
    @classmethod
1839
 
    def get_reference(cls, a_bzrdir):
1840
 
        """Get the target reference of the branch in a_bzrdir.
1841
 
 
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.
1845
 
 
1846
 
        :param a_bzrdir: The bzrdir to get the branch data from.
1847
 
        :return: None if the branch is not a reference branch.
1848
 
        """
1849
 
        return None
1850
 
 
1851
 
    @classmethod
1852
 
    def _initialize_control_files(cls, a_bzrdir, utf8_files, lock_filename,
1853
 
            lock_class):
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()
1859
 
        try:
1860
 
            for filename, content in utf8_files:
1861
 
                control_files.put_utf8(filename, content)
1862
 
        finally:
1863
 
            control_files.unlock()
1864
 
        
1865
 
    @classmethod
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', ''),
1871
 
                      ('tags', ''),
1872
 
                      ]
1873
 
        cls._initialize_control_files(a_bzrdir, utf8_files,
1874
 
            'lock', lockdir.LockDir)
1875
 
        return cls.open(a_bzrdir, _found=True)
1876
 
 
1877
 
    @classmethod
1878
 
    def open(cls, a_bzrdir, _found=False):
1879
 
        """Return the branch object for a_bzrdir
1880
 
 
1881
 
        _found is a private parameter, do not use it. It is used to indicate
1882
 
               if format probing has already be done.
1883
 
        """
1884
 
        if not _found:
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',
1889
 
                                                     lockdir.LockDir)
1890
 
        return cls(_format=cls,
1891
 
            _control_files=control_files,
1892
 
            a_bzrdir=a_bzrdir,
1893
 
            _repository=a_bzrdir.find_repository())
1894
 
 
1895
 
    @classmethod
1896
 
    def is_supported(cls):
1897
 
        return True
1898
 
 
1899
 
    def _make_tags(self):
1900
 
        return BasicTags(self)
1901
 
 
1902
 
    @classmethod
1903
 
    def supports_tags(cls):
1904
 
        return True
1905
 
 
1906
 
 
1907
 
BranchFormat.register_format(BzrBranchExperimental)
1908
 
 
1909
 
 
1910
1823
class BzrBranch6(BzrBranch5):
1911
1824
 
1912
1825
    @needs_read_lock
1917
1830
        revno = int(revno)
1918
1831
        return revno, revision_id
1919
1832
 
1920
 
    def last_revision(self):
1921
 
        """Return last revision id, or None"""
1922
 
        revision_id = self.last_revision_info()[1]
1923
 
        return revision_id
1924
 
 
1925
1833
    def _write_last_revision_info(self, revno, revision_id):
1926
1834
        """Simply write out the revision id, with no checks.
1927
1835
 
2098
2006
        return self.new_revno - self.old_revno
2099
2007
 
2100
2008
    def report(self, to_file):
2101
 
        if self.old_revid == self.new_revid:
2102
 
            to_file.write('No revisions to pull.\n')
2103
 
        else:
2104
 
            to_file.write('Now on revision %d.\n' % self.new_revno)
 
2009
        if not is_quiet():
 
2010
            if self.old_revid == self.new_revid:
 
2011
                to_file.write('No revisions to pull.\n')
 
2012
            else:
 
2013
                to_file.write('Now on revision %d.\n' % self.new_revno)
2105
2014
        self._show_tag_conficts(to_file)
2106
2015
 
2107
2016