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)
755
777
version in version_ids]
756
778
for name in topo_sort(pending_graph):
757
779
other_idx = other._name_map[name]
758
self._check_version_consistent(other, other_idx, name)
759
sha1 = other._sha1s[other_idx]
780
# returns True if we have it, False if we need it.
781
if not self._check_version_consistent(other, other_idx, name):
782
names_to_join.append((other_idx, name))
763
if name in self._name_map:
764
idx = self._lookup(name)
765
n1 = set(map(other._idx_to_name, other._parents[other_idx]))
766
n2 = set(map(self._idx_to_name, self._parents[idx]))
767
if sha1 == self._sha1s[idx] and n1 == n2:
770
names_to_join.append((other_idx, name))
772
786
if pb and not msg:
773
787
msg = 'weave join'
845
859
:param msg: An optional message for the progress
847
861
new_weave = _reweave(self, other, pb=pb, msg=msg)
862
self._copy_weave_content(new_weave)
864
def _copy_weave_content(self, otherweave):
865
"""adsorb the content from otherweave."""
848
866
for attr in self.__slots__:
849
867
if attr != '_weave_name':
850
setattr(self, attr, getattr(new_weave, attr))
868
setattr(self, attr, copy(getattr(otherweave, attr)))
853
871
class WeaveFile(Weave):
856
874
WEAVE_SUFFIX = '.weave'
858
def __init__(self, name, transport, mode=None, create=False):
876
def __init__(self, name, transport, filemode=None, create=False, access_mode='w'):
859
877
"""Create a WeaveFile.
861
879
:param create: If not True, only open an existing knit.
863
super(WeaveFile, self).__init__(name)
881
super(WeaveFile, self).__init__(name, access_mode)
864
882
self._transport = transport
883
self._filemode = filemode
867
885
_read_weave_v5(self._transport.get(name + WeaveFile.WEAVE_SUFFIX), self)
868
886
except errors.NoSuchFile:
871
889
# new file, save it
874
def add_lines(self, version_id, parents, lines):
892
def _add_lines(self, version_id, parents, lines):
875
893
"""Add a version and save the weave."""
876
super(WeaveFile, self).add_lines(version_id, parents, lines)
894
super(WeaveFile, self)._add_lines(version_id, parents, lines)
897
def _clone_text(self, new_version_id, old_version_id, parents):
898
"""See VersionedFile.clone_text."""
899
super(WeaveFile, self)._clone_text(new_version_id, old_version_id, parents)
879
902
def copy_to(self, name, transport):
880
903
"""See VersionedFile.copy_to()."""
881
904
# as we are all in memory always, just serialise to the new place.
883
906
write_weave_v5(self, sio)
885
transport.put(name + WeaveFile.WEAVE_SUFFIX, sio, self._mode)
908
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)
910
def create_empty(self, name, transport, filemode=None):
911
return WeaveFile(name, transport, filemode, create=True)
891
914
"""Save the weave."""
915
self._check_write_ok()
893
917
write_weave_v5(self, sio)
895
919
self._transport.put(self._weave_name + WeaveFile.WEAVE_SUFFIX,
900
924
def get_suffixes():
1233
1257
def join(self, pb=None, msg=None, version_ids=None, ignore_missing=False):
1234
1258
"""See InterVersionedFile.join."""
1259
if self.target.versions() == []:
1261
self.target._copy_weave_content(self.source)
1236
1264
self.target._join(self.source, pb, msg, version_ids, ignore_missing)
1237
1265
except errors.WeaveParentMismatch: