/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 repository.py

Implement Repository.iter_files_bytes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
    Tag,
53
53
    ZERO_SHA,
54
54
    )
 
55
from dulwich.object_store import (
 
56
    tree_lookup_path,
 
57
    )
55
58
 
56
59
 
57
60
class GitRepository(ForeignRepository):
134
137
            timestamp, timezone, committer, revprops, revision_id,
135
138
            lossy)
136
139
 
 
140
    def iter_files_bytes(self, desired_files):
 
141
        """Iterate through file versions.
 
142
 
 
143
        Files will not necessarily be returned in the order they occur in
 
144
        desired_files.  No specific order is guaranteed.
 
145
 
 
146
        Yields pairs of identifier, bytes_iterator.  identifier is an opaque
 
147
        value supplied by the caller as part of desired_files.  It should
 
148
        uniquely identify the file version in the caller's context.  (Examples:
 
149
        an index number or a TreeTransform trans_id.)
 
150
 
 
151
        bytes_iterator is an iterable of bytestrings for the file.  The
 
152
        kind of iterable and length of the bytestrings are unspecified, but for
 
153
        this implementation, it is a list of bytes produced by
 
154
        VersionedFile.get_record_stream().
 
155
 
 
156
        :param desired_files: a list of (file_id, revision_id, identifier)
 
157
            triples
 
158
        """
 
159
        per_revision = {}
 
160
        for (file_id, revision_id, identifier) in desired_files:
 
161
            per_revision.setdefault(revision_id, []).append((file_id, identifier))
 
162
        for revid, files in per_revision.iteritems():
 
163
            (commit_id, mapping) = self.lookup_bzr_revision_id(revid)
 
164
            try:
 
165
                commit = self._git.object_store[commit_id]
 
166
            except KeyError:
 
167
                raise errors.RevisionNotPresent(revid, self)
 
168
            root_tree = commit.tree
 
169
            for fileid, identifier in files:
 
170
                path = mapping.parse_file_id(fileid)
 
171
                try:
 
172
                    obj = tree_lookup_path(
 
173
                        self._git.object_store.__getitem__, root_tree, path)
 
174
                    if isinstance(obj, tuple):
 
175
                        (mode, item_id) = obj
 
176
                        obj = self._git.object_store[item_id]
 
177
                except KeyError:
 
178
                    raise errors.RevisionNotPresent((fileid, revid), self)
 
179
                else:
 
180
                    if obj.type_name == "tree":
 
181
                        yield (identifier, [])
 
182
                    elif obj.type_name == "blob":
 
183
                        yield (identifier, obj.chunked)
 
184
                    else:
 
185
                        raise AssertionError("file text resolved to %r" % obj)
 
186
 
 
187
 
137
188
    def _iter_revision_ids(self):
138
189
        mapping = self.get_mapping()
139
190
        for sha in self._git.object_store: