~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:31:58 UTC
  • mto: This revision was merged to the branch mainline in revision 852.
  • Revision ID: mbp@sourcefrog.net-20050627033158-c86b5bf3deda0f47
Knit structure now allows for versions to include the lines present in other 
versions.  (Not applied transitively for the moment.)  This is applied when 
unpacking texts.

Start adding Knit.check()

Hand-pack a knit and check that included versions are respected when 
unpacking lines.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
        is present in the version equal to index-id.
33
33
 
34
34
    _v
35
 
        List of versions, indexed by index number.  Each one is an empty
36
 
        tuple because the version_id isn't stored yet.
 
35
        List of versions, indexed by index number.
 
36
 
 
37
        For each version we store the tuple (included_versions), which
 
38
        lists the previous versions also considered active.
37
39
    """
38
40
    def __init__(self):
39
41
        self._l = []
53
55
        for line in text:
54
56
            self._l.append((idx, line))
55
57
 
56
 
        self._v.append(())
 
58
        included = ()
 
59
        vers_info = (included,)
 
60
        self._v.append(vers_info)
57
61
        return idx
58
62
 
59
63
    
65
69
        """Yield list of (index-id, line) pairs for the specified version.
66
70
 
67
71
        The index indicates when the line originated in the weave."""
68
 
        self._v[index]                  # check index is valid
 
72
        vers_info = self._v[index]
 
73
 
 
74
        included = set(vers_info[0])
 
75
        included.add(index)
69
76
 
70
77
        for origin, line in self._l:
71
 
            if origin == index:
 
78
            if origin in included:
72
79
                yield origin, line
73
80
 
74
81
 
88
95
        pprint(self._l, to_file)
89
96
 
90
97
 
 
98
    def check(self):
 
99
        for vers_info in self._v:
 
100
            included = set()
 
101
            for vi in vers_info[0]:
 
102
                if vi < 0 or vi >= index:
 
103
                    raise ValueError("invalid included_version %d for index %d"
 
104
                                     % (vi, index))
 
105
                if vi in included:
 
106
                    raise ValueError("repeated included_version %d for index %d"
 
107
                                     % (vi, index))
 
108
                included.add(vi)
 
109
            
 
110
 
 
111
 
91
112
 
92
113
def update_knit(knit, new_vers, new_lines):
93
114
    """Return a new knit whose text matches new_lines.