/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 branch cloning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
        )
30
30
from bzrlib.plugins.git.remote import RemoteGitRepository
31
31
 
32
 
from dulwich.client import SimpleFetchGraphWalker
33
32
from dulwich.objects import Commit
34
33
 
35
34
from cStringIO import StringIO
50
49
 
51
50
    def remove(self, revid):
52
51
        self.done.add(revid)
53
 
        if revid in self.heads:
 
52
        if ref in self.heads:
54
53
            self.heads.remove(revid)
55
54
        if revid in self.parents:
56
55
            for p in self.parents[revid]:
122
121
            raise AssertionError("Unknown blob kind, perms=%r." % (mode,))
123
122
 
124
123
 
125
 
def import_git_objects(repo, mapping, num_objects, object_iter, pb=None):
 
124
def import_git_objects(repo, mapping, object_iter, pb=None):
126
125
    """Import a set of git objects into a bzr repository.
127
126
 
128
127
    :param repo: Bazaar repository
129
128
    :param mapping: Mapping to use
130
 
    :param num_objects: Number of objects.
131
129
    :param object_iter: Iterator over Git objects.
132
130
    """
133
131
    # TODO: a more (memory-)efficient implementation of this
134
132
    objects = {}
135
133
    for i, o in enumerate(object_iter):
136
134
        if pb is not None:
137
 
            pb.update("fetching objects", i, num_objects) 
 
135
            pb.update("fetching objects", i) 
138
136
        objects[o.id] = o
139
137
    graph = []
140
138
    root_trees = {}
163
161
                return objects[sha]
164
162
            return reconstruct_git_object(repo, mapping, sha)
165
163
        parent_invs = [repo.get_inventory(r) for r in rev.parent_ids]
166
 
        import_git_tree(repo, mapping, "", root_tree, inv, parent_invs, 
167
 
            lookup_object)
 
164
        import_git_tree(repo, mapping, "", root_tree, inv, parent_invs, lookup_object)
168
165
        repo.add_revision(rev.revision_id, rev, inv)
169
166
 
170
167
 
187
184
    raise KeyError("No such object %s" % sha)
188
185
 
189
186
 
190
 
class InterGitNonGitRepository(InterRepository):
 
187
class InterGitRepository(InterRepository):
191
188
 
192
189
    _matching_repo_format = GitFormat()
193
190
 
204
201
        if mapping is None:
205
202
            mapping = self.source.get_mapping()
206
203
        def progress(text):
207
 
            pb.update("git: %s" % text.rstrip("\r\n"), 0, 0)
 
204
            pb.note("git: %s", text)
208
205
        def determine_wants(heads):
209
206
            if revision_id is None:
210
207
                ret = heads.values()
220
217
            try:
221
218
                self.target.start_write_group()
222
219
                try:
223
 
                    (num_objects, objects_iter) = \
224
 
                            self.source.fetch_objects(determine_wants, 
225
 
                                graph_walker, progress)
226
 
                    import_git_objects(self.target, mapping, num_objects, 
227
 
                                       objects_iter, pb)
 
220
                    import_git_objects(self.target, mapping,
 
221
                        iter(self.source.fetch_objects(determine_wants, graph_walker, 
 
222
                            progress)), pb)
228
223
                finally:
229
224
                    self.target.commit_write_group()
230
225
            finally:
238
233
        """Be compatible with GitRepository."""
239
234
        # FIXME: Also check target uses VersionedFile
240
235
        return (isinstance(source, GitRepository) and 
241
 
                target.supports_rich_root() and
242
 
                not isinstance(target, GitRepository))
243
 
 
244
 
 
245
 
class InterGitRepository(InterRepository):
246
 
 
247
 
    _matching_repo_format = GitFormat()
248
 
 
249
 
    @staticmethod
250
 
    def _get_repo_format_to_test():
251
 
        return None
252
 
 
253
 
    def copy_content(self, revision_id=None, pb=None):
254
 
        """See InterRepository.copy_content."""
255
 
        self.fetch(revision_id, pb, find_ghosts=False)
256
 
 
257
 
    def fetch(self, revision_id=None, pb=None, find_ghosts=False, 
258
 
              mapping=None):
259
 
        if mapping is None:
260
 
            mapping = self.source.get_mapping()
261
 
        def progress(text):
262
 
            info("git: %s", text)
263
 
        r = self.target._git
264
 
        if revision_id is None:
265
 
            determine_wants = lambda x: [y for y in x.values() if not y in r.object_store]
266
 
        else:
267
 
            args = [mapping.revision_id_bzr_to_foreign(revision_id)]
268
 
            determine_wants = lambda x: [y for y in args if not y in r.object_store]
269
 
 
270
 
        graphwalker = SimpleFetchGraphWalker(r.heads().values(), r.get_parents)
271
 
        f, commit = r.object_store.add_pack()
272
 
        try:
273
 
            self.source._git.fetch_pack(path, determine_wants, graphwalker, f.write, progress)
274
 
            f.close()
275
 
            commit()
276
 
        except:
277
 
            f.close()
278
 
            raise
279
 
 
280
 
    @staticmethod
281
 
    def is_compatible(source, target):
282
 
        """Be compatible with GitRepository."""
283
 
        return (isinstance(source, GitRepository) and 
284
 
                isinstance(target, GitRepository))
 
236
                target.supports_rich_root())