/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-07-05 12:50:01 UTC
  • mfrom: (7490.40.46 work)
  • mto: (7490.40.48 work)
  • mto: This revision was merged to the branch mainline in revision 7519.
  • Revision ID: jelmer@jelmer.uk-20200705125001-7s3vo0p55szbbws7
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
 
21
23
import base64
22
24
import stat
23
25
 
37
39
    NULL_REVISION,
38
40
    Revision,
39
41
    )
 
42
from ..sixish import (
 
43
    PY3,
 
44
    text_type,
 
45
    viewitems,
 
46
    )
40
47
from .errors import (
41
48
    NoPushSupport,
42
49
    )
160
167
    """Class that maps between Git and Bazaar semantics."""
161
168
    experimental = False
162
169
 
163
 
    BZR_DUMMY_FILE = None  # type: Optional[str]
 
170
    BZR_DUMMY_FILE = None
164
171
 
165
172
    def is_special_file(self, filename):
166
173
        return (filename in (self.BZR_DUMMY_FILE, ))
190
197
    def generate_file_id(self, path):
191
198
        # Git paths are just bytestrings
192
199
        # We must just hope they are valid UTF-8..
193
 
        if isinstance(path, str):
194
 
            path = path.encode("utf-8")
 
200
        if isinstance(path, text_type):
 
201
            path = encode_git_path(path)
195
202
        if path == b"":
196
203
            return ROOT_ID
197
204
        return FILE_ID_PREFIX + escape_file_id(path)
203
210
            raise ValueError
204
211
        return decode_git_path(unescape_file_id(file_id[len(FILE_ID_PREFIX):]))
205
212
 
 
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
 
206
221
    def import_unusual_file_modes(self, rev, unusual_file_modes):
207
222
        if unusual_file_modes:
208
223
            ret = [(path, unusual_file_modes[path])
259
274
        (message, renames, branch, extra) = extract_hg_metadata(message)
260
275
        if branch is not None:
261
276
            rev.properties[u'hg:extra:branch'] = branch
262
 
        for name, value in extra.items():
 
277
        for name, value in viewitems(extra):
263
278
            rev.properties[u'hg:extra:' + name] = base64.b64encode(value)
264
279
        if renames:
265
280
            rev.properties[u'hg:renames'] = base64.b64encode(bencode.bencode(
266
 
                [(new, old) for (old, new) in renames.items()]))
 
281
                [(new, old) for (old, new) in viewitems(renames)]))
267
282
        return message
268
283
 
269
284
    def _extract_bzr_metadata(self, rev, message):
354
369
                 u'commit-timezone-neg-utc', u'git-implicit-encoding',
355
370
                 u'git-gpg-signature', u'git-explicit-encoding',
356
371
                 u'author-timestamp', u'file-modes'])
357
 
            for k, v in rev.properties.items():
 
372
            for k, v in viewitems(rev.properties):
358
373
                if k not in mapping_properties:
359
374
                    metadata.properties[k] = v
360
375
        if not lossy and metadata:
581
596
def symlink_to_blob(symlink_target):
582
597
    from dulwich.objects import Blob
583
598
    blob = Blob()
584
 
    if isinstance(symlink_target, str):
 
599
    if isinstance(symlink_target, text_type):
585
600
        symlink_target = encode_git_path(symlink_target)
586
601
    blob.data = symlink_target
587
602
    return blob