~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to weave.py

  • Committer: Martin Pool
  • Date: 2005-06-28 09:21:30 UTC
  • mto: This revision was merged to the branch mainline in revision 852.
  • Revision ID: mbp@sourcefrog.net-20050628092130-b3b669cc920a7cdd
Basic parsing of delete instructions.

Check that they don't interfere with extracting revisions composed only of 
insertions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
215
215
 
216
216
        The set typically but not necessarily corresponds to a version.
217
217
        """
218
 
        istack = []
 
218
        istack = []          # versions for which an insertion block is current
 
219
 
 
220
        dset = set()         # versions for which a deletion block is current
 
221
 
219
222
        isactive = False
220
 
        lineno = 0
 
223
 
 
224
        lineno = 0         # line of weave, 0-based
221
225
        
222
226
        for l in self._l:
223
227
            if isinstance(l, tuple):
224
228
                c, v = l
225
229
                if c == '{':
226
 
                    if istack and (istack[-1][1] >= v):
 
230
                    if istack and (istack[-1] >= v):
227
231
                        raise WeaveFormatError("improperly nested insertions %d>=%d on line %d" 
228
 
                                               % (istack[-1][1], v, lineno))
229
 
                    istack.append(l)
230
 
                    isactive = (v in included)
 
232
                                               % (istack[-1], v, lineno))
 
233
                    istack.append(v)
231
234
                elif c == '}':
232
 
                    oldc, oldv = istack.pop()
233
 
                    assert oldc == '{'
234
 
                    assert oldv == v
235
 
                    isactive = istack and (istack[-1][1] in included)
 
235
                    try:
 
236
                        oldv = istack.pop()
 
237
                    except IndexError:
 
238
                        raise WeaveFormatError("unmatched close of insertion %d on line %d"
 
239
                                               % (v, lineno))
 
240
                    if oldv != v:
 
241
                        raise WeaveFormatError("mismatched close of insertion %d!=%d on line %d"
 
242
                                               % (oldv, v, lineno))
 
243
                elif c == '[':
 
244
                    # block deleted in v
 
245
                    if v in dset:
 
246
                        raise WeaveFormatError("repeated deletion marker for version %d on line %d"
 
247
                                               % (v, lineno))
 
248
                    else:
 
249
                        dset.add(v)
 
250
                elif c == ']':
 
251
                    if v in dset:
 
252
                        dset.remove(v)
 
253
                    else:
 
254
                        raise WeaveFormatError("unmatched close of deletion %d on line %d"
 
255
                                               % (v, lineno))
236
256
                else:
237
257
                    raise WeaveFormatError("invalid processing instruction %r on line %d"
238
258
                                           % (l, lineno))
241
261
                if not istack:
242
262
                    raise WeaveFormatError("literal at top level on line %d"
243
263
                                           % lineno)
 
264
                isactive = istack[-1] in included
244
265
                if isactive:
245
 
                    origin = istack[-1][1]
 
266
                    origin = istack[-1]
246
267
                    yield origin, lineno, l
247
268
            lineno += 1
248
269
 
249
270
        if istack:
250
271
            raise WeaveFormatError("unclosed insertion blocks at end of weave",
251
272
                                   istack)
 
273
        if dset:
 
274
            raise WeaveFormatError("unclosed deletion blocks at end of weave",
 
275
                                   dset)
252
276
 
253
277
 
254
278
    def getiter(self, index):