~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Andrew Bennetts
  • Date: 2009-06-10 05:32:52 UTC
  • mto: This revision was merged to the branch mainline in revision 4446.
  • Revision ID: andrew.bennetts@canonical.com-20090610053252-38q6noygu4nvef8p
Move _extend_partial_history into Branch base class, and use it in get_rev_id rather than self.revision_history().

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
        self._revision_history_cache = None
92
92
        self._revision_id_to_revno_cache = None
93
93
        self._partial_revision_id_to_revno_cache = {}
 
94
        self._partial_revision_history_cache = []
94
95
        self._last_revision_info_cache = None
95
96
        self._merge_sorted_revisions_cache = None
96
97
        self._open_hook()
125
126
            raise errors.UnstackableRepositoryFormat(self.repository._format,
126
127
                self.repository.base)
127
128
 
 
129
    def _extend_partial_history(self, stop_index=None, stop_revision=None):
 
130
        """Extend the partial history to include a given index
 
131
 
 
132
        If a stop_index is supplied, stop when that index has been reached.
 
133
        If a stop_revision is supplied, stop when that revision is
 
134
        encountered.  Otherwise, stop when the beginning of history is
 
135
        reached.
 
136
 
 
137
        :param stop_index: The index which should be present.  When it is
 
138
            present, history extension will stop.
 
139
        :param revision_id: The revision id which should be present.  When
 
140
            it is encountered, history extension will stop.
 
141
        """
 
142
        repo = self.repository
 
143
        if len(self._partial_revision_history_cache) == 0:
 
144
            iterator = repo.iter_reverse_revision_history(self.last_revision())
 
145
        else:
 
146
            start_revision = self._partial_revision_history_cache[-1]
 
147
            iterator = repo.iter_reverse_revision_history(start_revision)
 
148
            #skip the last revision in the list
 
149
            next_revision = iterator.next()
 
150
        for revision_id in iterator:
 
151
            self._partial_revision_history_cache.append(revision_id)
 
152
            if (stop_index is not None and
 
153
                len(self._partial_revision_history_cache) > stop_index):
 
154
                break
 
155
            if revision_id == stop_revision:
 
156
                break
 
157
 
128
158
    @staticmethod
129
159
    def open(base, _unsupported=False, possible_transports=None):
130
160
        """Open the branch rooted at base.
698
728
        self._revision_id_to_revno_cache = None
699
729
        self._last_revision_info_cache = None
700
730
        self._merge_sorted_revisions_cache = None
 
731
        self._partial_revision_history_cache = []
 
732
        self._partial_revision_id_to_revno_cache = {}
701
733
 
702
734
    def _gen_revision_history(self):
703
735
        """Return sequence of revision hashes on to this branch.
831
863
        except ValueError:
832
864
            raise errors.NoSuchRevision(self, revision_id)
833
865
 
 
866
    @needs_read_lock
834
867
    def get_rev_id(self, revno, history=None):
835
868
        """Find the revision id of the specified revno."""
836
869
        if revno == 0:
837
870
            return _mod_revision.NULL_REVISION
838
 
        if history is None:
839
 
            history = self.revision_history()
840
 
        if revno <= 0 or revno > len(history):
 
871
        last_revno, last_revid = self.last_revision_info()
 
872
        if revno == last_revno:
 
873
            return last_revid
 
874
        if revno <= 0 or revno > last_revno:
841
875
            raise errors.NoSuchRevision(self, revno)
842
 
        return history[revno - 1]
 
876
        distance_from_last = last_revno - revno
 
877
        if len(self._partial_revision_history_cache) <= distance_from_last:
 
878
            self._extend_partial_history(revno)
 
879
        return self._partial_revision_history_cache[revno]
843
880
 
844
881
    @needs_write_lock
845
882
    def pull(self, source, overwrite=False, stop_revision=None,
2376
2413
        self._ignore_fallbacks = kwargs.get('ignore_fallbacks', False)
2377
2414
        super(BzrBranch8, self).__init__(*args, **kwargs)
2378
2415
        self._last_revision_info_cache = None
2379
 
        self._partial_revision_history_cache = []
2380
2416
        self._reference_info = None
2381
2417
 
2382
2418
    def _clear_cached_state(self):
2383
2419
        super(BzrBranch8, self)._clear_cached_state()
2384
2420
        self._last_revision_info_cache = None
2385
 
        self._partial_revision_history_cache = []
2386
2421
        self._reference_info = None
2387
2422
 
2388
2423
    def _last_revision_info(self):
2444
2479
        self._extend_partial_history(stop_index=last_revno-1)
2445
2480
        return list(reversed(self._partial_revision_history_cache))
2446
2481
 
2447
 
    def _extend_partial_history(self, stop_index=None, stop_revision=None):
2448
 
        """Extend the partial history to include a given index
2449
 
 
2450
 
        If a stop_index is supplied, stop when that index has been reached.
2451
 
        If a stop_revision is supplied, stop when that revision is
2452
 
        encountered.  Otherwise, stop when the beginning of history is
2453
 
        reached.
2454
 
 
2455
 
        :param stop_index: The index which should be present.  When it is
2456
 
            present, history extension will stop.
2457
 
        :param revision_id: The revision id which should be present.  When
2458
 
            it is encountered, history extension will stop.
2459
 
        """
2460
 
        repo = self.repository
2461
 
        if len(self._partial_revision_history_cache) == 0:
2462
 
            iterator = repo.iter_reverse_revision_history(self.last_revision())
2463
 
        else:
2464
 
            start_revision = self._partial_revision_history_cache[-1]
2465
 
            iterator = repo.iter_reverse_revision_history(start_revision)
2466
 
            #skip the last revision in the list
2467
 
            next_revision = iterator.next()
2468
 
        for revision_id in iterator:
2469
 
            self._partial_revision_history_cache.append(revision_id)
2470
 
            if (stop_index is not None and
2471
 
                len(self._partial_revision_history_cache) > stop_index):
2472
 
                break
2473
 
            if revision_id == stop_revision:
2474
 
                break
2475
 
 
2476
2482
    def _write_revision_history(self, history):
2477
2483
        """Factored out of set_revision_history.
2478
2484