/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: 2020-08-10 15:00:17 UTC
  • mfrom: (7490.40.99 work)
  • mto: This revision was merged to the branch mainline in revision 7521.
  • Revision ID: jelmer@jelmer.uk-20200810150017-vs7xnrd1vat4iktg
Merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
"""Converters, etc for going between Bazaar and Git ids."""
20
20
 
21
 
from __future__ import absolute_import
22
 
 
23
21
import base64
24
22
import stat
25
23
 
39
37
    NULL_REVISION,
40
38
    Revision,
41
39
    )
42
 
from ..sixish import (
43
 
    PY3,
44
 
    text_type,
45
 
    viewitems,
46
 
    )
47
40
from .errors import (
48
41
    NoPushSupport,
49
42
    )
197
190
    def generate_file_id(self, path):
198
191
        # Git paths are just bytestrings
199
192
        # We must just hope they are valid UTF-8..
200
 
        if isinstance(path, text_type):
201
 
            path = encode_git_path(path)
 
193
        if isinstance(path, str):
 
194
            path = path.encode("utf-8")
202
195
        if path == b"":
203
196
            return ROOT_ID
204
197
        return FILE_ID_PREFIX + escape_file_id(path)
210
203
            raise ValueError
211
204
        return decode_git_path(unescape_file_id(file_id[len(FILE_ID_PREFIX):]))
212
205
 
213
 
    def revid_as_refname(self, revid):
214
 
        if not isinstance(revid, bytes):
215
 
            raise TypeError(revid)
216
 
        if PY3:
217
 
            revid = revid.decode('utf-8')
218
 
        quoted_revid = urlutils.quote(revid)
219
 
        return b"refs/bzr/" + quoted_revid.encode('utf-8')
220
 
 
221
206
    def import_unusual_file_modes(self, rev, unusual_file_modes):
222
207
        if unusual_file_modes:
223
208
            ret = [(path, unusual_file_modes[path])
274
259
        (message, renames, branch, extra) = extract_hg_metadata(message)
275
260
        if branch is not None:
276
261
            rev.properties[u'hg:extra:branch'] = branch
277
 
        for name, value in viewitems(extra):
 
262
        for name, value in extra.items():
278
263
            rev.properties[u'hg:extra:' + name] = base64.b64encode(value)
279
264
        if renames:
280
265
            rev.properties[u'hg:renames'] = base64.b64encode(bencode.bencode(
281
 
                [(new, old) for (old, new) in viewitems(renames)]))
 
266
                [(new, old) for (old, new) in renames.items()]))
282
267
        return message
283
268
 
284
269
    def _extract_bzr_metadata(self, rev, message):
369
354
                 u'commit-timezone-neg-utc', u'git-implicit-encoding',
370
355
                 u'git-gpg-signature', u'git-explicit-encoding',
371
356
                 u'author-timestamp', u'file-modes'])
372
 
            for k, v in viewitems(rev.properties):
 
357
            for k, v in rev.properties.items():
373
358
                if k not in mapping_properties:
374
359
                    metadata.properties[k] = v
375
360
        if not lossy and metadata:
596
581
def symlink_to_blob(symlink_target):
597
582
    from dulwich.objects import Blob
598
583
    blob = Blob()
599
 
    if isinstance(symlink_target, text_type):
 
584
    if isinstance(symlink_target, str):
600
585
        symlink_target = encode_git_path(symlink_target)
601
586
    blob.data = symlink_target
602
587
    return blob