/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 formatting, remove catch-all for exceptions when opening local repositories.

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, urlutils
 
17
from bzrlib import osutils
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, inv):
 
67
def import_git_blob(repo, mapping, path, blob):
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
 
    ie = inv.add_path(path, "file", file_id)
 
78
    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
 
            tree = lookup_object(hexsha)
103
 
            import_git_tree(repo, mapping, child_path, tree, inv, lookup_object)
 
102
            import_git_tree(repo, mapping, child_path, lookup_object, inv)
104
103
        elif entry_kind == 1:
105
 
            blob = lookup_object(hexsha)
106
 
            import_git_blob(repo, mapping, child_path, blob, inv)
 
104
            import_git_blob(repo, mapping, child_path, lookup_object, inv)
107
105
        else:
108
106
            raise AssertionError("Unknown blob kind, perms=%r." % (mode,))
109
107
 
121
119
        objects[o.id] = o
122
120
    root_trees = {}
123
121
    # Find and convert commit objects
124
 
    for o in objects.itervalues():
 
122
    for o in objects.iterkeys():
125
123
        if isinstance(o, Commit):
126
124
            rev = mapping.import_commit(o)
127
 
            root_trees[rev] = objects[o.tree]
 
125
            root_trees[rev] = objects[o.tree_sha]
128
126
    # Create the inventory objects
129
127
    for rev, root_tree in root_trees.iteritems():
130
128
        # We have to do this here, since we have to walk the tree and 
131
129
        # we need to make sure to import the blobs / trees with the riht 
132
130
        # path; this may involve adding them more than once.
133
131
        inv = Inventory()
134
 
        inv.revision_id = rev.revision_id
135
132
        def lookup_object(sha):
136
133
            if sha in objects:
137
134
                return objects[sha]
138
135
            return reconstruct_git_object(repo, mapping, sha)
139
 
        import_git_tree(repo, mapping, "", root_tree, inv, lookup_object)
 
136
        import_git_tree(repo, mapping, "", tree, inv, lookup_object)
140
137
        repo.add_revision(rev.revision_id, rev, inv)
141
138
 
142
139
 
189
186
        graph_walker = BzrFetchGraphWalker(self.target, mapping)
190
187
        self.target.lock_write()
191
188
        try:
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()
 
189
            import_git_objects(self.target, mapping,
 
190
                self.source.fetch_objects(determine_wants, graph_walker, 
 
191
                    progress))
199
192
        finally:
200
193
            self.target.unlock()
201
194