/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

More work on roundtrip push support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
104
104
        super(BzrGitMapping, self).__init__(foreign_git)
105
105
 
106
106
    def __eq__(self, other):
107
 
        return (type(self) == type(other) and 
 
107
        return (type(self) == type(other) and
108
108
                self.revid_prefix == other.revid_prefix)
109
109
 
110
110
    @classmethod
127
127
        # We must just hope they are valid UTF-8..
128
128
        if path == "":
129
129
            return ROOT_ID
 
130
        if type(path) is unicode:
 
131
            path = path.encode("utf-8")
130
132
        return escape_file_id(path)
131
133
 
132
134
    def is_control_file(self, path):
183
185
 
184
186
    def _extract_git_svn_metadata(self, rev, message):
185
187
        lines = message.split("\n")
186
 
        if not (lines[-1] == "" and lines[-2].startswith("git-svn-id:")):
 
188
        if not (lines[-1] == "" and len(lines) >= 2 and lines[-2].startswith("git-svn-id:")):
187
189
            return message
188
190
        git_svn_id = lines[-2].split(": ", 1)[1]
189
191
        rev.properties['git-svn-id'] = git_svn_id
225
227
        b.set_raw_chunks(serialize_fileid_map(fileid_map))
226
228
        return b
227
229
 
228
 
    def export_commit(self, rev, tree_sha, parent_lookup, roundtrip):
 
230
    def export_commit(self, rev, tree_sha, parent_lookup, roundtrip,
 
231
                      verifiers):
229
232
        """Turn a Bazaar revision in to a Git commit
230
233
 
231
234
        :param tree_sha: Tree sha for the commit
232
235
        :param parent_lookup: Function for looking up the GIT sha equiv of a
233
236
            bzr revision
 
237
        :param roundtrip: Whether to store roundtripping information.
 
238
        :param verifiers: Verifiers info
234
239
        :return dulwich.objects.Commit represent the revision:
235
240
        """
236
241
        from dulwich.objects import Commit
238
243
        commit.tree = tree_sha
239
244
        if roundtrip:
240
245
            metadata = BzrGitRevisionMetadata()
 
246
            metadata.verifiers = verifiers
241
247
        else:
242
248
            metadata = None
243
249
        parents = []
305
311
    def import_commit(self, commit, lookup_parent_revid):
306
312
        """Convert a git commit to a bzr revision.
307
313
 
308
 
        :return: a `bzrlib.revision.Revision` object and a 
309
 
            dictionary of path -> file ids
 
314
        :return: a `bzrlib.revision.Revision` object, foreign revid and a
 
315
            testament sha1
310
316
        """
311
317
        if commit is None:
312
318
            raise AssertionError("Commit object can't be None")
345
351
        rev.timezone = commit.commit_timezone
346
352
        if rev.git_metadata is not None:
347
353
            md = rev.git_metadata
348
 
            if md.revision_id:
349
 
                rev.revision_id = md.revision_id
 
354
            roundtrip_revid = md.revision_id
350
355
            if md.explicit_parent_ids:
351
356
                rev.parent_ids = md.explicit_parent_ids
352
357
            rev.properties.update(md.properties)
353
 
        return rev
 
358
            verifiers = md.verifiers
 
359
        else:
 
360
            roundtrip_revid = None
 
361
            verifiers = {}
 
362
        return rev, roundtrip_revid, verifiers
354
363
 
355
364
    def get_fileid_map(self, lookup_object, tree_sha):
356
365
        """Obtain a fileid map for a particular tree.
398
407
        return ret
399
408
 
400
409
    def import_commit(self, commit, lookup_parent_revid):
401
 
        rev, file_ids = super(BzrGitMappingExperimental, self).import_commit(commit, lookup_parent_revid)
 
410
        rev, roundtrip_revid, verifiers = super(BzrGitMappingExperimental, self).import_commit(commit, lookup_parent_revid)
402
411
        rev.properties['converted_revision'] = "git %s\n" % commit.id
403
 
        return rev, file_ids
 
412
        return rev, roundtrip_revid, verifiers
404
413
 
405
414
 
406
415
class GitMappingRegistry(VcsMappingRegistry):
572
581
        self.mapping = mapping
573
582
 
574
583
    def lookup_file_id(self, path):
 
584
        assert type(path) is str
575
585
        try:
576
 
            return self.file_ids[path]
 
586
            file_id = self.file_ids[path]
577
587
        except KeyError:
578
 
            return self.mapping.generate_file_id(path)
 
588
            file_id = self.mapping.generate_file_id(path)
 
589
        assert type(file_id) is str
 
590
        return file_id
579
591
 
580
592
    def lookup_path(self, file_id):
581
593
        if self.paths is None:
583
595
            for k, v in self.file_ids.iteritems():
584
596
                self.paths[v] = k
585
597
        try:
586
 
            return self.paths[file_id]
 
598
            path = self.paths[file_id]
587
599
        except KeyError:
588
600
            return self.mapping.parse_file_id(file_id)
 
601
        else:
 
602
            assert type(path) is str
 
603
            return path