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

  • Committer: Jelmer Vernooij
  • Date: 2018-07-03 00:15:59 UTC
  • mto: This revision was merged to the branch mainline in revision 7027.
  • Revision ID: jelmer@jelmer.uk-20180703001559-crogxh6en8s4d83b
Fix remaining git tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
    NULL_REVISION,
43
43
    )
44
44
from ...sixish import (
 
45
    PY3,
45
46
    text_type,
46
47
    viewitems,
47
48
    )
64
65
 
65
66
 
66
67
DEFAULT_FILE_MODE = stat.S_IFREG | 0o644
67
 
HG_RENAME_SOURCE = "HG:rename-source"
68
 
HG_EXTRA = "HG:extra"
 
68
HG_RENAME_SOURCE = b"HG:rename-source"
 
69
HG_EXTRA = b"HG:extra"
69
70
 
70
71
# This HG extra is used to indicate the commit that this commit was based on.
71
 
HG_EXTRA_AMEND_SOURCE = "amend_source"
 
72
HG_EXTRA_AMEND_SOURCE = b"amend_source"
72
73
 
73
74
FILE_ID_PREFIX = b'git:'
74
75
 
174
175
    def revid_as_refname(self, revid):
175
176
        if not isinstance(revid, bytes):
176
177
            raise TypeError(revid)
177
 
        return b"refs/bzr/" + urlutils.quote(revid)
 
178
        if PY3:
 
179
            revid = revid.decode('utf-8')
 
180
        quoted_revid = urlutils.quote(revid)
 
181
        return b"refs/bzr/" + quoted_revid.encode('utf-8')
178
182
 
179
183
    def import_unusual_file_modes(self, rev, unusual_file_modes):
180
184
        if unusual_file_modes:
347
351
        i = 0
348
352
        propname = u'git-mergetag-0'
349
353
        while propname in rev.properties:
350
 
            commit.mergetag.append(Tag.from_string(rev.properties[propname].encode(encoding)))
 
354
            commit.mergetag.append(Tag.from_string(rev.properties[propname]))
351
355
            i += 1
352
356
            propname = u'git-mergetag-%d' % i
353
357
        if u'git-extra' in rev.properties:
354
 
            commit.extra.extend([l.split(' ', 1) for l in rev.properties[u'git-extra'].splitlines()])
 
358
            commit.extra.extend([l.split(b' ', 1) for l in rev.properties[u'git-extra'].splitlines()])
355
359
        return commit
356
360
 
357
361
    def import_fileid_map(self, blob):
376
380
        def decode_using_encoding(rev, commit, encoding):
377
381
            rev.committer = commit.committer.decode(encoding)
378
382
            if commit.committer != commit.author:
379
 
                rev.properties[u'author'] = str(commit.author).decode(encoding)
 
383
                rev.properties[u'author'] = commit.author.decode(encoding)
380
384
            rev.message, rev.git_metadata = self._decode_commit_message(
381
385
                rev, commit.message, encoding)
382
386
        if commit.encoding is not None:
430
434
        extra_lines = []
431
435
        for k, v in commit.extra:
432
436
            if k == HG_RENAME_SOURCE:
433
 
                extra_lines.append(k + ' ' + v + '\n')
 
437
                extra_lines.append(k + b' ' + v + b'\n')
434
438
            elif k == HG_EXTRA:
435
 
                hgk, hgv = v.split(':', 1)
 
439
                hgk, hgv = v.split(b':', 1)
436
440
                if hgk not in (HG_EXTRA_AMEND_SOURCE, ):
437
441
                    raise UnknownMercurialCommitExtra(commit, hgk)
438
 
                extra_lines.append(k + ' ' + v + '\n')
 
442
                extra_lines.append(k + b' ' + v + b'\n')
439
443
            else:
440
444
                unknown_extra_fields.append(k)
441
445
        if unknown_extra_fields:
442
 
            raise UnknownCommitExtra(commit, unknown_extra_fields)
 
446
            raise UnknownCommitExtra(
 
447
                commit, [f.decode('ascii', 'replace') for f in unknown_extra_fields])
443
448
        if extra_lines:
444
 
            rev.properties[u'git-extra'] = ''.join(extra_lines)
 
449
            rev.properties[u'git-extra'] = b''.join(extra_lines)
445
450
        return rev, roundtrip_revid, verifiers
446
451
 
447
452
    def get_fileid_map(self, lookup_object, tree_sha):
548
553
 
549
554
    @classmethod
550
555
    def show_foreign_revid(cls, foreign_revid):
551
 
        return { "git commit": foreign_revid }
 
556
        return { "git commit": foreign_revid.decode('utf-8') }
552
557
 
553
558
 
554
559
foreign_vcs_git = ForeignGit()