173
160
each version; the parent's parents are implied.
176
List of hex SHA-1 of each version.
179
List of symbolic names for each version. Each should be unique.
182
For each name, the version number.
185
Descriptive name of this weave; typically the filename if known.
163
List of hex SHA-1 of each version, or None if not recorded.
189
__slots__ = ['_weave', '_parents', '_sha1s', '_names', '_name_map',
190
'_weave_name', '_matcher']
166
__slots__ = ['_weave', '_parents', '_sha1s']
192
def __init__(self, weave_name=None, access_mode='w', matcher=None):
193
super(Weave, self).__init__(access_mode)
195
170
self._parents = []
199
self._weave_name = weave_name
201
self._matcher = bzrlib.patiencediff.PatienceSequenceMatcher
203
self._matcher = matcher
206
return "Weave(%r)" % self._weave_name
209
"""Return a deep copy of self.
211
The copy can be modified without affecting the original weave."""
213
other._weave = self._weave[:]
214
other._parents = self._parents[:]
215
other._sha1s = self._sha1s[:]
216
other._names = self._names[:]
217
other._name_map = self._name_map.copy()
218
other._weave_name = self._weave_name
221
174
def __eq__(self, other):
222
175
if not isinstance(other, Weave):
224
177
return self._parents == other._parents \
225
and self._weave == other._weave \
226
and self._sha1s == other._sha1s
178
and self._weave == other._weave
228
181
def __ne__(self, other):
229
182
return not self.__eq__(other)
231
@deprecated_method(zero_eight)
232
def idx_to_name(self, index):
233
"""Old public interface, the public interface is all names now."""
236
def _idx_to_name(self, version):
237
return self._names[version]
239
@deprecated_method(zero_eight)
240
def lookup(self, name):
241
"""Backwards compatibility thunk:
243
Return name, as name is valid in the api now, and spew deprecation
248
def _lookup(self, name):
249
"""Convert symbolic version name to index."""
251
return self._name_map[name]
253
raise RevisionNotPresent(name, self._weave_name)
255
@deprecated_method(zero_eight)
256
def iter_names(self):
257
"""Deprecated convenience function, please see VersionedFile.names()."""
258
return iter(self.names())
260
@deprecated_method(zero_eight)
262
"""See Weave.versions for the current api."""
263
return self.versions()
266
"""See VersionedFile.versions."""
267
return self._names[:]
269
def has_version(self, version_id):
270
"""See VersionedFile.has_version."""
271
return (version_id in self._name_map)
273
__contains__ = has_version
275
def get_delta(self, version_id):
276
"""See VersionedFile.get_delta."""
277
return self.get_deltas([version_id])[version_id]
279
def get_deltas(self, version_ids):
280
"""See VersionedFile.get_deltas."""
281
version_ids = self.get_ancestry(version_ids)
282
for version_id in version_ids:
283
if not self.has_version(version_id):
284
raise RevisionNotPresent(version_id, self)
285
# try extracting all versions; parallel extraction is used
286
nv = self.num_versions()
292
last_parent_lines = {}
294
parent_inclusions = {}
299
# its simplest to generate a full set of prepared variables.
301
name = self._names[i]
302
sha1s[name] = self.get_sha1(name)
303
parents_list = self.get_parents(name)
305
parent = parents_list[0]
306
parents[name] = parent
307
parent_inclusions[name] = inclusions[parent]
310
parent_inclusions[name] = set()
311
# we want to emit start, finish, replacement_length, replacement_lines tuples.
312
diff_hunks[name] = []
313
current_hunks[name] = [0, 0, 0, []] # #start, finish, repl_length, repl_tuples
314
parent_linenums[name] = 0
316
parent_noeols[name] = False
317
last_parent_lines[name] = None
318
new_inc = set([name])
319
for p in self._parents[i]:
320
new_inc.update(inclusions[self._idx_to_name(p)])
321
# debug only, known good so far.
322
#assert set(new_inc) == set(self.get_ancestry(name)), \
323
# 'failed %s != %s' % (set(new_inc), set(self.get_ancestry(name)))
324
inclusions[name] = new_inc
326
nlines = len(self._weave)
328
for lineno, inserted, deletes, line in self._walk_internal():
329
# a line is active in a version if:
330
# insert is in the versions inclusions
332
# deleteset & the versions inclusions is an empty set.
333
# so - if we have a included by mapping - version is included by
334
# children, we get a list of children to examine for deletes affect
335
# ing them, which is less than the entire set of children.
336
for version_id in version_ids:
337
# The active inclusion must be an ancestor,
338
# and no ancestors must have deleted this line,
339
# because we don't support resurrection.
340
parent_inclusion = parent_inclusions[version_id]
341
inclusion = inclusions[version_id]
342
parent_active = inserted in parent_inclusion and not (deletes & parent_inclusion)
343
version_active = inserted in inclusion and not (deletes & inclusion)
344
if not parent_active and not version_active:
345
# unrelated line of ancestry
347
elif parent_active and version_active:
349
parent_linenum = parent_linenums[version_id]
350
if current_hunks[version_id] != [parent_linenum, parent_linenum, 0, []]:
351
diff_hunks[version_id].append(tuple(current_hunks[version_id]))
353
current_hunks[version_id] = [parent_linenum, parent_linenum, 0, []]
354
parent_linenums[version_id] = parent_linenum
357
noeols[version_id] = True
360
elif parent_active and not version_active:
362
current_hunks[version_id][1] += 1
363
parent_linenums[version_id] += 1
364
last_parent_lines[version_id] = line
365
elif not parent_active and version_active:
367
# noeol only occurs at the end of a file because we
368
# diff linewise. We want to show noeol changes as a
369
# empty diff unless the actual eol-less content changed.
372
if last_parent_lines[version_id][-1] != '\n':
373
parent_noeols[version_id] = True
374
except (TypeError, IndexError):
377
if theline[-1] != '\n':
378
noeols[version_id] = True
382
parent_should_go = False
384
if parent_noeols[version_id] == noeols[version_id]:
385
# no noeol toggle, so trust the weaves statement
386
# that this line is changed.
388
if parent_noeols[version_id]:
389
theline = theline + '\n'
390
elif parent_noeols[version_id]:
391
# parent has no eol, we do:
392
# our line is new, report as such..
394
elif noeols[version_id]:
395
# append a eol so that it looks like
397
theline = theline + '\n'
398
if parents[version_id] is not None:
399
#if last_parent_lines[version_id] is not None:
400
parent_should_go = True
401
if last_parent_lines[version_id] != theline:
404
#parent_should_go = False
406
current_hunks[version_id][2] += 1
407
current_hunks[version_id][3].append((inserted, theline))
409
# last hunk last parent line is not eaten
410
current_hunks[version_id][1] -= 1
411
if current_hunks[version_id][1] < 0:
412
current_hunks[version_id][1] = 0
413
# import pdb;pdb.set_trace()
414
# assert current_hunks[version_id][1] >= 0
418
version = self._idx_to_name(i)
419
if current_hunks[version] != [0, 0, 0, []]:
420
diff_hunks[version].append(tuple(current_hunks[version]))
422
for version_id in version_ids:
423
result[version_id] = (
427
diff_hunks[version_id],
431
def get_parents(self, version_id):
432
"""See VersionedFile.get_parent."""
433
return map(self._idx_to_name, self._parents[self._lookup(version_id)])
435
def _check_repeated_add(self, name, parents, text, sha1):
436
"""Check that a duplicated add is OK.
438
If it is, return the (old) index; otherwise raise an exception.
440
idx = self._lookup(name)
441
if sorted(self._parents[idx]) != sorted(parents) \
442
or sha1 != self._sha1s[idx]:
443
raise RevisionAlreadyPresent(name, self._weave_name)
446
@deprecated_method(zero_eight)
447
def add_identical(self, old_rev_id, new_rev_id, parents):
448
"""Please use Weave.clone_text now."""
449
return self.clone_text(new_rev_id, old_rev_id, parents)
451
def _add_lines(self, version_id, parents, lines, parent_texts):
452
"""See VersionedFile.add_lines."""
453
return self._add(version_id, lines, map(self._lookup, parents))
455
@deprecated_method(zero_eight)
456
def add(self, name, parents, text, sha1=None):
457
"""See VersionedFile.add_lines for the non deprecated api."""
458
return self._add(name, text, map(self._maybe_lookup, parents), sha1)
460
def _add(self, version_id, lines, parents, sha1=None):
185
def add(self, parents, text):
461
186
"""Add a single text on top of the weave.
463
188
Returns the index number of the newly added version.
466
Symbolic name for this version.
467
(Typically the revision-id of the revision that added it.)
470
191
List or set of direct parent version numbers.
473
Sequence of lines to be added in the new version.
476
assert isinstance(version_id, basestring)
477
self._check_lines_not_unicode(lines)
478
self._check_lines_are_lines(lines)
480
sha1 = sha_strings(lines)
481
if version_id in self._name_map:
482
return self._check_repeated_add(version_id, parents, lines, sha1)
194
Sequence of lines to be added in the new version."""
484
196
self._check_versions(parents)
485
## self._check_lines(lines)
197
## self._check_lines(text)
486
198
new_version = len(self._parents)
488
# if we abort after here the (in-memory) weave will be corrupt because only
489
# some fields are updated
490
# XXX: FIXME implement a succeed-or-fail of the rest of this routine.
491
# - Robert Collins 20060226
492
self._parents.append(parents[:])
206
# if we abort after here the weave will be corrupt
207
self._parents.append(frozenset(parents))
493
208
self._sha1s.append(sha1)
494
self._names.append(version_id)
495
self._name_map[version_id] = new_version
848
assert l.__class__ in (str, unicode)
447
assert isinstance(l, basestring)
849
448
if isactive is None:
850
449
isactive = (not dset) and istack and (istack[-1] in included)
852
451
result.append((istack[-1], lineno, l))
855
raise WeaveFormatError("unclosed insertion blocks "
856
"at end of weave: %s" % istack)
455
raise WFE("unclosed insertion blocks at end of weave",
858
raise WeaveFormatError("unclosed deletion blocks at end of weave: %s"
862
@deprecated_method(zero_eight)
863
def get_iter(self, name_or_index):
864
"""Deprecated, please do not use. Lookups are not not needed.
866
Please use get_lines now.
868
return iter(self.get_lines(self._maybe_lookup(name_or_index)))
870
@deprecated_method(zero_eight)
871
def maybe_lookup(self, name_or_index):
872
"""Deprecated, please do not use. Lookups are not not needed."""
873
return self._maybe_lookup(name_or_index)
875
def _maybe_lookup(self, name_or_index):
876
"""Convert possible symbolic name to index, or pass through indexes.
880
if isinstance(name_or_index, (int, long)):
883
return self._lookup(name_or_index)
885
@deprecated_method(zero_eight)
886
def get(self, version_id):
887
"""Please use either Weave.get_text or Weave.get_lines as desired."""
888
return self.get_lines(version_id)
890
def get_lines(self, version_id):
891
"""See VersionedFile.get_lines()."""
892
int_index = self._maybe_lookup(version_id)
893
result = [line for (origin, lineno, line) in self._extract([int_index])]
894
expected_sha1 = self._sha1s[int_index]
895
measured_sha1 = sha_strings(result)
896
if measured_sha1 != expected_sha1:
897
raise errors.WeaveInvalidChecksum(
898
'file %s, revision %s, expected: %s, measured %s'
899
% (self._weave_name, version_id,
900
expected_sha1, measured_sha1))
903
def get_sha1(self, version_id):
904
"""See VersionedFile.get_sha1()."""
905
return self._sha1s[self._lookup(version_id)]
907
@deprecated_method(zero_eight)
458
raise WFE("unclosed deletion blocks at end of weave",
465
def get_iter(self, version):
466
"""Yield lines for the specified version."""
467
for origin, lineno, line in self._extract([version]):
471
def get(self, index):
472
return list(self.get_iter(index))
475
def mash_iter(self, included):
476
"""Return composed version of multiple included versions."""
477
for origin, lineno, text in self._extract(included):
481
def dump(self, to_file):
482
from pprint import pprint
483
print >>to_file, "Weave._weave = ",
484
pprint(self._weave, to_file)
485
print >>to_file, "Weave._parents = ",
486
pprint(self._parents, to_file)
908
490
def numversions(self):
909
"""How many versions are in this weave?
911
Deprecated in favour of num_versions.
913
return self.num_versions()
915
def num_versions(self):
916
"""How many versions are in this weave?"""
917
491
l = len(self._parents)
918
492
assert l == len(self._sha1s)
921
__len__ = num_versions
497
return self.numversions()
923
500
def check(self, progress_bar=None):
924
# TODO evaluate performance hit of using string sets in this routine.
925
# TODO: check no circular inclusions
926
# TODO: create a nested progress bar
927
for version in range(self.num_versions()):
501
# check no circular inclusions
502
for version in range(self.numversions()):
928
503
inclusions = list(self._parents[version])
930
505
inclusions.sort()
932
507
raise WeaveFormatError("invalid included version %d for index %d"
933
508
% (inclusions[-1], version))
935
# try extracting all versions; parallel extraction is used
936
nv = self.num_versions()
941
# For creating the ancestry, IntSet is much faster (3.7s vs 0.17s)
942
# The problem is that set membership is much more expensive
943
name = self._idx_to_name(i)
944
sha1s[name] = sha.new()
946
new_inc = set([name])
947
for p in self._parents[i]:
948
new_inc.update(inclusions[self._idx_to_name(p)])
950
assert set(new_inc) == set(self.get_ancestry(name)), \
951
'failed %s != %s' % (set(new_inc), set(self.get_ancestry(name)))
952
inclusions[name] = new_inc
954
nlines = len(self._weave)
956
update_text = 'checking weave'
958
short_name = os.path.basename(self._weave_name)
959
update_text = 'checking %s' % (short_name,)
960
update_text = update_text[:25]
962
for lineno, insert, deleteset, line in self._walk_internal():
510
# try extracting all versions; this is a bit slow and parallel
511
# extraction could be used
513
nv = self.numversions()
514
for version in range(nv):
964
progress_bar.update(update_text, lineno, nlines)
966
for name, name_inclusions in inclusions.items():
967
# The active inclusion must be an ancestor,
968
# and no ancestors must have deleted this line,
969
# because we don't support resurrection.
970
if (insert in name_inclusions) and not (deleteset & name_inclusions):
971
sha1s[name].update(line)
974
version = self._idx_to_name(i)
975
hd = sha1s[version].hexdigest()
976
expected = self._sha1s[i]
516
progress_bar.update('checking text', version, nv)
518
for l in self.get_iter(version):
521
expected = self._sha1s[version]
977
522
if hd != expected:
978
raise errors.WeaveInvalidChecksum(
979
"mismatched sha1 for version %s: "
980
"got %s, expected %s"
981
% (version, hd, expected))
523
raise WeaveError("mismatched sha1 for version %d; "
524
"got %s, expected %s"
525
% (version, hd, expected))
983
527
# TODO: check insertions are properly nested, that there are
984
528
# no lines outside of insertion blocks, that deletions are
985
529
# properly paired, etc.
987
def _join(self, other, pb, msg, version_ids, ignore_missing):
988
"""Worker routine for join()."""
989
if not other.versions():
990
return # nothing to update, easy
993
# versions is never none, InterWeave checks this.
996
# two loops so that we do not change ourselves before verifying it
998
# work through in index order to make sure we get all dependencies
1001
# get the selected versions only that are in other.versions.
1002
version_ids = set(other.versions()).intersection(set(version_ids))
1003
# pull in the referenced graph.
1004
version_ids = other.get_ancestry(version_ids)
1005
pending_graph = [(version, other.get_parents(version)) for
1006
version in version_ids]
1007
for name in topo_sort(pending_graph):
1008
other_idx = other._name_map[name]
1009
# returns True if we have it, False if we need it.
1010
if not self._check_version_consistent(other, other_idx, name):
1011
names_to_join.append((other_idx, name))
1020
for other_idx, name in names_to_join:
1021
# TODO: If all the parents of the other version are already
1022
# present then we can avoid some work by just taking the delta
1023
# and adjusting the offsets.
1024
new_parents = self._imported_parents(other, other_idx)
1025
sha1 = other._sha1s[other_idx]
1030
pb.update(msg, merged, len(names_to_join))
1032
lines = other.get_lines(other_idx)
1033
self._add(name, lines, new_parents, sha1)
1035
mutter("merged = %d, processed = %d, file_id=%s; deltat=%d"%(
1036
merged, processed, self._weave_name, time.time()-time0))
1038
def _imported_parents(self, other, other_idx):
1039
"""Return list of parents in self corresponding to indexes in other."""
1041
for parent_idx in other._parents[other_idx]:
1042
parent_name = other._names[parent_idx]
1043
if parent_name not in self._name_map:
1044
# should not be possible
1045
raise WeaveError("missing parent {%s} of {%s} in %r"
1046
% (parent_name, other._name_map[other_idx], self))
1047
new_parents.append(self._name_map[parent_name])
1050
def _check_version_consistent(self, other, other_idx, name):
1051
"""Check if a version in consistent in this and other.
1053
To be consistent it must have:
1056
* the same direct parents (by name, not index, and disregarding
1059
If present & correct return True;
1060
if not present in self return False;
1061
if inconsistent raise error."""
1062
this_idx = self._name_map.get(name, -1)
1064
if self._sha1s[this_idx] != other._sha1s[other_idx]:
1065
raise errors.WeaveTextDiffers(name, self, other)
1066
self_parents = self._parents[this_idx]
1067
other_parents = other._parents[other_idx]
1068
n1 = set([self._names[i] for i in self_parents])
1069
n2 = set([other._names[i] for i in other_parents])
1070
if not self._compatible_parents(n1, n2):
1071
raise WeaveParentMismatch("inconsistent parents "
1072
"for version {%s}: %s vs %s" % (name, n1, n2))
1078
@deprecated_method(zero_eight)
1079
def reweave(self, other, pb=None, msg=None):
1080
"""reweave has been superseded by plain use of join."""
1081
return self.join(other, pb, msg)
1083
def _reweave(self, other, pb, msg):
1084
"""Reweave self with other - internal helper for join().
1086
:param other: The other weave to merge
1087
:param pb: An optional progress bar, indicating how far done we are
1088
:param msg: An optional message for the progress
1090
new_weave = _reweave(self, other, pb=pb, msg=msg)
1091
self._copy_weave_content(new_weave)
1093
def _copy_weave_content(self, otherweave):
1094
"""adsorb the content from otherweave."""
1095
for attr in self.__slots__:
1096
if attr != '_weave_name':
1097
setattr(self, attr, copy(getattr(otherweave, attr)))
1100
class WeaveFile(Weave):
1101
"""A WeaveFile represents a Weave on disk and writes on change."""
1103
WEAVE_SUFFIX = '.weave'
1105
def __init__(self, name, transport, filemode=None, create=False, access_mode='w'):
1106
"""Create a WeaveFile.
1108
:param create: If not True, only open an existing knit.
1110
super(WeaveFile, self).__init__(name, access_mode)
1111
self._transport = transport
1112
self._filemode = filemode
1114
_read_weave_v5(self._transport.get(name + WeaveFile.WEAVE_SUFFIX), self)
1115
except errors.NoSuchFile:
1121
def _add_lines(self, version_id, parents, lines, parent_texts):
1122
"""Add a version and save the weave."""
1123
result = super(WeaveFile, self)._add_lines(version_id, parents, lines,
1128
def _clone_text(self, new_version_id, old_version_id, parents):
1129
"""See VersionedFile.clone_text."""
1130
super(WeaveFile, self)._clone_text(new_version_id, old_version_id, parents)
1133
def copy_to(self, name, transport):
1134
"""See VersionedFile.copy_to()."""
1135
# as we are all in memory always, just serialise to the new place.
1137
write_weave_v5(self, sio)
1139
transport.put_file(name + WeaveFile.WEAVE_SUFFIX, sio, self._filemode)
1141
def create_empty(self, name, transport, filemode=None):
1142
return WeaveFile(name, transport, filemode, create=True)
1145
"""Save the weave."""
1146
self._check_write_ok()
1148
write_weave_v5(self, sio)
1150
self._transport.put_file(self._weave_name + WeaveFile.WEAVE_SUFFIX,
1156
"""See VersionedFile.get_suffixes()."""
1157
return [WeaveFile.WEAVE_SUFFIX]
1159
def join(self, other, pb=None, msg=None, version_ids=None,
1160
ignore_missing=False):
1161
"""Join other into self and save."""
1162
super(WeaveFile, self).join(other, pb, msg, version_ids, ignore_missing)
1166
@deprecated_function(zero_eight)
1167
def reweave(wa, wb, pb=None, msg=None):
1168
"""reweaving is deprecation, please just use weave.join()."""
1169
_reweave(wa, wb, pb, msg)
1171
def _reweave(wa, wb, pb=None, msg=None):
1172
"""Combine two weaves and return the result.
1174
This works even if a revision R has different parents in
1175
wa and wb. In the resulting weave all the parents are given.
1177
This is done by just building up a new weave, maintaining ordering
1178
of the versions in the two inputs. More efficient approaches
1179
might be possible but it should only be necessary to do
1180
this operation rarely, when a new previously ghost version is
1183
:param pb: An optional progress bar, indicating how far done we are
1184
:param msg: An optional message for the progress
1188
queue_a = range(wa.num_versions())
1189
queue_b = range(wb.num_versions())
1190
# first determine combined parents of all versions
1191
# map from version name -> all parent names
1192
combined_parents = _reweave_parent_graphs(wa, wb)
1193
mutter("combined parents: %r", combined_parents)
1194
order = topo_sort(combined_parents.iteritems())
1195
mutter("order to reweave: %r", order)
1200
for idx, name in enumerate(order):
1202
pb.update(msg, idx, len(order))
1203
if name in wa._name_map:
1204
lines = wa.get_lines(name)
1205
if name in wb._name_map:
1206
lines_b = wb.get_lines(name)
1207
if lines != lines_b:
1208
mutter('Weaves differ on content. rev_id {%s}', name)
1209
mutter('weaves: %s, %s', wa._weave_name, wb._weave_name)
1211
lines = list(difflib.unified_diff(lines, lines_b,
1212
wa._weave_name, wb._weave_name))
1213
mutter('lines:\n%s', ''.join(lines))
1214
raise errors.WeaveTextDiffers(name, wa, wb)
1216
lines = wb.get_lines(name)
1217
wr._add(name, lines, [wr._lookup(i) for i in combined_parents[name]])
1220
def _reweave_parent_graphs(wa, wb):
1221
"""Return combined parent ancestry for two weaves.
1223
Returned as a list of (version_name, set(parent_names))"""
1225
for weave in [wa, wb]:
1226
for idx, name in enumerate(weave._names):
1227
p = combined.setdefault(name, set())
1228
p.update(map(weave._idx_to_name, weave._parents[idx]))
1233
"""Show the weave's table-of-contents"""
1234
print '%6s %50s %10s %10s' % ('ver', 'name', 'sha1', 'parents')
1235
for i in (6, 50, 10, 10):
533
def merge(self, merge_versions):
534
"""Automerge and mark conflicts between versions.
536
This returns a sequence, each entry describing alternatives
537
for a chunk of the file. Each of the alternatives is given as
540
If there is a chunk of the file where there's no diagreement,
541
only one alternative is given.
544
# approach: find the included versions common to all the
546
raise NotImplementedError()
550
def _delta(self, included, lines):
551
"""Return changes from basis to new revision.
553
The old text for comparison is the union of included revisions.
555
This is used in inserting a new text.
557
Delta is returned as a sequence of
558
(weave1, weave2, newlines).
560
This indicates that weave1:weave2 of the old weave should be
561
replaced by the sequence of lines in newlines. Note that
562
these line numbers are positions in the total weave and don't
563
correspond to the lines in any extracted version, or even the
564
extracted union of included versions.
566
If line1=line2, this is a pure insert; if newlines=[] this is a
567
pure delete. (Similar to difflib.)
572
def plan_merge(self, ver_a, ver_b):
573
"""Return pseudo-annotation indicating how the two versions merge.
575
This is computed between versions a and b and their common
578
Weave lines present in none of them are skipped entirely.
580
inc_a = self.inclusions([ver_a])
581
inc_b = self.inclusions([ver_b])
582
inc_c = inc_a & inc_b
584
for lineno, insert, deleteset, line in self._walk():
585
if deleteset & inc_c:
586
# killed in parent; can't be in either a or b
587
# not relevant to our work
588
yield 'killed-base', line
589
elif insert in inc_c:
590
# was inserted in base
591
killed_a = bool(deleteset & inc_a)
592
killed_b = bool(deleteset & inc_b)
593
if killed_a and killed_b:
594
yield 'killed-both', line
596
yield 'killed-a', line
598
yield 'killed-b', line
600
yield 'unchanged', line
601
elif insert in inc_a:
602
if deleteset & inc_a:
603
yield 'ghost-a', line
607
elif insert in inc_b:
608
if deleteset & inc_b:
609
yield 'ghost-b', line
613
# not in either revision
614
yield 'irrelevant', line
616
yield 'unchanged', '' # terminator
620
def weave_merge(self, plan):
625
for state, line in plan:
626
if state == 'unchanged' or state == 'killed-both':
627
# resync and flush queued conflicts changes if any
628
if not lines_a and not lines_b:
630
elif ch_a and not ch_b:
632
for l in lines_a: yield l
633
elif ch_b and not ch_a:
634
for l in lines_b: yield l
635
elif lines_a == lines_b:
636
for l in lines_a: yield l
639
for l in lines_a: yield l
641
for l in lines_b: yield l
648
if state == 'unchanged':
651
elif state == 'killed-a':
654
elif state == 'killed-b':
657
elif state == 'new-a':
660
elif state == 'new-b':
664
assert state in ('irrelevant', 'ghost-a', 'ghost-b', 'killed-base',
675
"""Show some text information about the weave."""
676
print '%6s %40s %20s' % ('ver', 'sha1', 'parents')
677
for i in (6, 40, 20):
1238
for i in range(w.num_versions()):
680
for i in range(w.numversions()):
1239
681
sha1 = w._sha1s[i]
1241
parent_str = ' '.join(map(str, w._parents[i]))
1242
print '%6d %-50.50s %10.10s %s' % (i, name, sha1, parent_str)
1246
def weave_stats(weave_file, pb):
682
print '%6d %40s %s' % (i, sha1, ' '.join(map(str, w._parents[i])))
686
def weave_stats(weave_file):
687
from bzrlib.progress import ProgressBar
1247
688
from bzrlib.weavefile import read_weave
1249
692
wf = file(weave_file, 'rb')
1250
693
w = read_weave(wf)
1251
694
# FIXME: doesn't work on pipes