/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/weave.py

  • Committer: Martin Pool
  • Date: 2005-07-18 14:28:13 UTC
  • Revision ID: mbp@sourcefrog.net-20050718142813-253ec02b9636bd98
- add stubbed-out test for clashing replace and delete

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
# properly nested, that there is no text outside of an insertion, that
72
72
# insertions or deletions are not repeated, etc.
73
73
 
 
74
# TODO: Make the info command just show info, not extract everything:
 
75
# it can be much faster.
 
76
 
 
77
# TODO: Perhaps use long integers as sets instead of set objects; may
 
78
# be faster.
 
79
 
74
80
# TODO: Parallel-extract that passes back each line along with a
75
81
# description of which revisions include it.  Nice for checking all
76
82
# shas in parallel.
492
498
        return l
493
499
 
494
500
 
495
 
    def __len__(self):
496
 
        return self.numversions()
497
 
 
498
 
 
499
501
    def check(self, progress_bar=None):
500
502
        # check no circular inclusions
501
503
        for version in range(self.numversions()):
670
672
 
671
673
 
672
674
 
673
 
def weave_info(w):
 
675
def weave_info(filename, out):
674
676
    """Show some text information about the weave."""
675
 
    print '%6s %40s %20s' % ('ver', 'sha1', 'parents')
676
 
    for i in (6, 40, 20):
677
 
        print '-' * i,
678
 
    print
679
 
    for i in range(w.numversions()):
680
 
        sha1 = w._sha1s[i]
681
 
        print '%6d %40s %s' % (i, sha1, ' '.join(map(str, w._parents[i])))
682
 
 
683
 
 
684
 
 
685
 
def weave_stats(weave_file):
686
 
    from bzrlib.progress import ProgressBar
687
 
    from bzrlib.weavefile import read_weave
688
 
 
689
 
    pb = ProgressBar()
690
 
 
691
 
    wf = file(weave_file, 'rb')
 
677
    from weavefile import read_weave
 
678
    wf = file(filename, 'rb')
692
679
    w = read_weave(wf)
693
680
    # FIXME: doesn't work on pipes
694
681
    weave_size = wf.tell()
 
682
    print >>out, "weave file size %d bytes" % weave_size
 
683
    print >>out, "weave contains %d versions" % len(w._parents)
695
684
 
696
685
    total = 0
697
 
    vers = len(w)
698
 
    for i in range(vers):
699
 
        pb.update('checking sizes', i, vers)
700
 
        for line in w.get_iter(i):
701
 
            total += len(line)
702
 
 
703
 
    pb.clear()
704
 
 
705
 
    print 'versions          %9d' % vers
706
 
    print 'weave file        %9d bytes' % weave_size
707
 
    print 'total contents    %9d bytes' % total
708
 
    print 'compression ratio %9.2fx' % (float(total) / float(weave_size))
709
 
 
 
686
    print '%6s %6s %8s %40s %20s' % ('ver', 'lines', 'bytes', 'sha1', 'parents')
 
687
    for i in (6, 6, 8, 40, 20):
 
688
        print '-' * i,
 
689
    print
 
690
    for i in range(len(w._parents)):
 
691
        text = w.get(i)
 
692
        lines = len(text)
 
693
        bytes = sum((len(a) for a in text))
 
694
        sha1 = w._sha1s[i]
 
695
        print '%6d %6d %8d %40s' % (i, lines, bytes, sha1),
 
696
        for pv in w._parents[i]:
 
697
            print pv,
 
698
        print
 
699
        total += bytes
 
700
 
 
701
    print >>out, "versions total %d bytes" % total
 
702
    print >>out, "compression ratio %.3f" % (float(total)/float(weave_size))
710
703
 
711
704
 
712
705
def usage():
810
803
                lasto = origin
811
804
                
812
805
    elif cmd == 'info':
813
 
        weave_info(readit())
814
 
 
815
 
    elif cmd == 'stats':
816
 
        weave_stats(argv[2])
 
806
        weave_info(argv[2], sys.stdout)
817
807
        
818
808
    elif cmd == 'check':
819
809
        w = readit()