1036
1034
p = combined.setdefault(name, set())
1037
1035
p.update(map(weave._idx_to_name, weave._parents[idx]))
1038
1036
return combined
1042
"""Show the weave's table-of-contents"""
1043
print '%6s %50s %10s %10s' % ('ver', 'name', 'sha1', 'parents')
1044
for i in (6, 50, 10, 10):
1047
for i in range(w.num_versions()):
1050
parent_str = ' '.join(map(str, w._parents[i]))
1051
print '%6d %-50.50s %10.10s %s' % (i, name, sha1, parent_str)
1055
def weave_stats(weave_file, pb):
1056
from bzrlib.weavefile import read_weave
1058
wf = file(weave_file, 'rb')
1060
# FIXME: doesn't work on pipes
1061
weave_size = wf.tell()
1065
for i in range(vers):
1066
pb.update('checking sizes', i, vers)
1067
for origin, lineno, line in w._extract([i]):
1072
print 'versions %9d' % vers
1073
print 'weave file %9d bytes' % weave_size
1074
print 'total contents %9d bytes' % total
1075
print 'compression ratio %9.2fx' % (float(total) / float(weave_size))
1078
print 'average size %9d bytes' % avg
1079
print 'relative size %9.2fx' % (float(weave_size) / float(avg))
1083
print """bzr weave tool
1085
Experimental tool for weave algorithm.
1088
weave init WEAVEFILE
1089
Create an empty weave file
1090
weave get WEAVEFILE VERSION
1091
Write out specified version.
1092
weave check WEAVEFILE
1093
Check consistency of all versions.
1095
Display table of contents.
1096
weave add WEAVEFILE NAME [BASE...] < NEWTEXT
1097
Add NEWTEXT, with specified parent versions.
1098
weave annotate WEAVEFILE VERSION
1099
Display origin of each line.
1100
weave merge WEAVEFILE VERSION1 VERSION2 > OUT
1101
Auto-merge two versions and display conflicts.
1102
weave diff WEAVEFILE VERSION1 VERSION2
1103
Show differences between two versions.
1107
% weave init foo.weave
1109
% weave add foo.weave ver0 < foo.txt
1112
(create updated version)
1114
% weave get foo.weave 0 | diff -u - foo.txt
1115
% weave add foo.weave ver1 0 < foo.txt
1118
% weave get foo.weave 0 > foo.txt (create forked version)
1120
% weave add foo.weave ver2 0 < foo.txt
1123
% weave merge foo.weave 1 2 > foo.txt (merge them)
1124
% vi foo.txt (resolve conflicts)
1125
% weave add foo.weave merged 1 2 < foo.txt (commit merged version)
1137
# in case we're run directly from the subdirectory
1138
sys.path.append('..')
1140
from bzrlib.weavefile import write_weave, read_weave
1141
from bzrlib.progress import ProgressBar
1156
return read_weave(file(argv[2], 'rb'))
1162
# at the moment, based on everything in the file
1164
parents = map(int, argv[4:])
1165
lines = sys.stdin.readlines()
1166
ver = w.add(name, parents, lines)
1167
write_weave(w, file(argv[2], 'wb'))
1168
print 'added version %r %d' % (name, ver)
1171
if os.path.exists(fn):
1172
raise IOError("file exists")
1174
write_weave(w, file(fn, 'wb'))
1175
elif cmd == 'get': # get one version
1177
sys.stdout.writelines(w.get_iter(int(argv[3])))
1182
v1, v2 = map(int, argv[3:5])
1185
diff_gen = bzrlib.patiencediff.unified_diff(lines1, lines2,
1186
'%s version %d' % (fn, v1),
1187
'%s version %d' % (fn, v2))
1188
sys.stdout.writelines(diff_gen)
1190
elif cmd == 'annotate':
1192
# newline is added to all lines regardless; too hard to get
1193
# reasonable formatting otherwise
1195
for origin, text in w.annotate(int(argv[3])):
1196
text = text.rstrip('\r\n')
1198
print ' | %s' % (text)
1200
print '%5d | %s' % (origin, text)
1206
elif cmd == 'stats':
1207
weave_stats(argv[2], ProgressBar())
1209
elif cmd == 'check':
1214
print '%d versions ok' % w.num_versions()
1216
elif cmd == 'inclusions':
1218
print ' '.join(map(str, w.inclusions([int(argv[3])])))
1220
elif cmd == 'parents':
1222
print ' '.join(map(str, w._parents[int(argv[3])]))
1224
elif cmd == 'plan-merge':
1225
# replaced by 'bzr weave-plan-merge'
1227
for state, line in w.plan_merge(int(argv[3]), int(argv[4])):
1229
print '%14s | %s' % (state, line),
1230
elif cmd == 'merge':
1231
# replaced by 'bzr weave-merge-text'
1233
p = w.plan_merge(int(argv[3]), int(argv[4]))
1234
sys.stdout.writelines(w.weave_merge(p))
1236
raise ValueError('unknown command %r' % cmd)
1239
if __name__ == '__main__':
1241
sys.exit(main(sys.argv))