~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/weave.py

  • Committer: Martin Pool
  • Date: 2005-07-17 18:06:53 UTC
  • Revision ID: mbp@sourcefrog.net-20050717180653-f16d08bd74610f6d
- update more weave code to use intsets

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
 
57
57
 
58
58
 
59
 
 
60
 
try:
61
 
    set
62
 
    frozenset
63
 
except NameError:
64
 
    from sets import Set, ImmutableSet
65
 
    set = Set
66
 
    frozenset = ImmutableSet
67
 
    del Set, ImmutableSet
 
59
from bzrlib.intset import IntSet
68
60
 
69
61
 
70
62
 
241
233
        return idx
242
234
 
243
235
 
244
 
    def inclusions_bitset(self, versions):
245
 
        i = 0
246
 
        for v in versions:
247
 
            i |= (1L << v)
248
 
        v = max(versions)
249
 
        while v >= 0:
250
 
            if i & (1L << v):
251
 
                # if v is included, include all its parents
252
 
                for pv in self._v[v]:
253
 
                    i |= (1L << pv)
254
 
            v -= 1
255
 
        return i
256
 
 
257
 
 
258
236
    def inclusions(self, versions):
259
237
        """Return set of all ancestors of given version(s)."""
260
 
        from bzrlib.intset import IntSet
261
 
        
262
238
        i = IntSet(versions)
263
239
        v = max(versions)
264
240
        try:
274
250
 
275
251
    def minimal_parents(self, version):
276
252
        """Find the minimal set of parents for the version."""
277
 
        from bzrlib.intset import IntSet
278
 
        
279
253
        included = self._v[version]
280
254
        if not included:
281
255
            return []
300
274
        if parents:
301
275
            self._v.append(parents)
302
276
        else:
303
 
            self._v.append(frozenset())
 
277
            self._v.append(IntSet())
304
278
 
305
279
 
306
280
    def _check_lines(self, text):
344
318
        """
345
319
        
346
320
        istack = []
347
 
        dset = 0L
 
321
        dset = IntSet()
348
322
 
349
323
        lineno = 0         # line of weave, 0-based
350
324
 
357
331
                elif c == '}':
358
332
                    oldv = istack.pop()
359
333
                elif c == '[':
360
 
                    vs = (1L << v)
361
 
                    assert not (dset & vs)
362
 
                    dset |= vs
 
334
                    assert v not in dset
 
335
                    dset.add(v)
363
336
                elif c == ']':
364
 
                    vs = (1L << v)
365
 
                    assert dset & vs
366
 
                    dset ^= vs
 
337
                    dset.remove(v)
367
338
                else:
368
339
                    raise WeaveFormatError('unexpected instruction %r'
369
340
                                           % v)
387
358
        included = self.inclusions(versions)
388
359
 
389
360
        istack = []
390
 
        dset = set()
 
361
        dset = IntSet()
391
362
 
392
363
        lineno = 0         # line of weave, 0-based
393
364
 
442
413
 
443
414
    def mash_iter(self, included):
444
415
        """Return composed version of multiple included versions."""
445
 
        included = frozenset(included)
446
416
        for origin, lineno, text in self._extract(included):
447
417
            yield text
448
418
 
577
547
 
578
548
        Weave lines present in none of them are skipped entirely.
579
549
        """
580
 
        inc_a = self.inclusions_bitset([ver_a])
581
 
        inc_b = self.inclusions_bitset([ver_b])
 
550
        inc_a = self.inclusions([ver_a])
 
551
        inc_b = self.inclusions([ver_b])
582
552
        inc_c = inc_a & inc_b
583
553
 
584
554
        for lineno, insert, deleteset, line in self._walk():
585
 
            insertset = (1L << insert)
586
555
            if deleteset & inc_c:
587
556
                # killed in parent; can't be in either a or b
588
557
                # not relevant to our work
589
558
                yield 'killed-base', line
590
 
            elif insertset & inc_c:
 
559
            elif insert in inc_c:
591
560
                # was inserted in base
592
561
                killed_a = bool(deleteset & inc_a)
593
562
                killed_b = bool(deleteset & inc_b)
599
568
                    yield 'killed-b', line
600
569
                else:
601
570
                    yield 'unchanged', line
602
 
            elif insertset & inc_a:
 
571
            elif insert in inc_a:
603
572
                if deleteset & inc_a:
604
573
                    yield 'ghost-a', line
605
574
                else:
606
575
                    # new in A; not in B
607
576
                    yield 'new-a', line
608
 
            elif insertset & inc_b:
 
577
            elif insert in inc_b:
609
578
                if deleteset & inc_b:
610
579
                    yield 'ghost-b', line
611
580
                else: