~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: John Arbash Meinel
  • Date: 2007-04-26 18:53:33 UTC
  • mfrom: (2465 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2466.
  • Revision ID: john@arbash-meinel.com-20070426185333-i1xlyaeyf049kdxc
[merge] bzr.dev 2465

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
        revision as _mod_revision,
36
36
        transport,
37
37
        tree,
 
38
        tsort,
38
39
        ui,
39
40
        urlutils,
40
41
        )
100
101
    def __init__(self, *ignored, **ignored_too):
101
102
        self.tags = self._make_tags()
102
103
        self._revision_history_cache = None
 
104
        self._revision_id_to_revno_cache = None
103
105
 
104
106
    def break_lock(self):
105
107
        """Break a lock if one is present from another instance.
195
197
    def get_physical_lock_status(self):
196
198
        raise NotImplementedError(self.get_physical_lock_status)
197
199
 
 
200
    @needs_read_lock
 
201
    def get_revision_id_to_revno_map(self):
 
202
        """Return the revision_id => dotted revno map.
 
203
 
 
204
        This will be regenerated on demand, but will be cached.
 
205
 
 
206
        :return: A dictionary mapping revision_id => dotted revno.
 
207
            This dictionary should not be modified by the caller.
 
208
        """
 
209
        if self._revision_id_to_revno_cache is not None:
 
210
            mapping = self._revision_id_to_revno_cache
 
211
        else:
 
212
            mapping = self._gen_revno_map()
 
213
            self._cache_revision_id_to_revno(mapping)
 
214
        # TODO: jam 20070417 Since this is being cached, should we be returning
 
215
        #       a copy?
 
216
        # I would rather not, and instead just declare that users should not
 
217
        # modify the return value.
 
218
        return mapping
 
219
 
 
220
    def _gen_revno_map(self):
 
221
        """Create a new mapping from revision ids to dotted revnos.
 
222
 
 
223
        Dotted revnos are generated based on the current tip in the revision
 
224
        history.
 
225
        This is the worker function for get_revision_id_to_revno_map, which
 
226
        just caches the return value.
 
227
 
 
228
        :return: A dictionary mapping revision_id => dotted revno.
 
229
        """
 
230
        last_revision = self.last_revision()
 
231
        revision_graph = self.repository.get_revision_graph(last_revision)
 
232
        merge_sorted_revisions = tsort.merge_sort(
 
233
            revision_graph,
 
234
            last_revision,
 
235
            None,
 
236
            generate_revno=True)
 
237
        revision_id_to_revno = dict((rev_id, revno)
 
238
                                    for seq_num, rev_id, depth, revno, end_of_merge
 
239
                                     in merge_sorted_revisions)
 
240
        return revision_id_to_revno
 
241
 
198
242
    def leave_lock_in_place(self):
199
243
        """Tell this branch object not to release the physical lock when this
200
244
        object is unlocked.
344
388
        """
345
389
        self._revision_history_cache = rev_history
346
390
 
 
391
    def _cache_revision_id_to_revno(self, revision_id_to_revno):
 
392
        """Set the cached revision_id => revno map to revision_id_to_revno.
 
393
 
 
394
        This API is semi-public; it only for use by subclasses, all other code
 
395
        should consider it to be private.
 
396
        """
 
397
        self._revision_id_to_revno_cache = revision_id_to_revno
 
398
 
347
399
    def _clear_cached_state(self):
348
400
        """Clear any cached data on this branch, e.g. cached revision history.
349
401
 
354
406
        should consider it to be private.
355
407
        """
356
408
        self._revision_history_cache = None
 
409
        self._revision_id_to_revno_cache = None
357
410
 
358
411
    def _gen_revision_history(self):
359
412
        """Return sequence of revision hashes on to this branch.
461
514
        try:
462
515
            return history.index(revision_id) + 1
463
516
        except ValueError:
464
 
            raise bzrlib.errors.NoSuchRevision(self, revision_id)
 
517
            raise errors.NoSuchRevision(self, revision_id)
465
518
 
466
519
    def get_rev_id(self, revno, history=None):
467
520
        """Find the revision id of the specified revno."""
470
523
        if history is None:
471
524
            history = self.revision_history()
472
525
        if revno <= 0 or revno > len(history):
473
 
            raise bzrlib.errors.NoSuchRevision(self, revno)
 
526
            raise errors.NoSuchRevision(self, revno)
474
527
        return history[revno - 1]
475
528
 
476
529
    def pull(self, source, overwrite=False, stop_revision=None):
1325
1378
    def set_revision_history(self, rev_history):
1326
1379
        """See Branch.set_revision_history."""
1327
1380
        rev_history = [osutils.safe_revision_id(r) for r in rev_history]
 
1381
        self._clear_cached_state()
1328
1382
        self._write_revision_history(rev_history)
1329
1383
        self._cache_revision_history(rev_history)
1330
1384
        for hook in Branch.hooks['set_rh']:
1542
1596
                try: 
1543
1597
                    url = url.encode('ascii')
1544
1598
                except UnicodeEncodeError:
1545
 
                    raise bzrlib.errors.InvalidURL(url,
 
1599
                    raise errors.InvalidURL(url,
1546
1600
                        "Urls must be 7-bit ascii, "
1547
1601
                        "use bzrlib.urlutils.escape")
1548
1602
            url = urlutils.relative_url(self.base, url)