7
7
# Author: Martin Pool <mbp@canonical.com>
10
"""knit - a weave-like structure
12
A Knit manages versions of line-based text files, keeping track of the
13
originating version for each line.
15
Versions are referenced by nonnegative integers. In a full system
16
this will be just a local shorthand for some universally-unique
19
Texts are represented as a seqence of (version, text, live) tuples.
20
An empty sequence represents an empty text. The version is the
21
version in which the line was introduced. The *live* flag is false if
22
the line is no longer present and being tracked only for the purposes
10
"""knit - a weave-like structure"""
14
"""knit - versioned text file storage.
16
A Knit manages versions of line-based text files, keeping track of the
17
originating version for each line.
19
Versions are referenced by nonnegative integers. In a full system
20
this will be just a local shorthand for some universally-unique
23
Texts are represented as a seqence of (version, text, live) tuples.
24
An empty sequence represents an empty text. The version is the
25
version in which the line was introduced. The *live* flag is false if
26
the line is no longer present and being tracked only for the purposes
30
Stores the actual weave.
34
"""Add a single text on top of the weave."""
35
if not isinstance(text, list):
36
raise ValueError("text should be a list, not %s" % type(text))
27
44
text1 = [(0, "hello world", True)]
88
print '***** annotated:'
91
print '***** plain text:'
92
print '\n'.join(knit2text(knit2))
94
text3 = """hello world
96
hello boys""".split('\n')
98
print repr(knit2text(knit2))
100
knit3 = update_knit(knit2, 3, text3)
102
print '***** result of update:'
103
show_annotated(knit3)
105
print '***** annotated:'
106
show_annotated(knit2)
108
print '***** plain text:'
109
print '\n'.join(knit2text(knit2))
111
text3 = """hello world
113
hello boys""".split('\n')
115
print repr(knit2text(knit2))
117
knit3 = update_knit(knit2, 3, text3)
119
print '***** result of update:'
120
show_annotated(knit3)