~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to weave.py

  • Committer: Martin Pool
  • Date: 2005-06-30 07:58:00 UTC
  • mto: This revision was merged to the branch mainline in revision 852.
  • Revision ID: mbp@sourcefrog.net-20050630075800-9af4341e177e121a
Remove VerInfo class; just store sets directly in the list of  
versions.

Add tests for serialize/deserialize.

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
    del Set, ImmutableSet
62
62
 
63
63
 
64
 
class VerInfo(object):
65
 
    """Information about a version in a Weave."""
66
 
    included = frozenset()
67
 
    def __init__(self, included=None):
68
 
        if included:
69
 
            self.included = frozenset(included)
70
 
 
71
 
    def __repr__(self):
72
 
        s = self.__class__.__name__ + '('
73
 
        if self.included:
74
 
            s += 'included=%r' % (list(self.included))
75
 
        s += ')'
76
 
        return s
77
 
 
78
 
 
79
64
class WeaveError(Exception):
80
65
    """Exception in processing weave"""
81
66
 
223
208
                                   + [('}', idx)]
224
209
                    offset += 2 + len(newlines)
225
210
 
226
 
            self._v.append(VerInfo(parents))
 
211
            self._addversion(parents)
227
212
        else:
228
213
            # special case; adding with no parents revision; can do this
229
214
            # more quickly by just appending unconditionally
231
216
            self._l += text
232
217
            self._l.append(('}', idx))
233
218
 
234
 
            self._v.append(VerInfo())
 
219
            self._addversion(None)
235
220
            
236
221
        return idx
237
222
 
238
223
 
 
224
    def _addversion(self, parents):
 
225
        if parents:
 
226
            self._v.append(frozenset(parents))
 
227
        else:
 
228
            self._v.append(frozenset())
 
229
 
 
230
 
239
231
    def _check_lines(self, text):
240
232
        if not isinstance(text, list):
241
233
            raise ValueError("text should be a list, not %s" % type(text))
267
259
            vi = self._v[index]
268
260
        except IndexError:
269
261
            raise IndexError('version index %d out of range' % index)
270
 
        included = set(vi.included)
 
262
        included = set(vi)
271
263
        included.add(index)
272
264
        for origin, lineno, text in self._extract(included):
273
265
            yield origin, text