/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 converter.py

  • Committer: Jelmer Vernooij
  • Date: 2009-04-02 15:54:49 UTC
  • mto: (0.200.326 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20090402155449-nuqhu1fsnqk6bt0g
Check that regenerated objects have the expected sha1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import stat
24
24
 
25
25
from bzrlib import (
 
26
    errors,
26
27
    ui,
27
28
    )
28
29
 
29
30
from bzrlib.plugins.git.mapping import (
30
31
    inventory_to_tree_and_blobs,
 
32
    mapping_registry,
31
33
    revision_to_commit,
32
34
    )
33
35
from bzrlib.plugins.git.shamap import (
78
80
        rev = self.repository.get_revision(revid)
79
81
        commit_obj = revision_to_commit(rev, tree_sha,
80
82
            self._idmap._parent_lookup)
81
 
        self._idmap.add_entry(commit_obj.sha().hexdigest(), "commit",
82
 
            (revid, tree_sha))
 
83
        try:
 
84
            foreign_revid, mapping = mapping_registry.parse_revision_id(revid)
 
85
        except errors.InvalidRevisionId:
 
86
            pass
 
87
        else:
 
88
            if foreign_revid != commit_obj.id:
 
89
                raise AssertionError("recreated git commit had different sha1: expected %s, got %s" % (foreign_revid, commit_obj.id))
 
90
        self._idmap.add_entry(commit_obj.id, "commit", (revid, tree_sha))
83
91
 
84
92
    def _get_blob(self, fileid, revision):
85
93
        """Return a Git Blob object from a fileid and revision stored in bzr.
106
114
        for name, ie in inv[fileid].children.iteritems():
107
115
            if ie.kind == "directory":
108
116
                subtree = self._get_tree(inv.id2path(ie.file_id), revid, inv)
109
 
                tree.add(stat.S_IFDIR, name.encode('UTF-8'),
110
 
                    subtree.sha().hexdigest())
 
117
                tree.add(stat.S_IFDIR, name.encode('UTF-8'), subtree.id)
111
118
            elif ie.kind == "file":
112
119
                blob = self._get_blob(ie.file_id, ie.revision)
113
120
                mode = stat.S_IFREG | 0644
114
121
                if ie.executable:
115
122
                    mode |= 0111
116
 
                tree.add(mode, name.encode('UTF-8'), blob.sha().hexdigest())
 
123
                tree.add(mode, name.encode('UTF-8'), blob.id)
117
124
            elif ie.kind == "symlink":
118
125
                raise AssertionError("Symlinks not yet supported")
119
126
        tree.serialize()