~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Ian Clatworthy
  • Date: 2009-01-22 13:58:18 UTC
  • mto: (3951.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 3952.
  • Revision ID: ian.clatworthy@canonical.com-20090122135818-twftjodatp3cm7xm
review feedback from jam

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
        self.tags = self._make_tags()
90
90
        self._revision_history_cache = None
91
91
        self._revision_id_to_revno_cache = None
92
 
        self._revision_id_to_revno_top_cache = {}
 
92
        self._partial_revision_id_to_revno_cache = {}
93
93
        self._last_revision_info_cache = None
94
94
        self._open_hook()
95
95
        hooks = Branch.hooks['open']
190
190
        raise NotImplementedError(self.get_physical_lock_status)
191
191
 
192
192
    @needs_read_lock
193
 
    def dotted_revno_to_revision_id(self, revno, _reverse_cache=False):
 
193
    def dotted_revno_to_revision_id(self, revno, _cache_reverse=False):
194
194
        """Return the revision_id for a dotted revno.
195
195
 
196
196
        :param revno: a tuple like (1,) or (1,1,2)
201
201
        :return: the revision_id
202
202
        :raises errors.NoSuchRevision: if the revno doesn't exist
203
203
        """
204
 
        rev_id = self._dotted_revno_to_revision_id(revno)
205
 
        if _reverse_cache:
206
 
            self._revision_id_to_revno_top_cache[rev_id] = revno
 
204
        rev_id = self._do_dotted_revno_to_revision_id(revno)
 
205
        if _cache_reverse:
 
206
            self._partial_revision_id_to_revno_cache[rev_id] = revno
207
207
        return rev_id
208
208
 
209
 
    def _dotted_revno_to_revision_id(self, revno):
 
209
    def _do_dotted_revno_to_revision_id(self, revno):
210
210
        """Worker function for dotted_revno_to_revision_id.
211
211
 
212
212
        Subclasses should override this if they wish to
215
215
        if len(revno) == 1:
216
216
            return self.get_rev_id(revno[0])
217
217
        revision_id_to_revno = self.get_revision_id_to_revno_map()
218
 
        for revision_id, this_revno in revision_id_to_revno.iteritems():
219
 
            if revno == this_revno:
220
 
                return revision_id
 
218
        revision_ids = [revision_id for revision_id, this_revno
 
219
                        in revision_id_to_revno.iteritems()
 
220
                        if revno == this_revno]
 
221
        if len(revision_ids) == 1:
 
222
            return revision_ids[0]
221
223
        else:
222
224
            revno_str = '.'.join(map(str, revno))
223
225
            raise errors.NoSuchRevision(self, revno_str)
228
230
        
229
231
        :return: a tuple like (1,) or (400,1,3).
230
232
        """
231
 
        return self._revision_id_to_dotted_revno(revision_id)
 
233
        return self._do_revision_id_to_dotted_revno(revision_id)
232
234
 
233
 
    def _revision_id_to_dotted_revno(self, revision_id):
 
235
    def _do_revision_id_to_dotted_revno(self, revision_id):
234
236
        """Worker function for revision_id_to_revno."""
235
237
        # Try the caches if they are loaded
236
 
        result = self._revision_id_to_revno_top_cache.get(revision_id)
237
 
        if result is None and self._revision_id_to_revno_cache:
 
238
        result = self._partial_revision_id_to_revno_cache.get(revision_id)
 
239
        if result is not None:
 
240
            return result
 
241
        if self._revision_id_to_revno_cache:
238
242
            result = self._revision_id_to_revno_cache.get(revision_id)
239
 
        if result is None:
240
 
            # Try the mainline as it's optimised
241
 
            try:
242
 
                revno = self.revision_id_to_revno(revision_id)
243
 
                return (revno,)
244
 
            except errors.NoSuchRevision:
245
 
                # We need to load and use the full revno map after all
246
 
                result = self.get_revision_id_to_revno_map().get(revision_id)
247
 
                if result is None:
248
 
                    raise errors.NoSuchRevision(self, revision_id)
 
243
            if result is None:
 
244
                raise errors.NoSuchRevision(self, revision_id)
 
245
        # Try the mainline as it's optimised
 
246
        try:
 
247
            revno = self.revision_id_to_revno(revision_id)
 
248
            return (revno,)
 
249
        except errors.NoSuchRevision:
 
250
            # We need to load and use the full revno map after all
 
251
            result = self.get_revision_id_to_revno_map().get(revision_id)
 
252
            if result is None:
 
253
                raise errors.NoSuchRevision(self, revision_id)
249
254
        return result
250
255
 
251
256
    def get_revision_id_to_revno_map(self):