/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: Aaron Bentley
  • Date: 2007-02-14 18:22:19 UTC
  • mto: This revision was merged to the branch mainline in revision 2290.
  • Revision ID: abentley@panoramicfeedback.com-20070214182219-w5d2wep3j7rb5h7r
Store revno for Branch6, set_last_revision -> set_last_revision_info

Show diffs side-by-side

added added

removed removed

Lines of Context:
977
977
 
978
978
    def initialize(self, a_bzrdir):
979
979
        """Create a branch of this format in a_bzrdir."""
980
 
        utf8_files = [('last-revision', 'null:\n'),
 
980
        utf8_files = [('last-revision', '0 null:\n'),
981
981
                      ('branch-name', ''),
982
982
                      ('branch.conf', '')
983
983
                      ]
1281
1281
            hook(self, rev_history)
1282
1282
 
1283
1283
    @needs_write_lock
1284
 
    def set_last_revision(self, revision_id):
1285
 
        self.set_revision_history(self._lefthand_history(revision_id))
 
1284
    def set_last_revision_info(self, revno, revision_id):
 
1285
        history = self._lefthand_history(revision_id)
 
1286
        assert len(history) == revno, '%d != %d' % (len(history), revno)
 
1287
        self.set_revision_history(history)
1286
1288
 
1287
1289
    def _gen_revision_history(self):
1288
1290
        decode_utf8 = cache_utf8.decode
1689
1691
class BzrBranch6(BzrBranch5):
1690
1692
 
1691
1693
    @needs_read_lock
 
1694
    def last_revision_info(self):
 
1695
        revision_string = self.control_files.get_utf8('last-revision').read()
 
1696
        revno, revision_id = revision_string.rstrip('\n').split(' ', 1)
 
1697
        revno = int(revno)
 
1698
        return revno, revision_id
 
1699
 
1692
1700
    def last_revision(self):
1693
1701
        """Return last revision id, or None"""
1694
 
        revision_id = self.control_files.get_utf8('last-revision').read()
1695
 
        revision_id = revision_id.rstrip('\n')
 
1702
        revision_id = self.last_revision_info()[1]
1696
1703
        if revision_id == _mod_revision.NULL_REVISION:
1697
1704
            revision_id = None
1698
1705
        return revision_id
1699
1706
 
1700
 
    def _write_last_revision(self, revision_id):
 
1707
    def _write_last_revision_info(self, revno, revision_id):
1701
1708
        """Simply write out the revision id, with no checks.
1702
1709
 
1703
 
        Use set_last_revision to perform this safely.
 
1710
        Use set_last_revision_info to perform this safely.
1704
1711
 
1705
1712
        Does not update the revision_history cache.
1706
 
        Intended to be called by set_last_revision and write_revision_history.
 
1713
        Intended to be called by set_last_revision_info and
 
1714
        _write_revision_history.
1707
1715
        """
1708
1716
        if revision_id is None:
1709
1717
            revision_id = 'null:'
1710
 
        self.control_files.put_utf8('last-revision', revision_id + '\n')
 
1718
        out_string = '%d %s\n' % (revno, revision_id)
 
1719
        self.control_files.put_utf8('last-revision', out_string)
1711
1720
 
1712
1721
    @needs_write_lock
1713
 
    def set_last_revision(self, revision_id):
 
1722
    def set_last_revision_info(self, revno, revision_id):
1714
1723
        if self._get_append_revisions_only():
1715
1724
            self._check_history_violation(revision_id)
1716
 
        self._write_last_revision(revision_id)
 
1725
        self._write_last_revision_info(revno, revision_id)
1717
1726
        transaction = self.get_transaction()
1718
1727
        cached_history = transaction.map.find_revision_history()
1719
1728
        if cached_history is not None:
1762
1771
            last_revision = history[-1]
1763
1772
        if self._get_append_revisions_only():
1764
1773
            self._check_history_violation(last_revision)
1765
 
        self._write_last_revision(last_revision)
 
1774
        self._write_last_revision_info(len(history), last_revision)
1766
1775
 
1767
1776
    @needs_write_lock
1768
1777
    def append_revision(self, *revision_ids):
1769
1778
        if len(revision_ids) == 0:
1770
1779
            return
1771
 
        prev_revision = self.last_revision()
 
1780
        prev_revno, prev_revision = self.last_revision_info()
1772
1781
        for revision in self.repository.get_revisions(revision_ids):
1773
 
            if prev_revision is None:
 
1782
            if prev_revision == _mod_revision.NULL_REVISION:
1774
1783
                if revision.parent_ids != []:
1775
1784
                    raise errors.NotLeftParentDescendant(self, prev_revision,
1776
1785
                                                         revision.revision_id)
1779
1788
                    raise errors.NotLeftParentDescendant(self, prev_revision,
1780
1789
                                                         revision.revision_id)
1781
1790
            prev_revision = revision.revision_id
1782
 
        self.set_last_revision(revision_ids[-1])
 
1791
        self.set_last_revision_info(prev_revno + len(revision_ids),
 
1792
                                    revision_ids[-1])
1783
1793
 
1784
1794
    def _set_config_location(self, name, url, config=None,
1785
1795
                             make_relative=False):
1865
1875
        This version is most efficient when the destination is also a
1866
1876
        BzrBranch6, but works for BzrBranch5, as long as the destination's
1867
1877
        repository contains all the lefthand ancestors of the intended
1868
 
        last_revision.  If not, set_last_revision will fail.
 
1878
        last_revision.  If not, set_last_revision_info will fail.
1869
1879
 
1870
1880
        :param destination: The branch to copy the history into
1871
1881
        :param revision_id: The revision-id to truncate history at.  May
1872
1882
          be None to copy complete history.
1873
1883
        """
1874
1884
        if revision_id is None:
1875
 
            revision_id = self.last_revision()
1876
 
        destination.set_last_revision(revision_id)
 
1885
            revno, revision_id = self.last_revision_info()
 
1886
        else:
 
1887
            revno = self.revision_id_to_revno(revision_id)
 
1888
        destination.set_last_revision_info(revno, revision_id)
1877
1889
 
1878
1890
 
1879
1891
class BranchTestProviderAdapter(object):
1946
1958
        new_branch = format.open(branch.bzrdir, _found=True)
1947
1959
 
1948
1960
        # Copy source data into target
1949
 
        new_branch.set_last_revision(branch.last_revision())
 
1961
        new_branch.set_last_revision_info(*branch.last_revision_info())
1950
1962
        new_branch.set_parent(branch.get_parent())
1951
1963
        new_branch.set_bound_location(branch.get_bound_location())
1952
1964
        new_branch.set_push_location(branch.get_push_location())