97
97
INDEX_SUFFIX = '.kndx'
100
# convenience factories for testing or use:
101
def AnnotatedKnitFactory(name, transport, mode=None):
102
"""Create a knit with path name in transport transport."""
103
return KnitVersionedFile(transport,
106
KnitAnnotateFactory(),
110
100
class KnitContent(object):
111
101
"""Content of a knit version to which deltas can be applied."""
241
231
stored and retrieved.
244
def __init__(self, transport, relpath, mode, factory,
234
def __init__(self, relpath, transport, file_mode=None, access_mode=None, factory=None,
245
235
basis_knit=None, delta=True):
246
236
"""Construct a knit at location specified by relpath."""
247
assert mode in ('r', 'w'), "invalid mode specified"
237
if access_mode is None:
239
assert access_mode in ('r', 'w'), "invalid mode specified %r" % access_mode
248
240
assert not basis_knit or isinstance(basis_knit, KnitVersionedFile), \
251
243
self.transport = transport
252
244
self.filename = relpath
253
245
self.basis_knit = basis_knit
254
self.factory = factory
255
self.writable = (mode == 'w')
246
self.factory = factory or KnitAnnotateFactory()
247
self.writable = (access_mode == 'w')
256
248
self.delta = delta
258
250
self._index = _KnitIndex(transport, relpath + INDEX_SUFFIX,
260
252
self._data = _KnitData(transport, relpath + DATA_SUFFIX,
263
255
def copy_to(self, name, transport):
264
256
"""See VersionedFile.copy_to()."""
271
263
transport.rename(name + INDEX_SUFFIX + '.tmp', name + INDEX_SUFFIX)
273
265
def create_empty(self, name, transport, mode=None):
274
return KnitVersionedFile(transport, name, 'w', self.factory, delta=self.delta)
266
return KnitVersionedFile(name, transport, factory=self.factory, delta=self.delta)
277
269
def get_suffixes():
814
806
class InterKnit(InterVersionedFile):
815
807
"""Optimised code paths for knit to knit operations."""
817
_matching_file_factory = staticmethod(AnnotatedKnitFactory)
809
_matching_file_factory = KnitVersionedFile
820
812
def is_compatible(source, target):