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

Merge fixes for SHA1s of symlinks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
133
133
    def _get_ie_object(self, entry, inv, unusual_modes):
134
134
        if entry.kind == "directory":
135
135
            return self._get_tree(entry.file_id, inv.revision_id, inv, unusual_modes)
136
 
        elif entry.kind in ("file", "symlink"):
137
 
            return self._get_blob(entry.file_id, entry.revision)
 
136
        elif entry.kind == "symlink":
 
137
            return self._get_blob_for_symlink(entry.symlink_target)
 
138
        elif entry.kind == "file":
 
139
            return self._get_blob_for_file(entry.file_id, entry.revision)
138
140
        else:
139
141
            raise AssertionError("unknown entry kind '%s'" % entry.kind)
140
142
 
163
165
    def _get_ie_sha1(self, entry, inv, unusual_modes):
164
166
        return self._get_ie_object_or_sha1(entry, inv, unusual_modes)[0]
165
167
 
166
 
    def _get_blob(self, fileid, revision, expected_sha=None):
 
168
    def _get_blob_for_symlink(self, symlink_target, expected_sha=None):
 
169
        """Return a Git Blob object for symlink.
 
170
 
 
171
        :param symlink_target: target of symlink.
 
172
        """
 
173
        if type(symlink_target) == unicode:
 
174
            symlink_target = symlink_target.encode('utf-8')
 
175
        blob = Blob()
 
176
        blob._text = symlink_target
 
177
        self._check_expected_sha(expected_sha, blob)
 
178
        return blob
 
179
 
 
180
    def _get_blob_for_file(self, fileid, revision, expected_sha=None):
167
181
        """Return a Git Blob object from a fileid and revision stored in bzr.
168
182
 
169
183
        :param fileid: File id of the text
170
184
        :param revision: Revision of the text
171
185
        """
 
186
        blob = Blob()
172
187
        chunks = self.repository.iter_files_bytes([(fileid, revision, None)]).next()[1]
173
 
        blob = Blob()
174
188
        blob._text = "".join(chunks)
175
189
        self._check_expected_sha(expected_sha, blob)
176
190
        return blob
177
191
 
 
192
    def _get_blob(self, fileid, revision, expected_sha=None):
 
193
        """Return a Git Blob object from a fileid and revision stored in bzr.
 
194
 
 
195
        :param fileid: File id of the text
 
196
        :param revision: Revision of the text
 
197
        """
 
198
        inv = self.repository.get_inventory(revision)
 
199
        entry = inv[fileid]
 
200
 
 
201
        if entry.kind == 'file':
 
202
            return self._get_blob_for_file(entry.file_id, entry.revision,
 
203
                                           expected_sha=expected_sha)
 
204
        elif entry.kind == 'symlink':
 
205
            return self._get_blob_for_symlink(entry.symlink_target,
 
206
                                              expected_sha=expected_sha)
 
207
        else:
 
208
            raise AssertionError
 
209
 
178
210
    def _get_tree(self, fileid, revid, inv, unusual_modes, expected_sha=None):
179
211
        """Return a Git Tree object from a file id and a revision stored in bzr.
180
212