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
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)
201
def get_revision_id_to_revno_map(self):
202
"""Return the revision_id => dotted revno map.
204
This will be regenerated on demand, but will be cached.
206
:return: A dictionary mapping revision_id => dotted revno.
207
This dictionary should not be modified by the caller.
209
if self._revision_id_to_revno_cache is not None:
210
mapping = self._revision_id_to_revno_cache
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
216
# I would rather not, and instead just declare that users should not
217
# modify the return value.
220
def _gen_revno_map(self):
221
"""Create a new mapping from revision ids to dotted revnos.
223
Dotted revnos are generated based on the current tip in the revision
225
This is the worker function for get_revision_id_to_revno_map, which
226
just caches the return value.
228
:return: A dictionary mapping revision_id => dotted revno.
230
last_revision = self.last_revision()
231
revision_graph = self.repository.get_revision_graph(last_revision)
232
merge_sorted_revisions = tsort.merge_sort(
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
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.
345
389
self._revision_history_cache = rev_history
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.
394
This API is semi-public; it only for use by subclasses, all other code
395
should consider it to be private.
397
self._revision_id_to_revno_cache = revision_id_to_revno
347
399
def _clear_cached_state(self):
348
400
"""Clear any cached data on this branch, e.g. cached revision history.
354
406
should consider it to be private.
356
408
self._revision_history_cache = None
409
self._revision_id_to_revno_cache = None
358
411
def _gen_revision_history(self):
359
412
"""Return sequence of revision hashes on to this branch.
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)
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]
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']:
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)