529
533
print >>out, "versions total %d bytes" % total
530
534
print >>out, "compression ratio %.3f" % (float(total)/float(weave_size))
538
print """bzr weave tool:
541
Create an empty weave file
542
weave get WEAVEFILE VERSION
543
Write out specified version.
544
weave check WEAVEFILE
545
Check consistency of all versions.
547
Display table of contents.
548
weave add WEAVEFILE [BASE...] < NEWTEXT
549
Add NEWTEXT, with specified parent versions.
550
weave annotate WEAVEFILE VERSION
551
Display origin of each line.
552
weave mash WEAVEFILE VERSION...
553
Display composite of all selected versions.
554
weave merge WEAVEFILE VERSION1 VERSION2 > OUT
555
Auto-merge two versions and display conflicts.
537
from weavefile import write_weave_v1, read_weave
563
from weavefile import write_weave, read_weave
540
w = read_weave(file(argv[2], 'rb'))
567
return read_weave(file(argv[2], 'rb'))
541
573
# at the moment, based on everything in the file
542
parents = set(range(len(w._v)))
574
parents = map(int, argv[3:])
543
575
lines = sys.stdin.readlines()
544
576
ver = w.add(parents, lines)
545
write_weave_v1(w, file(argv[2], 'wb'))
546
print 'added %d' % ver
577
write_weave(w, file(argv[2], 'wb'))
578
print 'added version %d' % ver
547
579
elif cmd == 'init':
549
581
if os.path.exists(fn):
550
582
raise IOError("file exists")
552
write_weave_v1(w, file(fn, 'wb'))
554
w = read_weave(file(argv[2], 'rb'))
584
write_weave(w, file(fn, 'wb'))
585
elif cmd == 'get': # get one version
555
587
sys.stdout.writelines(w.get_iter(int(argv[3])))
589
elif cmd == 'mash': # get composite
591
sys.stdout.writelines(w.mash_iter(map(int, argv[3:])))
556
593
elif cmd == 'annotate':
557
w = read_weave(file(argv[2], 'rb'))
558
595
# newline is added to all lines regardless; too hard to get
559
596
# reasonable formatting otherwise