/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

Fix revision_history test when no DeprecationWarning is printed and bzr 2.5
is used.

Older prereleases of bzr 2.5 didn't deprecate Branch.revision_history.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
from bzrlib.plugins.git.roundtrip import (
46
46
    extract_bzr_metadata,
47
47
    inject_bzr_metadata,
48
 
    BzrGitRevisionMetadata,
 
48
    CommitSupplement,
49
49
    deserialize_fileid_map,
50
50
    serialize_fileid_map,
51
51
    )
54
54
 
55
55
 
56
56
def escape_file_id(file_id):
57
 
    return file_id.replace('_', '__').replace(' ', '_s')
 
57
    return file_id.replace('_', '__').replace(' ', '_s').replace('\x0c', '_c')
58
58
 
59
59
 
60
60
def unescape_file_id(file_id):
68
68
                ret.append("_")
69
69
            elif file_id[i+1] == 's':
70
70
                ret.append(" ")
 
71
            elif file_id[i+1] == 'c':
 
72
                ret.append("\x0c")
71
73
            else:
72
74
                raise AssertionError("unknown escape character %s" %
73
75
                    file_id[i+1])
100
102
 
101
103
    BZR_DUMMY_FILE = None
102
104
 
 
105
    def is_special_file(self, filename):
 
106
        return (filename in (self.BZR_FILE_IDS_FILE, self.BZR_DUMMY_FILE))
 
107
 
103
108
    def __init__(self):
104
 
        super(BzrGitMapping, self).__init__(foreign_git)
 
109
        super(BzrGitMapping, self).__init__(foreign_vcs_git)
105
110
 
106
111
    def __eq__(self, other):
107
112
        return (type(self) == type(other) and
211
216
        return message, metadata
212
217
 
213
218
    def _decode_commit_message(self, rev, message, encoding):
214
 
        return message.decode(encoding), BzrGitRevisionMetadata()
 
219
        return message.decode(encoding), CommitSupplement()
215
220
 
216
221
    def _encode_commit_message(self, rev, message, encoding):
217
222
        return message.encode(encoding)
242
247
        commit = Commit()
243
248
        commit.tree = tree_sha
244
249
        if roundtrip:
245
 
            metadata = BzrGitRevisionMetadata()
 
250
            metadata = CommitSupplement()
246
251
            metadata.verifiers = verifiers
247
252
        else:
248
253
            metadata = None
318
323
            raise AssertionError("Commit object can't be None")
319
324
        rev = ForeignRevision(commit.id, self,
320
325
                self.revision_id_foreign_to_bzr(commit.id))
321
 
        rev.parent_ids = tuple([lookup_parent_revid(p) for p in commit.parents])
322
326
        rev.git_metadata = None
323
327
        def decode_using_encoding(rev, commit, encoding):
324
328
            rev.committer = str(commit.committer).decode(encoding)
349
353
            rev.properties['commit-timezone-neg-utc'] = ""
350
354
        rev.timestamp = commit.commit_time
351
355
        rev.timezone = commit.commit_timezone
 
356
        rev.parent_ids = None
352
357
        if rev.git_metadata is not None:
353
358
            md = rev.git_metadata
354
359
            roundtrip_revid = md.revision_id
359
364
        else:
360
365
            roundtrip_revid = None
361
366
            verifiers = {}
 
367
        if rev.parent_ids is None:
 
368
            rev.parent_ids = tuple([lookup_parent_revid(p) for p in commit.parents])
362
369
        return rev, roundtrip_revid, verifiers
363
370
 
364
371
    def get_fileid_map(self, lookup_object, tree_sha):
433
440
    "BzrGitMappingv1")
434
441
mapping_registry.register_lazy('git-experimental',
435
442
    "bzrlib.plugins.git.mapping", "BzrGitMappingExperimental")
 
443
#mapping_registry.set_default('git-experimental')
436
444
mapping_registry.set_default('git-v1')
437
445
 
438
446
 
462
470
        return { "git commit": foreign_revid }
463
471
 
464
472
 
465
 
foreign_git = ForeignGit()
 
473
foreign_vcs_git = ForeignGit()
466
474
default_mapping = mapping_registry.get_default()()
467
475
 
468
476
 
546
554
            mode = entry_mode(ie)
547
555
        hexsha = lookup_ie_sha1(ie)
548
556
        if hexsha is not None:
549
 
            tree.add(mode, name.encode("utf-8"), hexsha)
 
557
            tree.add(name.encode("utf-8"), mode, hexsha)
550
558
    if entry.parent_id is not None and len(tree) == 0:
551
559
        # Only the root can be an empty tree
552
560
        if empty_file_name is not None:
553
 
            tree.add(stat.S_IFREG | 0644, empty_file_name, 
554
 
                Blob().id)
 
561
            tree.add(empty_file_name, stat.S_IFREG | 0644, Blob().id)
555
562
        else:
556
563
            return None
557
564
    return tree
580
587
        self.paths = None
581
588
        self.mapping = mapping
582
589
 
 
590
    def set_file_id(self, path, file_id):
 
591
        assert type(path) is str
 
592
        assert type(file_id) is str
 
593
        self.file_ids[path] = file_id
 
594
 
583
595
    def lookup_file_id(self, path):
584
596
        assert type(path) is str
585
597
        try:
601
613
        else:
602
614
            assert type(path) is str
603
615
            return path
 
616
 
 
617
    def copy(self):
 
618
        return self.__class__(dict(self.file_ids), self.mapping)