~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/weavefile.py

  • Committer: Martin Pool
  • Date: 2005-08-18 07:11:44 UTC
  • Revision ID: mbp@sourcefrog.net-20050818071144-ac563170b231e8e1
- if weave tool is invoked with no arguments, show help

- rename weave command from 'info' to 'toc'
  (because it's kind of nerdy information)

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
There is one format marker followed by a blank line, followed by a
27
27
series of version headers, followed by the weave itself.
28
28
 
29
 
Each version marker has
30
 
 
31
 
 'i'   parent version indexes
32
 
 '1'   SHA-1 of text
33
 
 'n'   name
34
 
 
35
 
The inclusions do not need to list versions included by a parent.
 
29
Each version marker has 'i' and the included previous versions, then
 
30
'1' and the SHA-1 of the text, if known.  The inclusions do not need
 
31
to list versions included by a parent.
36
32
 
37
33
The weave is bracketed by 'w' and 'W' lines, and includes the '{}[]'
38
34
processing instructions.  Lines of text are prefixed by '.' if the
43
39
# an iterator returning the weave lines...  We don't really need to
44
40
# deserialize it into memory.
45
41
 
46
 
FORMAT_1 = '# bzr weave file v5\n'
 
42
FORMAT_1 = '# bzr weave file v4\n'
47
43
 
48
44
 
49
45
def write_weave(weave, f, format=None):
50
46
    if format == None or format == 1:
51
 
        return write_weave_v5(weave, f)
 
47
        return write_weave_v4(weave, f)
52
48
    else:
53
49
        raise ValueError("unknown weave format %r" % format)
54
50
 
55
51
 
56
 
def write_weave_v5(weave, f):
 
52
def write_weave_v4(weave, f):
57
53
    """Write weave to file f."""
58
54
    print >>f, FORMAT_1,
59
55
 
68
64
        else:
69
65
            print >>f, 'i'
70
66
        print >>f, '1', weave._sha1s[version]
71
 
        print >>f, 'n', weave._names[version]
72
67
        print >>f
73
68
 
74
69
    print >>f, 'w'
95
90
 
96
91
 
97
92
def read_weave(f):
98
 
    return read_weave_v5(f)
99
 
 
100
 
 
101
 
def read_weave_v5(f):
 
93
    return read_weave_v4(f)
 
94
 
 
95
 
 
96
def read_weave_v4(f):
102
97
    from weave import Weave, WeaveFormatError
103
98
    w = Weave()
104
99
 
111
106
    while True:
112
107
        l = f.readline()
113
108
        if l[0] == 'i':
 
109
            ver += 1
 
110
 
114
111
            if len(l) > 2:
115
112
                w._parents.append(map(int, l[2:].split(' ')))
116
113
            else:
121
118
            w._sha1s.append(l[2:])
122
119
                
123
120
            l = f.readline()
124
 
            assert l.startswith('n ')
125
 
            name = l[2:-1]
126
 
            assert name not in w._name_map
127
 
            w._names.append(name)
128
 
            w._name_map[name] = ver
129
 
                
130
 
            l = f.readline()
131
121
            assert l == '\n'
132
 
 
133
 
            ver += 1
134
122
        elif l == 'w\n':
135
123
            break
136
124
        else: