~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/weave.py

  • Committer: Martin Pool
  • Date: 2005-07-18 16:03:21 UTC
  • Revision ID: mbp@sourcefrog.net-20050718160321-58c34462be5cb9a7
- weave info only shows the weave headers, doesn't extract every version:
  much faster

- add len(Weave) operator

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
 
 
80
74
# TODO: Parallel-extract that passes back each line along with a
81
75
# description of which revisions include it.  Nice for checking all
82
76
# shas in parallel.
498
492
        return l
499
493
 
500
494
 
 
495
    def __len__(self):
 
496
        return self.numversions()
 
497
 
 
498
 
501
499
    def check(self, progress_bar=None):
502
500
        # check no circular inclusions
503
501
        for version in range(self.numversions()):
672
670
 
673
671
 
674
672
 
675
 
def weave_info(filename, out):
 
673
def weave_info(w):
676
674
    """Show some text information about the weave."""
677
 
    from weavefile import read_weave
678
 
    wf = file(filename, 'rb')
679
 
    w = read_weave(wf)
680
 
    # FIXME: doesn't work on pipes
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)
684
 
 
685
 
    total = 0
686
 
    print '%6s %6s %8s %40s %20s' % ('ver', 'lines', 'bytes', 'sha1', 'parents')
687
 
    for i in (6, 6, 8, 40, 20):
 
675
    print '%6s %40s %20s' % ('ver', 'sha1', 'parents')
 
676
    for i in (6, 40, 20):
688
677
        print '-' * i,
689
678
    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))
 
679
    for i in range(w.numversions()):
694
680
        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
 
681
        print '%6d %40s %s' % (i, sha1, ' '.join(map(str, w._parents[i])))
700
682
 
701
 
    print >>out, "versions total %d bytes" % total
702
 
    print >>out, "compression ratio %.3f" % (float(total)/float(weave_size))
703
683
 
704
684
 
705
685
def usage():
803
783
                lasto = origin
804
784
                
805
785
    elif cmd == 'info':
806
 
        weave_info(argv[2], sys.stdout)
 
786
        weave_info(readit())
807
787
        
808
788
    elif cmd == 'check':
809
789
        w = readit()