/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: Andrew Bennetts
  • Date: 2008-04-07 10:34:57 UTC
  • mfrom: (3344 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3349.
  • Revision ID: andrew.bennetts@canonical.com-20080407103457-ro4t95pd3imwt0zw
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
        errors,
26
26
        lockdir,
27
27
        lockable_files,
 
28
        repository,
28
29
        revision as _mod_revision,
29
30
        transport,
30
31
        tsort,
192
193
        :return: A dictionary mapping revision_id => dotted revno.
193
194
        """
194
195
        last_revision = self.last_revision()
195
 
        revision_graph = self.repository.get_revision_graph(last_revision)
 
196
        revision_graph = repository._old_get_graph(self.repository,
 
197
            last_revision)
196
198
        merge_sorted_revisions = tsort.merge_sort(
197
199
            revision_graph,
198
200
            last_revision,
1375
1377
        """See Branch.set_revision_history."""
1376
1378
        if 'evil' in debug.debug_flags:
1377
1379
            mutter_callsite(3, "set_revision_history scales with history.")
1378
 
        self._clear_cached_state()
1379
1380
        self._write_revision_history(rev_history)
 
1381
        self._clear_cached_state()
1380
1382
        self._cache_revision_history(rev_history)
1381
1383
        for hook in Branch.hooks['set_rh']:
1382
1384
            hook(self, rev_history)
1809
1811
 
1810
1812
class BzrBranch6(BzrBranch5):
1811
1813
 
 
1814
    def __init__(self, *args, **kwargs):
 
1815
        super(BzrBranch6, self).__init__(*args, **kwargs)
 
1816
        self._last_revision_info_cache = None
 
1817
        self._partial_revision_history_cache = []
 
1818
 
 
1819
    def _clear_cached_state(self):
 
1820
        super(BzrBranch6, self)._clear_cached_state()
 
1821
        self._last_revision_info_cache = None
 
1822
        self._partial_revision_history_cache = []
 
1823
 
1812
1824
    @needs_read_lock
1813
1825
    def last_revision_info(self):
 
1826
        """Return information about the last revision.
 
1827
 
 
1828
        :return: A tuple (revno, revision_id).
 
1829
        """
 
1830
        if self._last_revision_info_cache is None:
 
1831
            self._last_revision_info_cache = self._last_revision_info()
 
1832
        return self._last_revision_info_cache
 
1833
 
 
1834
    def _last_revision_info(self):
1814
1835
        revision_string = self.control_files.get('last-revision').read()
1815
1836
        revno, revision_id = revision_string.rstrip('\n').split(' ', 1)
1816
1837
        revision_id = cache_utf8.get_cached_utf8(revision_id)
1837
1858
            self._check_history_violation(revision_id)
1838
1859
        self._write_last_revision_info(revno, revision_id)
1839
1860
        self._clear_cached_state()
 
1861
        self._last_revision_info_cache = revno, revision_id
1840
1862
 
1841
1863
    def _check_history_violation(self, revision_id):
1842
1864
        last_revision = _mod_revision.ensure_null(self.last_revision())
1848
1870
    def _gen_revision_history(self):
1849
1871
        """Generate the revision history from last revision
1850
1872
        """
1851
 
        history = list(self.repository.iter_reverse_revision_history(
1852
 
            self.last_revision()))
1853
 
        history.reverse()
1854
 
        return history
 
1873
        self._extend_partial_history()
 
1874
        return list(reversed(self._partial_revision_history_cache))
 
1875
 
 
1876
    def _extend_partial_history(self, stop_index=None, stop_revision=None):
 
1877
        """Extend the partial history to include a given index
 
1878
 
 
1879
        If a stop_index is supplied, stop when that index has been reached.
 
1880
        If a stop_revision is supplied, stop when that revision is
 
1881
        encountered.  Otherwise, stop when the beginning of history is
 
1882
        reached.
 
1883
 
 
1884
        :param stop_index: The index which should be present.  When it is
 
1885
            present, history extension will stop.
 
1886
        :param revision_id: The revision id which should be present.  When
 
1887
            it is encountered, history extension will stop.
 
1888
        """
 
1889
        repo = self.repository
 
1890
        if len(self._partial_revision_history_cache) == 0:
 
1891
            iterator = repo.iter_reverse_revision_history(self.last_revision())
 
1892
        else:
 
1893
            start_revision = self._partial_revision_history_cache[-1]
 
1894
            iterator = repo.iter_reverse_revision_history(start_revision)
 
1895
            #skip the last revision in the list
 
1896
            next_revision = iterator.next()
 
1897
            assert next_revision == start_revision
 
1898
        for revision_id in iterator:
 
1899
            self._partial_revision_history_cache.append(revision_id)
 
1900
            if (stop_index is not None and
 
1901
                len(self._partial_revision_history_cache) > stop_index):
 
1902
                break
 
1903
            if revision_id == stop_revision:
 
1904
                break
1855
1905
 
1856
1906
    def _write_revision_history(self, history):
1857
1907
        """Factored out of set_revision_history.
1969
2019
        revno = len(history)
1970
2020
        self.set_last_revision_info(revno, revision_id)
1971
2021
 
 
2022
    @needs_read_lock
 
2023
    def get_rev_id(self, revno, history=None):
 
2024
        """Find the revision id of the specified revno."""
 
2025
        if revno == 0:
 
2026
            return _mod_revision.NULL_REVISION
 
2027
 
 
2028
        last_revno, last_revision_id = self.last_revision_info()
 
2029
        if revno <= 0 or revno > last_revno:
 
2030
            raise errors.NoSuchRevision(self, revno)
 
2031
 
 
2032
        if history is not None:
 
2033
            assert len(history) == last_revno, 'revno/history mismatch'
 
2034
            return history[revno - 1]
 
2035
 
 
2036
        index = last_revno - revno
 
2037
        if len(self._partial_revision_history_cache) <= index:
 
2038
            self._extend_partial_history(stop_index=index)
 
2039
        if len(self._partial_revision_history_cache) > index:
 
2040
            return self._partial_revision_history_cache[index]
 
2041
        else:
 
2042
            raise errors.NoSuchRevision(self, revno)
 
2043
 
 
2044
    @needs_read_lock
 
2045
    def revision_id_to_revno(self, revision_id):
 
2046
        """Given a revision id, return its revno"""
 
2047
        if _mod_revision.is_null(revision_id):
 
2048
            return 0
 
2049
        try:
 
2050
            index = self._partial_revision_history_cache.index(revision_id)
 
2051
        except ValueError:
 
2052
            self._extend_partial_history(stop_revision=revision_id)
 
2053
            index = len(self._partial_revision_history_cache) - 1
 
2054
            if self._partial_revision_history_cache[index] != revision_id:
 
2055
                raise errors.NoSuchRevision(self, revision_id)
 
2056
        return self.revno() - index
 
2057
 
1972
2058
 
1973
2059
######################################################################
1974
2060
# results of operations