79
78
def warn_unusual_mode(commit, path, mode):
80
trace.mutter("Unusual file mode %o for %s in %s. Storing as revision property. ",
84
def squash_revision(target_repo, rev):
85
"""Remove characters that can't be stored from a revision, if necessary.
87
:param target_repo: Repository in which the revision will be stored
88
:param rev: Revision object, will be modified in-place
90
if not getattr(target_repo._serializer, "squashes_xml_invalid_characters", True):
92
from bzrlib.xml_serializer import escape_invalid_chars
93
rev.message, num_escaped = escape_invalid_chars(rev.message)
95
warn_escaped(rev.foreign_revid, num_escaped)
96
if 'author' in rev.properties:
97
rev.properties['author'], num_escaped = escape_invalid_chars(
98
rev.properties['author'])
100
warn_escaped(rev.foreign_revid, num_escaped)
101
rev.committer, num_escaped = escape_invalid_chars(rev.committer)
103
warn_escaped(rev.foreign_revid, num_escaped)
79
trace.warning("Unusual file mode %o for %s in %s. Will be unable to "
80
"regenerate the SHA map.", mode, path, commit)
106
83
class BzrGitMapping(foreign.VcsMapping):
138
115
return unescape_file_id(file_id)
140
def import_unusual_file_modes(self, rev, unusual_file_modes):
141
if unusual_file_modes:
142
ret = [(name, unusual_file_modes[name]) for name in sorted(unusual_file_modes.keys())]
143
rev.properties['file-modes'] = bencode.bencode(ret)
145
def export_unusual_file_modes(self, rev):
147
return dict([(self.generate_file_id(path), mode) for (path, mode) in bencode.bdecode(rev.properties['file-modes'])])
151
117
def import_commit(self, commit):
152
118
"""Convert a git commit to a bzr revision.
157
123
raise AssertionError("Commit object can't be None")
158
124
rev = ForeignRevision(commit.id, self, self.revision_id_foreign_to_bzr(commit.id))
159
125
rev.parent_ids = tuple([self.revision_id_foreign_to_bzr(p) for p in commit.parents])
160
rev.message = commit.message.decode("utf-8", "replace")
161
rev.committer = str(commit.committer).decode("utf-8", "replace")
126
rev.message, num_escaped = escape_invalid_chars(commit.message.decode("utf-8", "replace"))
128
warn_escaped(commit.id, num_escaped)
129
rev.committer, num_escaped = escape_invalid_chars(str(commit.committer).decode("utf-8", "replace"))
131
warn_escaped(commit.id, num_escaped)
162
132
if commit.committer != commit.author:
163
rev.properties['author'] = str(commit.author).decode("utf-8", "replace")
133
rev.properties['author'], num_escaped = escape_invalid_chars(str(commit.author).decode("utf-8", "replace"))
135
warn_escaped(commit.id, num_escaped)
165
137
if commit.commit_time != commit.author_time:
166
138
rev.properties['author-timestamp'] = str(commit.author_time)
187
159
class GitMappingRegistry(VcsMappingRegistry):
188
"""Registry with available git mappings."""
190
161
def revision_id_bzr_to_foreign(self, bzr_revid):
191
162
if not bzr_revid.startswith("git-"):
233
204
blob._text = entry.symlink_target
237
207
def mode_is_executable(mode):
238
"""Check if mode should be considered executable."""
239
208
return bool(mode & 0111)
242
210
def mode_kind(mode):
243
"""Determine the Bazaar inventory kind based on Unix file mode."""
244
211
entry_kind = (mode & 0700000) / 0100000
245
212
if entry_kind == 0:
246
213
return 'directory'
275
241
raise AssertionError
278
def directory_to_tree(entry, lookup_ie_sha1, unusual_modes):
244
def directory_to_tree(entry, lookup_ie_sha1):
279
245
from dulwich.objects import Tree
281
247
for name in sorted(entry.children.keys()):
282
248
ie = entry.children[name]
284
mode = unusual_modes[ie.file_id]
286
mode = entry_mode(ie)
287
tree.add(mode, name.encode("utf-8"), lookup_ie_sha1(ie))
249
tree.add(entry_mode(ie), name.encode("utf-8"), lookup_ie_sha1(ie))
292
def extract_unusual_modes(rev):
294
foreign_revid, mapping = mapping_registry.parse_revision_id(rev.revision_id)
295
except errors.InvalidRevisionId:
298
return mapping.export_unusual_file_modes(rev)
301
def inventory_to_tree_and_blobs(inventory, texts, mapping, unusual_modes, cur=None):
254
def inventory_to_tree_and_blobs(inventory, texts, mapping, cur=None):
302
255
"""Convert a Bazaar tree to a Git tree.
304
257
:return: Yields tuples with object sha1, object and path
320
273
yield sha, tree, cur.encode("utf-8")
321
mode = unusual_modes.get(cur.encode("utf-8"), stat.S_IFDIR)
322
t = (mode, urlutils.basename(cur).encode('UTF-8'), sha)
274
t = (stat.S_IFDIR, urlutils.basename(cur).encode('UTF-8'), sha)
323
275
cur, tree = stack.pop()
338
290
yield sha, blob, path.encode("utf-8")
339
291
name = urlutils.basename(path).encode("utf-8")
340
mode = unusual_modes.get(path.encode("utf-8"), entry_mode(entry))
341
tree.add(mode, name, sha)
292
tree.add(entry_mode(entry), name, sha)
343
294
while len(stack) > 1:
346
297
yield sha, tree, cur.encode("utf-8")
347
mode = unusual_modes.get(cur.encode('utf-8'), stat.S_IFDIR)
348
t = (mode, urlutils.basename(cur).encode('UTF-8'), sha)
298
t = (stat.S_IFDIR, urlutils.basename(cur).encode('UTF-8'), sha)
349
299
cur, tree = stack.pop()