/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

Add test for option command in git-remote-helper.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
from bzrlib.revision import (
39
39
    NULL_REVISION,
40
40
    )
 
41
from bzrlib.plugins.git.errors import NoPushSupport
41
42
from bzrlib.plugins.git.hg import (
42
43
    format_hg_metadata,
43
44
    extract_hg_metadata,
45
46
from bzrlib.plugins.git.roundtrip import (
46
47
    extract_bzr_metadata,
47
48
    inject_bzr_metadata,
48
 
    BzrGitRevisionMetadata,
 
49
    CommitSupplement,
49
50
    deserialize_fileid_map,
50
51
    serialize_fileid_map,
51
52
    )
54
55
 
55
56
 
56
57
def escape_file_id(file_id):
57
 
    return file_id.replace('_', '__').replace(' ', '_s')
 
58
    return file_id.replace('_', '__').replace(' ', '_s').replace('\x0c', '_c')
58
59
 
59
60
 
60
61
def unescape_file_id(file_id):
68
69
                ret.append("_")
69
70
            elif file_id[i+1] == 's':
70
71
                ret.append(" ")
 
72
            elif file_id[i+1] == 'c':
 
73
                ret.append("\x0c")
71
74
            else:
72
75
                raise AssertionError("unknown escape character %s" %
73
76
                    file_id[i+1])
100
103
 
101
104
    BZR_DUMMY_FILE = None
102
105
 
 
106
    def is_special_file(self, filename):
 
107
        return (filename in (self.BZR_FILE_IDS_FILE, self.BZR_DUMMY_FILE))
 
108
 
103
109
    def __init__(self):
104
 
        super(BzrGitMapping, self).__init__(foreign_git)
 
110
        super(BzrGitMapping, self).__init__(foreign_vcs_git)
105
111
 
106
112
    def __eq__(self, other):
107
113
        return (type(self) == type(other) and
211
217
        return message, metadata
212
218
 
213
219
    def _decode_commit_message(self, rev, message, encoding):
214
 
        return message.decode(encoding), BzrGitRevisionMetadata()
 
220
        return message.decode(encoding), CommitSupplement()
215
221
 
216
222
    def _encode_commit_message(self, rev, message, encoding):
217
223
        return message.encode(encoding)
227
233
        b.set_raw_chunks(serialize_fileid_map(fileid_map))
228
234
        return b
229
235
 
230
 
    def export_commit(self, rev, tree_sha, parent_lookup, roundtrip,
 
236
    def export_commit(self, rev, tree_sha, parent_lookup, lossy,
231
237
                      verifiers):
232
238
        """Turn a Bazaar revision in to a Git commit
233
239
 
234
240
        :param tree_sha: Tree sha for the commit
235
241
        :param parent_lookup: Function for looking up the GIT sha equiv of a
236
242
            bzr revision
237
 
        :param roundtrip: Whether to store roundtripping information.
 
243
        :param lossy: Whether to store roundtripping information.
238
244
        :param verifiers: Verifiers info
239
245
        :return dulwich.objects.Commit represent the revision:
240
246
        """
241
247
        from dulwich.objects import Commit
242
248
        commit = Commit()
243
249
        commit.tree = tree_sha
244
 
        if roundtrip:
245
 
            metadata = BzrGitRevisionMetadata()
 
250
        if not lossy:
 
251
            metadata = CommitSupplement()
246
252
            metadata.verifiers = verifiers
247
253
        else:
248
254
            metadata = None
294
300
            for k, v in rev.properties.iteritems():
295
301
                if not k in mapping_properties:
296
302
                    metadata.properties[k] = v
297
 
        if self.roundtripping:
298
 
            commit.message = inject_bzr_metadata(commit.message, metadata, 
299
 
                                                 encoding)
 
303
        if not lossy:
 
304
            if self.roundtripping:
 
305
                commit.message = inject_bzr_metadata(commit.message, metadata, 
 
306
                                                     encoding)
 
307
            else:
 
308
                raise NoPushSupport()
300
309
        assert type(commit.message) == str
301
310
        return commit
302
311
 
318
327
            raise AssertionError("Commit object can't be None")
319
328
        rev = ForeignRevision(commit.id, self,
320
329
                self.revision_id_foreign_to_bzr(commit.id))
321
 
        rev.parent_ids = tuple([lookup_parent_revid(p) for p in commit.parents])
322
330
        rev.git_metadata = None
323
331
        def decode_using_encoding(rev, commit, encoding):
324
332
            rev.committer = str(commit.committer).decode(encoding)
349
357
            rev.properties['commit-timezone-neg-utc'] = ""
350
358
        rev.timestamp = commit.commit_time
351
359
        rev.timezone = commit.commit_timezone
 
360
        rev.parent_ids = None
352
361
        if rev.git_metadata is not None:
353
362
            md = rev.git_metadata
354
363
            roundtrip_revid = md.revision_id
359
368
        else:
360
369
            roundtrip_revid = None
361
370
            verifiers = {}
 
371
        if rev.parent_ids is None:
 
372
            rev.parent_ids = tuple([lookup_parent_revid(p) for p in commit.parents])
362
373
        return rev, roundtrip_revid, verifiers
363
374
 
364
375
    def get_fileid_map(self, lookup_object, tree_sha):
433
444
    "BzrGitMappingv1")
434
445
mapping_registry.register_lazy('git-experimental',
435
446
    "bzrlib.plugins.git.mapping", "BzrGitMappingExperimental")
 
447
# Uncomment the next line to enable the experimental bzr-git mappings.
 
448
# This will make sure all bzr metadata is pushed into git, allowing for
 
449
# full roundtripping later.
 
450
# NOTE: THIS IS EXPERIMENTAL. IT MAY EAT YOUR DATA OR CORRUPT
 
451
# YOUR BZR OR GIT REPOSITORIES. USE WITH CARE.
 
452
#mapping_registry.set_default('git-experimental')
436
453
mapping_registry.set_default('git-v1')
437
454
 
438
455
 
462
479
        return { "git commit": foreign_revid }
463
480
 
464
481
 
465
 
foreign_git = ForeignGit()
 
482
foreign_vcs_git = ForeignGit()
466
483
default_mapping = mapping_registry.get_default()()
467
484
 
468
485
 
546
563
            mode = entry_mode(ie)
547
564
        hexsha = lookup_ie_sha1(ie)
548
565
        if hexsha is not None:
549
 
            tree.add(mode, name.encode("utf-8"), hexsha)
 
566
            tree.add(name.encode("utf-8"), mode, hexsha)
550
567
    if entry.parent_id is not None and len(tree) == 0:
551
568
        # Only the root can be an empty tree
552
569
        if empty_file_name is not None:
553
 
            tree.add(stat.S_IFREG | 0644, empty_file_name, 
554
 
                Blob().id)
 
570
            tree.add(empty_file_name, stat.S_IFREG | 0644, Blob().id)
555
571
        else:
556
572
            return None
557
573
    return tree
580
596
        self.paths = None
581
597
        self.mapping = mapping
582
598
 
 
599
    def set_file_id(self, path, file_id):
 
600
        assert type(path) is str
 
601
        assert type(file_id) is str
 
602
        self.file_ids[path] = file_id
 
603
 
583
604
    def lookup_file_id(self, path):
584
605
        assert type(path) is str
585
606
        try:
601
622
        else:
602
623
            assert type(path) is str
603
624
            return path
 
625
 
 
626
    def copy(self):
 
627
        return self.__class__(dict(self.file_ids), self.mapping)