180
181
__slots__ = ['_weave', '_parents', '_sha1s', '_names', '_name_map',
183
def __init__(self, weave_name=None):
184
def __init__(self, weave_name=None, access_mode='w'):
185
super(Weave, self).__init__(access_mode)
185
187
self._parents = []
278
280
"""Please use Weave.clone_text now."""
279
281
return self.clone_text(new_rev_id, old_rev_id, parents)
281
def add_lines(self, version_id, parents, lines):
283
def _add_lines(self, version_id, parents, lines):
282
284
"""See VersionedFile.add_lines."""
283
285
return self._add(version_id, lines, map(self._lookup, parents))
406
408
offset += 2 + (j2 - j1)
407
409
return new_version
409
def clone_text(self, new_version_id, old_version_id, parents):
411
def _clone_text(self, new_version_id, old_version_id, parents):
410
412
"""See VersionedFile.clone_text."""
411
413
old_lines = self.get_text(old_version_id)
412
414
self.add_lines(new_version_id, parents, old_lines)
493
495
@deprecated_method(zero_eight)
495
"""_walk has become walk, a supported api."""
497
"""_walk has become visit, a supported api."""
498
return self._walk_internal()
500
def iter_lines_added_or_present_in_versions(self, version_ids=None):
501
"""See VersionedFile.iter_lines_added_or_present_in_versions()."""
502
if version_ids is None:
503
version_ids = self.versions()
504
version_ids = set(version_ids)
505
for lineno, inserted, deletes, line in self._walk_internal(version_ids):
506
# if inserted not in version_ids then it was inserted before the
507
# versions we care about, but because weaves cannot represent ghosts
508
# properly, we do not filter down to that
509
# if inserted not in version_ids: continue
515
#@deprecated_method(zero_eight)
498
516
def walk(self, version_ids=None):
499
517
"""See VersionedFile.walk."""
518
return self._walk_internal(version_ids)
520
def _walk_internal(self, version_ids=None):
521
"""Helper method for weave actions."""
705
727
update_text = 'checking %s' % (short_name,)
706
728
update_text = update_text[:25]
708
for lineno, insert, deleteset, line in self.walk():
730
for lineno, insert, deleteset, line in self._walk_internal():
710
732
progress_bar.update(update_text, lineno, nlines)
845
867
:param msg: An optional message for the progress
847
869
new_weave = _reweave(self, other, pb=pb, msg=msg)
870
self._copy_weave_content(new_weave)
872
def _copy_weave_content(self, otherweave):
873
"""adsorb the content from otherweave."""
848
874
for attr in self.__slots__:
849
875
if attr != '_weave_name':
850
setattr(self, attr, getattr(new_weave, attr))
876
setattr(self, attr, copy(getattr(otherweave, attr)))
853
879
class WeaveFile(Weave):
856
882
WEAVE_SUFFIX = '.weave'
858
def __init__(self, name, transport, mode=None, create=False):
884
def __init__(self, name, transport, filemode=None, create=False, access_mode='w'):
859
885
"""Create a WeaveFile.
861
887
:param create: If not True, only open an existing knit.
863
super(WeaveFile, self).__init__(name)
889
super(WeaveFile, self).__init__(name, access_mode)
864
890
self._transport = transport
891
self._filemode = filemode
867
893
_read_weave_v5(self._transport.get(name + WeaveFile.WEAVE_SUFFIX), self)
868
894
except errors.NoSuchFile:
871
897
# new file, save it
874
def add_lines(self, version_id, parents, lines):
900
def _add_lines(self, version_id, parents, lines):
875
901
"""Add a version and save the weave."""
876
super(WeaveFile, self).add_lines(version_id, parents, lines)
902
super(WeaveFile, self)._add_lines(version_id, parents, lines)
905
def _clone_text(self, new_version_id, old_version_id, parents):
906
"""See VersionedFile.clone_text."""
907
super(WeaveFile, self)._clone_text(new_version_id, old_version_id, parents)
879
910
def copy_to(self, name, transport):
880
911
"""See VersionedFile.copy_to()."""
881
912
# as we are all in memory always, just serialise to the new place.
883
914
write_weave_v5(self, sio)
885
transport.put(name + WeaveFile.WEAVE_SUFFIX, sio, self._mode)
916
transport.put(name + WeaveFile.WEAVE_SUFFIX, sio, self._filemode)
887
def create_empty(self, name, transport, mode=None):
888
return WeaveFile(name, transport, mode, create=True)
918
def create_empty(self, name, transport, filemode=None):
919
return WeaveFile(name, transport, filemode, create=True)
891
922
"""Save the weave."""
923
self._check_write_ok()
893
925
write_weave_v5(self, sio)
895
927
self._transport.put(self._weave_name + WeaveFile.WEAVE_SUFFIX,
900
932
def get_suffixes():
1233
1265
def join(self, pb=None, msg=None, version_ids=None, ignore_missing=False):
1234
1266
"""See InterVersionedFile.join."""
1267
if self.target.versions() == []:
1269
self.target._copy_weave_content(self.source)
1236
1272
self.target._join(self.source, pb, msg, version_ids, ignore_missing)
1237
1273
except errors.WeaveParentMismatch: