/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-09-02 23:36:06 UTC
  • mfrom: (2770.1.10 pack-annotate)
  • Revision ID: pqm@pqm.ubuntu.com-20070902233606-wb062d366w5c83uc
Support annotating knits with no annotation cache

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
from bzrlib.lazy_import import lazy_import
75
75
lazy_import(globals(), """
76
76
from bzrlib import (
 
77
    annotate,
77
78
    pack,
78
79
    trace,
79
80
    )
290
291
                       for origin, text in lines)
291
292
        return out
292
293
 
 
294
    def annotate_iter(self, knit, version_id):
 
295
        content = knit._get_content(version_id)
 
296
        return content.annotate_iter()
 
297
 
293
298
 
294
299
class KnitPlainFactory(_KnitFactory):
295
300
    """Factory for creating plain Content objects."""
345
350
            out.extend([text for origin, text in lines])
346
351
        return out
347
352
 
 
353
    def annotate_iter(self, knit, version_id):
 
354
        return annotate_knit(knit, version_id)
 
355
 
348
356
 
349
357
def make_empty_knit(transport, relpath):
350
358
    """Construct a empty knit at the specified location."""
1107
1115
    def annotate_iter(self, version_id):
1108
1116
        """See VersionedFile.annotate_iter."""
1109
1117
        version_id = osutils.safe_revision_id(version_id)
1110
 
        content = self._get_content(version_id)
1111
 
        for origin, text in content.annotate_iter():
1112
 
            yield origin, text
 
1118
        return self.factory.annotate_iter(self, version_id)
1113
1119
 
1114
1120
    def get_parents(self, version_id):
1115
1121
        """See VersionedFile.get_parents."""
2522
2528
        return besti, bestj, bestsize
2523
2529
 
2524
2530
 
 
2531
def annotate_knit(knit, revision_id):
 
2532
    """Annotate a knit with no cached annotations.
 
2533
 
 
2534
    This implementation is for knits with no cached annotations.
 
2535
    It will work for knits with cached annotations, but this is not
 
2536
    recommended.
 
2537
    """
 
2538
    ancestry = knit.get_ancestry(revision_id)
 
2539
    fulltext = dict(zip(ancestry, knit.get_line_list(ancestry)))
 
2540
    annotations = {}
 
2541
    for candidate in ancestry:
 
2542
        if candidate in annotations:
 
2543
            continue
 
2544
        parents = knit.get_parents(candidate)
 
2545
        if len(parents) == 0:
 
2546
            blocks = None
 
2547
        elif knit._index.get_method(candidate) != 'line-delta':
 
2548
            blocks = None
 
2549
        else:
 
2550
            parent, sha1, noeol, delta = knit.get_delta(candidate)
 
2551
            blocks = KnitContent.get_line_delta_blocks(delta,
 
2552
                fulltext[parents[0]], fulltext[candidate])
 
2553
        annotations[candidate] = list(annotate.reannotate([annotations[p]
 
2554
            for p in parents], fulltext[candidate], candidate, blocks))
 
2555
    return iter(annotations[revision_id])
 
2556
 
 
2557
 
2525
2558
try:
2526
2559
    from bzrlib._knit_load_data_c import _load_data_c as _load_data
2527
2560
except ImportError: