63
59
class SettingCustomFileIdsUnsupported(UnsupportedOperation):
65
_fmt = "Unable to store addition of file with custom file ids: %(file_ids)r"
61
_fmt = ("Unable to store addition of file with custom file ids: "
67
64
def __init__(self, file_ids):
68
65
BzrError.__init__(self)
93
90
for (file_id, path, changed_content, versioned, parent, name, kind,
94
91
executable) in iter_changes:
95
92
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])))
93
self._inv_delta.append(
94
(path[0], path[1], file_id, entry_factory[kind[1]](
95
file_id, name[1], parent[1])))
97
96
if kind[0] in ("file", "symlink"):
98
97
self._blobs[path[0].encode("utf-8")] = None
99
98
self._any_changes = True
113
112
if kind[1] == "file":
114
113
entry.executable = executable[1]
116
f, st = workingtree.get_file_with_stat(path[1], file_id)
115
f, st = workingtree.get_file_with_stat(path[1])
118
117
blob.data = f.read()
123
122
self.store.add_object(blob)
125
124
elif kind[1] == "symlink":
126
symlink_target = workingtree.get_symlink_target(path[1], file_id)
125
symlink_target = workingtree.get_symlink_target(path[1])
128
127
blob.data = symlink_target.encode("utf-8")
129
128
self.store.add_object(blob)
133
132
elif kind[1] == "tree-reference":
134
133
sha = read_submodule_head(workingtree.abspath(path[1]))
135
reference_revision = workingtree.get_reference_revision(path[1], file_id)
134
reference_revision = workingtree.get_reference_revision(path[1])
136
135
entry.reference_revision = reference_revision
185
184
if self._mapping.BZR_FILE_IDS_FILE is None:
186
185
raise SettingCustomFileIdsUnsupported(fileid_map)
187
186
self.store.add_object(fileid_blob)
188
self._blobs[self._mapping.BZR_FILE_IDS_FILE] = (stat.S_IFREG | 0o644, fileid_blob.id)
187
self._blobs[self._mapping.BZR_FILE_IDS_FILE] = (
188
stat.S_IFREG | 0o644, fileid_blob.id)
190
190
self._blobs[self._mapping.BZR_FILE_IDS_FILE] = None
191
191
self.new_inventory = None
197
197
def finish_inventory(self):
198
198
# eliminate blobs that were removed
199
self._blobs = {k: v for (k, v) in viewitems(self._blobs) if v is not None}
199
self._blobs = {k: v for (k, v) in viewitems(
200
self._blobs) if v is not None}
201
202
def _iterblobs(self):
202
return ((path, sha, mode) for (path, (mode, sha)) in viewitems(self._blobs))
203
return ((path, sha, mode) for (path, (mode, sha))
204
in viewitems(self._blobs))
204
206
def commit(self, message):
205
207
self._validate_unicode_text(message, 'commit message')
207
c.parents = [self.repository.lookup_bzr_revision_id(revid)[0] for revid in self.parents]
209
c.parents = [self.repository.lookup_bzr_revision_id(
210
revid)[0] for revid in self.parents]
208
211
c.tree = commit_tree(self.store, self._iterblobs())
209
212
encoding = self._revprops.pop(u'git-explicit-encoding', 'utf-8')
210
213
c.encoding = encoding.encode('ascii')
211
214
c.committer = fix_person_identifier(self._committer.encode(encoding))
212
c.author = fix_person_identifier(self._revprops.pop('author', self._committer).encode(encoding))
216
author = self._revprops.pop('author')
219
authors = self._revprops.pop('authors').splitlines()
221
author = self._committer
224
raise Exception("Unable to convert multiple authors")
225
elif len(authors) == 0:
226
author = self._committer
229
c.author = fix_person_identifier(author.encode(encoding))
213
230
if self._revprops:
214
231
raise NotImplementedError(self._revprops)
215
232
c.commit_time = int(self._timestamp)
217
234
c.commit_timezone = self._timezone
218
235
c.author_timezone = self._timezone
219
236
c.message = message.encode(encoding)
220
if self._config_stack.get('create_signatures') == _mod_config.SIGN_ALWAYS:
237
if (self._config_stack.get('create_signatures') ==
238
_mod_config.SIGN_ALWAYS):
221
239
strategy = gpg.GPGStrategy(self._config_stack)
222
240
c.gpgsig = strategy.sign(c.as_raw_string(), gpg.MODE_DETACH)
223
241
self.store.add_object(c)