/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: 2018-06-14 17:59:16 UTC
  • mto: This revision was merged to the branch mainline in revision 7065.
  • Revision ID: jelmer@jelmer.uk-20180614175916-a2e2xh5k533guq1x
Move breezy.plugins.git to breezy.git.

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
 
 
21
from dulwich.errors import (
 
22
    NotTreeError,
 
23
    )
19
24
from dulwich.object_store import (
20
25
    tree_lookup_path,
21
26
    )
22
27
 
23
 
from .. import osutils
24
 
from ..bzr.versionedfile import UnavailableRepresentation
25
 
from ..errors import (
26
 
    NoSuchRevision,
27
 
    )
 
28
from ..errors import UnavailableRepresentation
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
from .filegraph import GitFileLastChangeScanner
 
35
 
 
36
 
 
37
class GitFulltextContentFactory(object):
40
38
    """Static data content factory.
41
39
 
42
40
    This takes a fulltext when created and just returns that during
56
54
        """Create a ContentFactory."""
57
55
        self.store = store
58
56
        self.key = (path, revision)
59
 
        self.storage_kind = 'git-blob'
 
57
        self.storage_kind = 'fulltext'
60
58
        self.parents = None
61
59
        self.blob_id = blob_id
62
 
        self.size = None
63
60
 
64
61
    def get_bytes_as(self, storage_kind):
65
62
        if storage_kind == 'fulltext':
66
63
            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
64
        elif storage_kind == 'chunked':
70
65
            return self.store[self.blob_id].as_raw_chunks()
71
66
        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)
 
67
                'fulltext')
81
68
 
82
69
 
83
70
class GitAbsentContentFactory(object):
99
86
        self.key = (path, revision)
100
87
        self.storage_kind = 'absent'
101
88
        self.parents = None
102
 
        self.size = None
103
89
 
104
90
    def get_bytes_as(self, storage_kind):
105
91
        raise ValueError
106
92
 
107
 
    def iter_bytes_as(self, storage_kind):
108
 
        raise ValueError
109
 
 
110
93
 
111
94
class AnnotateProvider(object):
112
95
 
115
98
        self.store = self.change_scanner.repository._git.object_store
116
99
 
117
100
    def _get_parents(self, path, text_revision):
118
 
        commit_id, mapping = (
119
 
            self.change_scanner.repository.lookup_bzr_revision_id(
120
 
                text_revision))
 
101
        commit_id, mapping = self.change_scanner.repository.lookup_bzr_revision_id(
 
102
            text_revision)
121
103
        text_parents = []
122
 
        path = encode_git_path(path)
123
104
        for commit_parent in self.store[commit_id].parents:
124
105
            try:
125
 
                (path, text_parent) = (
126
 
                    self.change_scanner.find_last_change_revision(
127
 
                        path, commit_parent))
 
106
                (path, text_parent) = self.change_scanner.find_last_change_revision(path, commit_parent)
128
107
            except KeyError:
129
108
                continue
130
109
            if text_parent not in text_parents:
131
110
                text_parents.append(text_parent)
132
 
        return tuple([
133
 
            (decode_git_path(path),
134
 
                self.change_scanner.repository.lookup_foreign_revision_id(p))
135
 
            for p in text_parents])
 
111
        return tuple([(path,
 
112
            self.change_scanner.repository.lookup_foreign_revision_id(p)) for p
 
113
            in text_parents])
136
114
 
137
115
    def get_parent_map(self, keys):
138
116
        ret = {}
154
132
        store = self.change_scanner.repository._git.object_store
155
133
        for (path, text_revision) in keys:
156
134
            try:
157
 
                commit_id, mapping = (
158
 
                    self.change_scanner.repository.lookup_bzr_revision_id(
159
 
                        text_revision))
160
 
            except NoSuchRevision:
 
135
                commit_id, mapping = self.change_scanner.repository.lookup_bzr_revision_id(
 
136
                    text_revision)
 
137
            except errors.NoSuchRevision:
161
138
                yield GitAbsentContentFactory(store, path, text_revision)
162
139
                continue
163
140
 
167
144
                yield GitAbsentContentFactory(store, path, text_revision)
168
145
                continue
169
146
            try:
170
 
                (mode, blob_sha) = tree_lookup_path(
171
 
                    store.__getitem__, tree_id, encode_git_path(path))
 
147
                (mode, blob_sha) = tree_lookup_path(store.__getitem__, tree_id, path)
172
148
            except KeyError:
173
149
                yield GitAbsentContentFactory(store, path, text_revision)
174
150
            else:
175
 
                yield GitBlobContentFactory(
176
 
                    store, path, text_revision, blob_sha)
 
151
                yield GitFulltextContentFactory(store, path, text_revision, blob_sha)