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

Fix some bit of fetching.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
from bzrlib import osutils
 
17
from bzrlib import osutils, urlutils
18
18
from bzrlib.errors import InvalidRevisionId
19
19
from bzrlib.inventory import Inventory
20
20
from bzrlib.repository import InterRepository
64
64
        return None
65
65
 
66
66
 
67
 
def import_git_blob(repo, mapping, path, blob):
 
67
def import_git_blob(repo, mapping, path, blob, inv):
68
68
    """Import a git blob object into a bzr repository.
69
69
 
70
70
    :param repo: bzr repository
75
75
    repo.texts.add_lines((file_id, blob.id),
76
76
        [], #FIXME 
77
77
        osutils.split_lines(blob.data))
78
 
    inv.add_path(path, "file", file_id)
 
78
    ie = inv.add_path(path, "file", file_id)
79
79
 
80
80
 
81
81
def import_git_tree(repo, mapping, path, tree, inv, lookup_object):
99
99
        else:
100
100
            child_path = urlutils.join(path, name)
101
101
        if entry_kind == 0:
102
 
            import_git_tree(repo, mapping, child_path, lookup_object, inv)
 
102
            tree = lookup_object(hexsha)
 
103
            import_git_tree(repo, mapping, child_path, tree, inv, lookup_object)
103
104
        elif entry_kind == 1:
104
 
            import_git_blob(repo, mapping, child_path, lookup_object, inv)
 
105
            blob = lookup_object(hexsha)
 
106
            import_git_blob(repo, mapping, child_path, blob, inv)
105
107
        else:
106
108
            raise AssertionError("Unknown blob kind, perms=%r." % (mode,))
107
109
 
119
121
        objects[o.id] = o
120
122
    root_trees = {}
121
123
    # Find and convert commit objects
122
 
    for o in objects.iterkeys():
 
124
    for o in objects.itervalues():
123
125
        if isinstance(o, Commit):
124
126
            rev = mapping.import_commit(o)
125
 
            root_trees[rev] = objects[o.tree_sha]
 
127
            root_trees[rev] = objects[o.tree]
126
128
    # Create the inventory objects
127
129
    for rev, root_tree in root_trees.iteritems():
128
130
        # We have to do this here, since we have to walk the tree and 
129
131
        # we need to make sure to import the blobs / trees with the riht 
130
132
        # path; this may involve adding them more than once.
131
133
        inv = Inventory()
 
134
        inv.revision_id = rev.revision_id
132
135
        def lookup_object(sha):
133
136
            if sha in objects:
134
137
                return objects[sha]
135
138
            return reconstruct_git_object(repo, mapping, sha)
136
 
        import_git_tree(repo, mapping, "", tree, inv, lookup_object)
 
139
        import_git_tree(repo, mapping, "", root_tree, inv, lookup_object)
137
140
        repo.add_revision(rev.revision_id, rev, inv)
138
141
 
139
142
 
186
189
        graph_walker = BzrFetchGraphWalker(self.target, mapping)
187
190
        self.target.lock_write()
188
191
        try:
189
 
            import_git_objects(self.target, mapping,
190
 
                self.source.fetch_objects(determine_wants, graph_walker, 
191
 
                    progress))
 
192
            self.target.start_write_group()
 
193
            try:
 
194
                import_git_objects(self.target, mapping,
 
195
                    iter(self.source.fetch_objects(determine_wants, graph_walker, 
 
196
                        progress)))
 
197
            finally:
 
198
                self.target.commit_write_group()
192
199
        finally:
193
200
            self.target.unlock()
194
201