~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to knit.py

  • Committer: Martin Pool
  • Date: 2005-06-27 03:03:00 UTC
  • mto: This revision was merged to the branch mainline in revision 852.
  • Revision ID: mbp@sourcefrog.net-20050627030300-19f4ca68fded6702
Add test for storing two text versions.

Store texts as (index, line) pairs, where versions include only a 
single index.  Filter out active lines from get method.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    the version-id is used to reference it in the larger world.
27
27
 
28
28
    _l
29
 
        List of lines.
 
29
        List of edit instructions.
 
30
 
 
31
        Each line is stored as a tuple of (index-id, text).  The line
 
32
        is present in the version equal to index-id.
30
33
 
31
34
    _v
32
35
        List of versions, indexed by index number.  Each one is an empty
33
 
        tuple.
 
36
        tuple because the version_id isn't stored yet.
34
37
    """
35
38
    def __init__(self):
36
39
        self._l = []
37
40
        self._v = []
 
41
 
38
42
        
39
43
    def add(self, text):
40
44
        """Add a single text on top of the weave.
44
48
            raise ValueError("text should be a list, not %s" % type(text))
45
49
 
46
50
        idx = len(self._v)
47
 
        self._l = text
 
51
 
 
52
        # all of the previous texts are turned off; just append lines at the bottom
 
53
        for line in text:
 
54
            self._l.append((idx, line))
 
55
 
48
56
        self._v.append(())
49
57
        return idx
50
58
 
51
59
    
 
60
    def getiter(self, index):
 
61
        """Yield lines for the specified version."""
 
62
        self._v[index]                  # check index is valid
 
63
 
 
64
        for idx, line in self._l:
 
65
            if idx == index:
 
66
                yield line
 
67
 
 
68
 
52
69
    def get(self, index):
53
 
        self._v[index]                  # check index is valid
54
 
        
55
 
        return self._l[:]
 
70
        return list(self.getiter(index))
56
71
 
57
72
 
58
73
text1 = [(0, "hello world", True)]