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

Fix some long lines.

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
            elif file_id[i+1] == 's':
68
68
                ret.append(" ")
69
69
            else:
70
 
                raise AssertionError("unknown escape character %s" % file_id[i+1])
 
70
                raise AssertionError("unknown escape character %s" %
 
71
                    file_id[i+1])
71
72
            i += 1
72
73
        i += 1
73
74
    return "".join(ret)
85
86
 
86
87
 
87
88
def warn_unusual_mode(commit, path, mode):
88
 
    trace.mutter("Unusual file mode %o for %s in %s. Storing as revision property. ",
89
 
                 mode, path, commit)
 
89
    trace.mutter("Unusual file mode %o for %s in %s. Storing as revision "
 
90
                 "property. ", mode, path, commit)
90
91
 
91
92
 
92
93
def squash_revision(target_repo, rev):
162
163
 
163
164
    def _generate_git_svn_metadata(self, rev, encoding):
164
165
        try:
165
 
            return "\ngit-svn-id: %s\n" % rev.properties["git-svn-id"].encode(encoding)
 
166
            return "\ngit-svn-id: %s\n" % rev.properties["git-svn-id"].encode(
 
167
                encoding)
166
168
        except KeyError:
167
169
            return ""
168
170
 
174
176
            if name == 'hg:extra:branch':
175
177
                branch = rev.properties['hg:extra:branch']
176
178
            elif name.startswith('hg:extra'):
177
 
                extra[name[len('hg:extra:'):]] = base64.b64decode(rev.properties[name])
 
179
                extra[name[len('hg:extra:'):]] = base64.b64decode(
 
180
                    rev.properties[name])
178
181
            elif name == 'hg:renames':
179
 
                renames = bencode.bdecode(base64.b64decode(rev.properties['hg:renames']))
 
182
                renames = bencode.bdecode(base64.b64decode(
 
183
                    rev.properties['hg:renames']))
180
184
            # TODO: Export other properties as 'bzr:' extras?
181
185
        ret = format_hg_metadata(renames, branch, extra)
182
186
        assert isinstance(ret, str)
201
205
        for name, value in extra.iteritems():
202
206
            rev.properties['hg:extra:' + name] = base64.b64encode(value)
203
207
        if renames:
204
 
            rev.properties['hg:renames'] = base64.b64encode(bencode.bencode([(new, old) for (old, new) in renames.iteritems()]))
 
208
            rev.properties['hg:renames'] = base64.b64encode(bencode.bencode(
 
209
                [(new, old) for (old, new) in renames.iteritems()]))
205
210
        return message
206
211
 
207
212
    def _decode_commit_message(self, rev, message, encoding):
214
219
        """Turn a Bazaar revision in to a Git commit
215
220
 
216
221
        :param tree_sha: Tree sha for the commit
217
 
        :param parent_lookup: Function for looking up the GIT sha equiv of a bzr revision
 
222
        :param parent_lookup: Function for looking up the GIT sha equiv of a
 
223
            bzr revision
218
224
        :return dulwich.objects.Commit represent the revision:
219
225
        """
220
226
        from dulwich.objects import Commit
258
264
        """
259
265
        if commit is None:
260
266
            raise AssertionError("Commit object can't be None")
261
 
        rev = ForeignRevision(commit.id, self, self.revision_id_foreign_to_bzr(commit.id))
 
267
        rev = ForeignRevision(commit.id, self,
 
268
                self.revision_id_foreign_to_bzr(commit.id))
262
269
        rev.parent_ids = tuple([self.revision_id_foreign_to_bzr(p) for p in commit.parents])
263
270
        def decode_using_encoding(rev, commit, encoding):
264
271
            rev.committer = str(commit.committer).decode(encoding)
282
289
        if commit.commit_time != commit.author_time:
283
290
            rev.properties['author-timestamp'] = str(commit.author_time)
284
291
        if commit.commit_timezone != commit.author_timezone:
285
 
            rev.properties['author-timezone'] = "%d" % (commit.author_timezone, )
 
292
            rev.properties['author-timezone'] = "%d" % commit.author_timezone
286
293
        rev.timestamp = commit.commit_time
287
294
        rev.timezone = commit.commit_timezone
288
295
        return rev
334
341
 
335
342
mapping_registry = GitMappingRegistry()
336
343
mapping_registry.register_lazy('git-v1', "bzrlib.plugins.git.mapping",
337
 
                                   "BzrGitMappingv1")
338
 
mapping_registry.register_lazy('git-experimental', "bzrlib.plugins.git.mapping",
339
 
                                   "BzrGitMappingExperimental")
 
344
    "BzrGitMappingv1")
 
345
mapping_registry.register_lazy('git-experimental',
 
346
    "bzrlib.plugins.git.mapping", "BzrGitMappingExperimental")
340
347
mapping_registry.set_default('git-v1')
341
348
 
342
349
 
451
458
 
452
459
def extract_unusual_modes(rev):
453
460
    try:
454
 
        foreign_revid, mapping = mapping_registry.parse_revision_id(rev.revision_id)
 
461
        foreign_revid, mapping = mapping_registry.parse_revision_id(
 
462
            rev.revision_id)
455
463
    except errors.InvalidRevisionId:
456
464
        return {}
457
465
    else:
458
466
        return mapping.export_unusual_file_modes(rev)
459
467
 
460
468
 
461
 
def inventory_to_tree_and_blobs(inventory, texts, mapping, unusual_modes, cur=None):
 
469
def inventory_to_tree_and_blobs(inventory, texts, mapping, unusual_modes,
 
470
                                cur=None):
462
471
    """Convert a Bazaar tree to a Git tree.
463
472
 
464
473
    :return: Yields tuples with object sha1, object and path
489
498
        else:
490
499
            if entry.kind == "file":
491
500
                from dulwich.objects import Blob
492
 
                text = texts.get_record_stream([(entry.file_id, entry.revision)], 'unordered', True).next().get_bytes_as('fulltext')
 
501
                stream = texts.get_record_stream(
 
502
                    [(entry.file_id, entry.revision)], 'unordered', True)
 
503
                text = stream.next().get_bytes_as('fulltext')
493
504
                blob = Blob()
494
505
                blob.data = text
495
506
            elif entry.kind == "symlink":