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

  • Committer: Jelmer Vernooij
  • Date: 2018-11-11 04:08:32 UTC
  • mto: (7143.16.20 even-more-cleanups)
  • mto: This revision was merged to the branch mainline in revision 7175.
  • Revision ID: jelmer@jelmer.uk-20181111040832-nsljjynzzwmznf3h
Run autopep8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
    ret = bytearray()
83
83
    i = 0
84
84
    while i < len(file_id):
85
 
        if file_id[i:i+1] != b'_':
 
85
        if file_id[i:i + 1] != b'_':
86
86
            ret.append(file_id[i])
87
87
        else:
88
 
            if file_id[i+1:i+2] == b'_':
 
88
            if file_id[i + 1:i + 2] == b'_':
89
89
                ret.append(b"_"[0])
90
 
            elif file_id[i+1:i+2] == b's':
 
90
            elif file_id[i + 1:i + 2] == b's':
91
91
                ret.append(b" "[0])
92
 
            elif file_id[i+1:i+2] == b'c':
 
92
            elif file_id[i + 1:i + 2] == b'c':
93
93
                ret.append(b"\x0c"[0])
94
94
            else:
95
95
                raise ValueError("unknown escape character %s" %
96
 
                        file_id[i+1:i+2])
 
96
                                 file_id[i + 1:i + 2])
97
97
            i += 1
98
98
        i += 1
99
99
    return bytes(ret)
138
138
        super(BzrGitMapping, self).__init__(foreign_vcs_git)
139
139
 
140
140
    def __eq__(self, other):
141
 
        return (type(self) == type(other) and
142
 
                self.revid_prefix == other.revid_prefix)
 
141
        return (type(self) == type(other)
 
142
                and self.revid_prefix == other.revid_prefix)
143
143
 
144
144
    @classmethod
145
145
    def revision_id_foreign_to_bzr(cls, git_rev_id):
154
154
        """Convert a Bazaar revision id to a git revision id handle."""
155
155
        if not bzr_rev_id.startswith(b"%s:" % cls.revid_prefix):
156
156
            raise errors.InvalidRevisionId(bzr_rev_id, cls)
157
 
        return bzr_rev_id[len(cls.revid_prefix)+1:], cls()
 
157
        return bzr_rev_id[len(cls.revid_prefix) + 1:], cls()
158
158
 
159
159
    def generate_file_id(self, path):
160
160
        # Git paths are just bytestrings
300
300
        except KeyError:
301
301
            encoding = rev.properties.get(u'git-implicit-encoding', 'utf-8')
302
302
        try:
303
 
            commit.encoding = rev.properties[u'git-explicit-encoding'].encode('ascii')
 
303
            commit.encoding = rev.properties[u'git-explicit-encoding'].encode(
 
304
                'ascii')
304
305
        except KeyError:
305
306
            pass
306
307
        commit.committer = fix_person_identifier(rev.committer.encode(
322
323
        else:
323
324
            commit.author_timezone = commit.commit_timezone
324
325
        if u'git-gpg-signature' in rev.properties:
325
 
            commit.gpgsig = rev.properties[u'git-gpg-signature'].encode('ascii')
 
326
            commit.gpgsig = rev.properties[u'git-gpg-signature'].encode(
 
327
                'ascii')
326
328
        commit.message = self._encode_commit_message(rev, rev.message,
327
 
            encoding)
 
329
                                                     encoding)
328
330
        if not isinstance(commit.message, bytes):
329
331
            raise TypeError(commit.message)
330
332
        if metadata is not None:
345
347
                commit.message = inject_bzr_metadata(commit.message, metadata,
346
348
                                                     encoding)
347
349
            else:
348
 
                raise NoPushSupport(None, None, self, revision_id=rev.revision_id)
 
350
                raise NoPushSupport(
 
351
                    None, None, self, revision_id=rev.revision_id)
349
352
        if not isinstance(commit.message, bytes):
350
353
            raise TypeError(commit.message)
351
354
        i = 0
355
358
            i += 1
356
359
            propname = u'git-mergetag-%d' % i
357
360
        if u'git-extra' in rev.properties:
358
 
            commit.extra.extend([l.split(b' ', 1) for l in rev.properties[u'git-extra'].splitlines()])
 
361
            commit.extra.extend([l.split(b' ', 1)
 
362
                                 for l in rev.properties[u'git-extra'].splitlines()])
359
363
        return commit
360
364
 
361
365
    def import_fileid_map(self, blob):
375
379
        if commit is None:
376
380
            raise AssertionError("Commit object can't be None")
377
381
        rev = ForeignRevision(commit.id, self,
378
 
                self.revision_id_foreign_to_bzr(commit.id))
 
382
                              self.revision_id_foreign_to_bzr(commit.id))
379
383
        rev.git_metadata = None
 
384
 
380
385
        def decode_using_encoding(rev, commit, encoding):
381
386
            rev.committer = commit.committer.decode(encoding)
382
387
            if commit.committer != commit.author:
384
389
            rev.message, rev.git_metadata = self._decode_commit_message(
385
390
                rev, commit.message, encoding)
386
391
        if commit.encoding is not None:
387
 
            rev.properties[u'git-explicit-encoding'] = commit.encoding.decode('ascii')
 
392
            rev.properties[u'git-explicit-encoding'] = commit.encoding.decode(
 
393
                'ascii')
388
394
            decode_using_encoding(rev, commit, commit.encoding.decode('ascii'))
389
395
        else:
390
396
            for encoding in ('utf-8', 'latin1'):
405
411
        if commit._commit_timezone_neg_utc:
406
412
            rev.properties[u'commit-timezone-neg-utc'] = ""
407
413
        if commit.gpgsig:
408
 
            rev.properties[u'git-gpg-signature'] = commit.gpgsig.decode('ascii')
 
414
            rev.properties[u'git-gpg-signature'] = commit.gpgsig.decode(
 
415
                'ascii')
409
416
        if commit.mergetag:
410
417
            for i, tag in enumerate(commit.mergetag):
411
418
                rev.properties[u'git-mergetag-%d' % i] = tag.as_raw_string()
457
464
        :return: GitFileIdMap instance
458
465
        """
459
466
        try:
460
 
            file_id_map_sha = lookup_object(tree_sha)[self.BZR_FILE_IDS_FILE][1]
 
467
            file_id_map_sha = lookup_object(
 
468
                tree_sha)[self.BZR_FILE_IDS_FILE][1]
461
469
        except KeyError:
462
470
            file_ids = {}
463
471
        else:
495
503
        return ret
496
504
 
497
505
    def import_commit(self, commit, lookup_parent_revid):
498
 
        rev, roundtrip_revid, verifiers = super(BzrGitMappingExperimental, self).import_commit(commit, lookup_parent_revid)
 
506
        rev, roundtrip_revid, verifiers = super(
 
507
            BzrGitMappingExperimental, self).import_commit(commit, lookup_parent_revid)
499
508
        rev.properties[u'converted_revision'] = "git %s\n" % commit.id
500
509
        return rev, roundtrip_revid, verifiers
501
510
 
518
527
 
519
528
mapping_registry = GitMappingRegistry()
520
529
mapping_registry.register_lazy(b'git-v1', __name__,
521
 
    "BzrGitMappingv1")
 
530
                               "BzrGitMappingv1")
522
531
mapping_registry.register_lazy(b'git-experimental',
523
 
    __name__, "BzrGitMappingExperimental")
 
532
                               __name__, "BzrGitMappingExperimental")
524
533
# Uncomment the next line to enable the experimental bzr-git mappings.
525
534
# This will make sure all bzr metadata is pushed into git, allowing for
526
535
# full roundtripping later.
527
536
# NOTE: THIS IS EXPERIMENTAL. IT MAY EAT YOUR DATA OR CORRUPT
528
537
# YOUR BZR OR GIT REPOSITORIES. USE WITH CARE.
529
 
#mapping_registry.set_default('git-experimental')
 
538
# mapping_registry.set_default('git-experimental')
530
539
mapping_registry.set_default(b'git-v1')
531
540
 
532
541
 
553
562
 
554
563
    @classmethod
555
564
    def show_foreign_revid(cls, foreign_revid):
556
 
        return { "git commit": foreign_revid.decode('utf-8') }
 
565
        return {"git commit": foreign_revid.decode('utf-8')}
557
566
 
558
567
 
559
568
foreign_vcs_git = ForeignGit()