63
60
class SettingCustomFileIdsUnsupported(UnsupportedOperation):
65
_fmt = "Unable to store addition of file with custom file ids: %(file_ids)r"
62
_fmt = ("Unable to store addition of file with custom file ids: "
67
65
def __init__(self, file_ids):
68
66
BzrError.__init__(self)
93
91
for (file_id, path, changed_content, versioned, parent, name, kind,
94
92
executable) in iter_changes:
95
93
if kind[1] in ("directory",):
96
self._inv_delta.append((path[0], path[1], file_id, entry_factory[kind[1]](file_id, name[1], parent[1])))
94
self._inv_delta.append(
95
(path[0], path[1], file_id, entry_factory[kind[1]](
96
file_id, name[1], parent[1])))
97
97
if kind[0] in ("file", "symlink"):
98
98
self._blobs[path[0].encode("utf-8")] = None
99
99
self._any_changes = True
123
123
self.store.add_object(blob)
125
125
elif kind[1] == "symlink":
126
symlink_target = workingtree.get_symlink_target(path[1], file_id)
126
symlink_target = workingtree.get_symlink_target(path[1])
128
128
blob.data = symlink_target.encode("utf-8")
129
129
self.store.add_object(blob)
133
133
elif kind[1] == "tree-reference":
134
134
sha = read_submodule_head(workingtree.abspath(path[1]))
135
reference_revision = workingtree.get_reference_revision(path[1], file_id)
135
reference_revision = workingtree.get_reference_revision(path[1])
136
136
entry.reference_revision = reference_revision
142
142
encoded_new_path = path[1].encode("utf-8")
143
143
self._blobs[encoded_new_path] = (mode, sha)
144
144
if st is not None:
145
yield file_id, path[1], (entry.text_sha1, st)
145
yield path[1], (entry.text_sha1, st)
146
146
if self._mapping.generate_file_id(encoded_new_path) != file_id:
147
147
self._override_fileids[encoded_new_path] = file_id
185
185
if self._mapping.BZR_FILE_IDS_FILE is None:
186
186
raise SettingCustomFileIdsUnsupported(fileid_map)
187
187
self.store.add_object(fileid_blob)
188
self._blobs[self._mapping.BZR_FILE_IDS_FILE] = (stat.S_IFREG | 0o644, fileid_blob.id)
188
self._blobs[self._mapping.BZR_FILE_IDS_FILE] = (
189
stat.S_IFREG | 0o644, fileid_blob.id)
190
191
self._blobs[self._mapping.BZR_FILE_IDS_FILE] = None
191
192
self.new_inventory = None
197
198
def finish_inventory(self):
198
199
# eliminate blobs that were removed
199
self._blobs = {k: v for (k, v) in viewitems(self._blobs) if v is not None}
200
self._blobs = {k: v for (k, v) in viewitems(
201
self._blobs) if v is not None}
201
203
def _iterblobs(self):
202
return ((path, sha, mode) for (path, (mode, sha)) in viewitems(self._blobs))
204
return ((path, sha, mode) for (path, (mode, sha))
205
in viewitems(self._blobs))
204
207
def commit(self, message):
205
208
self._validate_unicode_text(message, 'commit message')
207
c.parents = [self.repository.lookup_bzr_revision_id(revid)[0] for revid in self.parents]
210
c.parents = [self.repository.lookup_bzr_revision_id(
211
revid)[0] for revid in self.parents]
208
212
c.tree = commit_tree(self.store, self._iterblobs())
209
213
encoding = self._revprops.pop(u'git-explicit-encoding', 'utf-8')
210
214
c.encoding = encoding.encode('ascii')
211
215
c.committer = fix_person_identifier(self._committer.encode(encoding))
212
c.author = fix_person_identifier(self._revprops.pop('author', self._committer).encode(encoding))
217
author = self._revprops.pop('author')
220
authors = self._revprops.pop('authors').splitlines()
222
author = self._committer
225
raise Exception("Unable to convert multiple authors")
226
elif len(authors) == 0:
227
author = self._committer
230
c.author = fix_person_identifier(author.encode(encoding))
231
bugstext = self._revprops.pop('bugs', None)
232
if bugstext is not None:
234
for url, status in bugtracker.decode_bug_urls(bugstext):
235
if status == bugtracker.FIXED:
236
message += "Fixes: %s\n" % url
237
elif status == bugtracker.RELATED:
238
message += "Bug: %s\n" % url
240
raise bugtracker.InvalidBugStatus(status)
213
241
if self._revprops:
214
242
raise NotImplementedError(self._revprops)
215
243
c.commit_time = int(self._timestamp)
217
245
c.commit_timezone = self._timezone
218
246
c.author_timezone = self._timezone
219
247
c.message = message.encode(encoding)
220
if self._config_stack.get('create_signatures') == _mod_config.SIGN_ALWAYS:
248
if (self._config_stack.get('create_signatures') ==
249
_mod_config.SIGN_ALWAYS):
221
250
strategy = gpg.GPGStrategy(self._config_stack)
222
251
c.gpgsig = strategy.sign(c.as_raw_string(), gpg.MODE_DETACH)
223
252
self.store.add_object(c)