/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 breezy/git/annotate.py

  • Committer: Jelmer Vernooij
  • Date: 2019-11-03 00:17:16 UTC
  • mto: This revision was merged to the branch mainline in revision 7412.
  • Revision ID: jelmer@jelmer.uk-20191103001716-cexkmouumoqj0jtg
Remove trailing newline.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Annotate."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
from dulwich.object_store import (
20
22
    tree_lookup_path,
21
23
    )
22
24
 
23
 
from .. import osutils
24
 
from ..bzr.versionedfile import UnavailableRepresentation
25
25
from ..errors import (
26
26
    NoSuchRevision,
 
27
    UnavailableRepresentation,
27
28
    )
28
29
from ..graph import Graph
29
30
from ..revision import (
30
31
    NULL_REVISION,
31
32
    )
32
33
 
33
 
from .mapping import (
34
 
    decode_git_path,
35
 
    encode_git_path,
36
 
    )
37
 
 
38
 
 
39
 
class GitBlobContentFactory(object):
 
34
 
 
35
class GitFulltextContentFactory(object):
40
36
    """Static data content factory.
41
37
 
42
38
    This takes a fulltext when created and just returns that during
56
52
        """Create a ContentFactory."""
57
53
        self.store = store
58
54
        self.key = (path, revision)
59
 
        self.storage_kind = 'git-blob'
 
55
        self.storage_kind = 'fulltext'
60
56
        self.parents = None
61
57
        self.blob_id = blob_id
62
 
        self.size = None
63
58
 
64
59
    def get_bytes_as(self, storage_kind):
65
60
        if storage_kind == 'fulltext':
66
61
            return self.store[self.blob_id].as_raw_string()
67
 
        elif storage_kind == 'lines':
68
 
            return list(osutils.chunks_to_lines(self.store[self.blob_id].as_raw_chunks()))
69
62
        elif storage_kind == 'chunked':
70
63
            return self.store[self.blob_id].as_raw_chunks()
71
64
        raise UnavailableRepresentation(self.key, storage_kind,
72
 
                                        self.storage_kind)
73
 
 
74
 
    def iter_bytes_as(self, storage_kind):
75
 
        if storage_kind == 'lines':
76
 
            return iter(osutils.chunks_to_lines(self.store[self.blob_id].as_raw_chunks()))
77
 
        elif storage_kind == 'chunked':
78
 
            return iter(self.store[self.blob_id].as_raw_chunks())
79
 
        raise UnavailableRepresentation(self.key, storage_kind,
80
 
                                        self.storage_kind)
 
65
                                        'fulltext')
81
66
 
82
67
 
83
68
class GitAbsentContentFactory(object):
99
84
        self.key = (path, revision)
100
85
        self.storage_kind = 'absent'
101
86
        self.parents = None
102
 
        self.size = None
103
87
 
104
88
    def get_bytes_as(self, storage_kind):
105
89
        raise ValueError
106
90
 
107
 
    def iter_bytes_as(self, storage_kind):
108
 
        raise ValueError
109
 
 
110
91
 
111
92
class AnnotateProvider(object):
112
93
 
119
100
            self.change_scanner.repository.lookup_bzr_revision_id(
120
101
                text_revision))
121
102
        text_parents = []
122
 
        path = encode_git_path(path)
123
103
        for commit_parent in self.store[commit_id].parents:
124
104
            try:
125
105
                (path, text_parent) = (
126
106
                    self.change_scanner.find_last_change_revision(
127
 
                        path, commit_parent))
 
107
                        path.encode('utf-8'), commit_parent))
128
108
            except KeyError:
129
109
                continue
130
110
            if text_parent not in text_parents:
131
111
                text_parents.append(text_parent)
132
112
        return tuple([
133
 
            (decode_git_path(path),
 
113
            (path.decode('utf-8'),
134
114
                self.change_scanner.repository.lookup_foreign_revision_id(p))
135
115
            for p in text_parents])
136
116
 
168
148
                continue
169
149
            try:
170
150
                (mode, blob_sha) = tree_lookup_path(
171
 
                    store.__getitem__, tree_id, encode_git_path(path))
 
151
                    store.__getitem__, tree_id, path.encode('utf-8'))
172
152
            except KeyError:
173
153
                yield GitAbsentContentFactory(store, path, text_revision)
174
154
            else:
175
 
                yield GitBlobContentFactory(
 
155
                yield GitFulltextContentFactory(
176
156
                    store, path, text_revision, blob_sha)