~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge3.py

  • Committer: Martin Pool
  • Date: 2008-04-24 07:22:53 UTC
  • mto: This revision was merged to the branch mainline in revision 3415.
  • Revision ID: mbp@sourcefrog.net-20080424072253-opmjij7xfy38w27f
Remove every assert statement from bzrlib!

Depending on the context they are:

 * turned into an explicit if/raise of either AssertionError 
   or something more specific -- particularly where they protect
   programming interfaces, complex invariants, or data file integrity
 * removed, if they're redundant with a later check, not protecting
   a meaningful invariant
 * turned into a selftest method on tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    >>> intersect((0, 9), (7, 15))
37
37
    (7, 9)
38
38
    """
39
 
    assert ra[0] <= ra[1]
40
 
    assert rb[0] <= rb[1]
41
 
    
42
39
    sa = max(ra[0], rb[0])
43
40
    sb = min(ra[1], rb[1])
44
41
    if sa < sb:
222
219
        iz = ia = ib = 0
223
220
        
224
221
        for zmatch, zend, amatch, aend, bmatch, bend in self.find_sync_regions():
225
 
            #print 'match base [%d:%d]' % (zmatch, zend)
226
 
            
227
222
            matchlen = zend - zmatch
228
 
            assert matchlen >= 0
229
 
            assert matchlen == (aend - amatch)
230
 
            assert matchlen == (bend - bmatch)
231
 
            
232
223
            len_a = amatch - ia
233
224
            len_b = bmatch - ib
234
225
            len_base = zmatch - iz
235
 
            assert len_a >= 0
236
 
            assert len_b >= 0
237
 
            assert len_base >= 0
238
 
 
239
226
            #print 'unmatched a=%d, b=%d' % (len_a, len_b)
240
227
 
241
228
            if len_a or len_b:
273
260
            # that's OK, we can just skip it.
274
261
 
275
262
            if matchlen > 0:
276
 
                assert ia == amatch
277
 
                assert ib == bmatch
278
 
                assert iz == zmatch
279
 
                
280
263
                yield 'unchanged', zmatch, zend
281
264
                iz = zend
282
265
                ia = aend
386
369
                intbase = i[0]
387
370
                intend = i[1]
388
371
                intlen = intend - intbase
389
 
 
390
 
                # found a match of base[i[0], i[1]]; this may be less than
391
 
                # the region that matches in either one
392
 
                assert intlen <= alen
393
 
                assert intlen <= blen
394
 
                assert abase <= intbase
395
 
                assert bbase <= intbase
396
 
 
397
372
                asub = amatch + (intbase - abase)
398
373
                bsub = bmatch + (intbase - bbase)
399
374
                aend = asub + intlen
400
375
                bend = bsub + intlen
401
 
 
402
 
                assert self.base[intbase:intend] == self.a[asub:aend], \
403
 
                       (self.base[intbase:intend], self.a[asub:aend])
404
 
 
405
 
                assert self.base[intbase:intend] == self.b[bsub:bend]
406
 
 
407
376
                sl.append((intbase, intend,
408
377
                           asub, aend,
409
378
                           bsub, bend))
410
 
 
411
379
            # advance whichever one ends first in the base text
412
380
            if (abase + alen) < (bbase + blen):
413
381
                ia += 1