82
82
r'.*revision="(?P<revision_id>[^"]+)"'
85
def abort_write_group(self):
86
"""Commit the contents accrued within the current write group.
88
:seealso: start_write_group.
90
if self._write_group is not self.get_transaction():
91
# has an unlock or relock occured ?
92
raise errors.BzrError('mismatched lock context and write group.')
93
self._abort_write_group()
94
self._write_group = None
96
def _abort_write_group(self):
97
"""Template method for per-repository write group cleanup.
99
This is called during abort before the write group is considered to be
100
finished and should cleanup any internal state accrued during the write
101
group. There is no requirement that data handed to the repository be
102
*not* made available - this is not a rollback - but neither should any
103
attempt be made to ensure that data added is fully commited. Abort is
104
invoked when an error has occured so futher disk or network operations
105
may not be possible or may error and if possible should not be
86
110
def add_inventory(self, revision_id, inv, parents):
87
111
"""Add the inventory inv to the repository as revision_id.
230
254
# TODO: make sure to construct the right store classes, etc, depending
231
255
# on whether escaping is required.
232
256
self._warn_if_deprecated()
257
self._write_group = None
234
259
def __repr__(self):
235
260
return '%s(%r)' % (self.__class__.__name__,
236
261
self.bzrdir.transport.base)
263
def has_same_location(self, other):
264
"""Returns a boolean indicating if this repository is at the same
265
location as another repository.
267
This might return False even when two repository objects are accessing
268
the same physical repository via different URLs.
270
if self.__class__ is not other.__class__:
272
return (self.control_files._transport.base ==
273
other.control_files._transport.base)
275
def is_in_write_group(self):
276
"""Return True if there is an open write group.
278
:seealso: start_write_group.
280
return self._write_group is not None
238
282
def is_locked(self):
239
283
return self.control_files.is_locked()
241
285
def lock_write(self, token=None):
242
286
"""Lock this repository for writing.
288
This causes caching within the repository obejct to start accumlating
289
data during reads, and allows a 'write_group' to be obtained. Write
290
groups must be used for actual data insertion.
244
292
:param token: if this is already locked, then lock_write will fail
245
293
unless the token matches the existing lock.
248
296
instance doesn't support using token locks.
249
297
:raises MismatchedToken: if the specified token doesn't match the token
250
298
of the existing lock.
299
:seealso: start_write_group.
252
301
A token should be passed in if you know that you have locked the object
253
302
some other way, and need to synchronise this object's state with that
256
305
XXX: this docstring is duplicated in many places, e.g. lockable_files.py
258
return self.control_files.lock_write(token=token)
307
result = self.control_files.lock_write(token=token)
260
311
def lock_read(self):
261
312
self.control_files.lock_read()
263
315
def get_physical_lock_status(self):
264
316
return self.control_files.get_physical_lock_status()
359
411
revision_id = osutils.safe_revision_id(revision_id)
360
412
return InterRepository.get(self, destination).copy_content(revision_id)
414
def commit_write_group(self):
415
"""Commit the contents accrued within the current write group.
417
:seealso: start_write_group.
419
if self._write_group is not self.get_transaction():
420
# has an unlock or relock occured ?
421
raise errors.BzrError('mismatched lock context and write group.')
422
self._commit_write_group()
423
self._write_group = None
425
def _commit_write_group(self):
426
"""Template method for per-repository write group cleanup.
428
This is called before the write group is considered to be
429
finished and should ensure that all data handed to the repository
430
for writing during the write group is safely committed (to the
431
extent possible considering file system caching etc).
362
434
def fetch(self, source, revision_id=None, pb=None):
363
435
"""Fetch the content required to construct revision_id from source.
389
461
:param revision_id: Optional revision id.
391
463
revision_id = osutils.safe_revision_id(revision_id)
392
return _CommitBuilder(self, parents, config, timestamp, timezone,
464
result =_CommitBuilder(self, parents, config, timestamp, timezone,
393
465
committer, revprops, revision_id)
466
self.start_write_group()
395
469
def unlock(self):
470
if (self.control_files._lock_count == 1 and
471
self.control_files._lock_mode == 'w'):
472
if self._write_group is not None:
473
raise errors.BzrError(
474
'Must end write groups before releasing write locks.')
396
475
self.control_files.unlock()
410
489
self.copy_content_into(dest_repo, revision_id)
492
def start_write_group(self):
493
"""Start a write group in the repository.
495
Write groups are used by repositories which do not have a 1:1 mapping
496
between file ids and backend store to manage the insertion of data from
497
both fetch and commit operations.
499
A write lock is required around the start_write_group/commit_write_group
500
for the support of lock-requiring repository formats.
502
One can only insert data into a repository inside a write group.
506
if not self.is_locked() or self.control_files._lock_mode != 'w':
507
raise errors.NotWriteLocked(self)
508
if self._write_group:
509
raise errors.BzrError('already in a write group')
510
self._start_write_group()
511
# so we can detect unlock/relock - the write group is now entered.
512
self._write_group = self.get_transaction()
514
def _start_write_group(self):
515
"""Template method for per-repository write group startup.
517
This is called before the write group is considered to be
414
522
def sprout(self, to_bzrdir, revision_id=None):
415
523
"""Create a descendent repository for new development.
801
909
reconciler.reconcile()
802
910
return reconciler
912
def _refresh_data(self):
913
"""Helper called from lock_* to ensure coherency with disk.
915
The default implementation does nothing; it is however possible
916
for repositories to maintain loaded indices across multiple locks
917
by checking inside their implementation of this method to see
918
whether their indices are still valid. This depends of course on
919
the disk format being validatable in this manner.
805
923
def revision_tree(self, revision_id):
806
924
"""Return Tree for a revision on this branch.
1048
1166
inv = revision_tree.inventory
1049
1167
entries = inv.iter_entries()
1050
# backwards compatability hack: skip the root id.
1168
# backwards compatibility hack: skip the root id.
1051
1169
if not repository.supports_rich_root():
1052
1170
path, root = entries.next()
1053
1171
if root.revision != rev.revision_id:
1926
2044
revision_id=self._new_revision_id,
1927
2045
properties=self._revprops)
1928
2046
rev.parent_ids = self.parents
1929
self.repository.add_revision(self._new_revision_id, rev,
2047
self.repository.add_revision(self._new_revision_id, rev,
1930
2048
self.new_inventory, self._config)
2049
self.repository.commit_write_group()
1931
2050
return self._new_revision_id
1933
2052
def revision_tree(self):