/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

Clean up trailing whitespace.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
from dulwich.objects import (
18
18
    Commit,
19
19
    Tag,
20
 
    Tree,
21
20
    S_ISGITLINK,
22
21
    )
23
22
from dulwich.object_store import (
24
23
    tree_lookup_path,
25
24
    )
26
 
from itertools import (
27
 
    imap,
28
 
    )
29
 
import posixpath
30
25
import re
31
26
import stat
32
27
 
33
28
from bzrlib import (
34
29
    debug,
 
30
    lru_cache,
35
31
    osutils,
36
32
    trace,
37
33
    ui,
 
34
    urlutils,
38
35
    )
39
36
from bzrlib.errors import (
40
37
    BzrError,
57
54
    topo_sort,
58
55
    )
59
56
from bzrlib.versionedfile import (
60
 
    ChunkedContentFactory,
 
57
    FulltextContentFactory,
61
58
    )
62
59
 
63
60
from bzrlib.plugins.git.mapping import (
64
61
    DEFAULT_FILE_MODE,
65
62
    inventory_to_tree_and_blobs,
66
63
    mode_is_executable,
67
 
    mode_kind,
68
64
    squash_revision,
69
65
    warn_unusual_mode,
70
66
    )
71
67
from bzrlib.plugins.git.object_store import (
72
68
    BazaarObjectStore,
73
 
    LRUInventoryCache,
74
69
    )
75
70
from bzrlib.plugins.git.remote import (
76
71
    RemoteGitRepository,
82
77
    )
83
78
 
84
79
 
85
 
def import_git_blob(texts, mapping, path, name, (base_hexsha, hexsha), 
86
 
        base_inv, parent_id, revision_id,
87
 
        parent_invs, lookup_object, (base_mode, mode), store_updater):
 
80
MAX_INV_CACHE_SIZE = 50 * 1024 * 1024
 
81
 
 
82
 
 
83
def import_git_blob(texts, mapping, path, hexsha, base_inv, base_ie, parent_id,
 
84
    revision_id, parent_invs, shagitmap, lookup_object, executable, symlink):
88
85
    """Import a git blob object into a bzr repository.
89
86
 
90
87
    :param texts: VersionedFiles to add to
92
89
    :param blob: A git blob
93
90
    :return: Inventory delta for this file
94
91
    """
95
 
    if base_hexsha == hexsha and base_mode == mode:
96
 
        # If nothing has changed since the base revision, we're done
97
 
        return []
98
92
    file_id = mapping.generate_file_id(path)
99
 
    if stat.S_ISLNK(mode):
 
93
    if symlink:
100
94
        cls = InventoryLink
101
95
    else:
102
96
        cls = InventoryFile
103
 
    ie = cls(file_id, name.decode("utf-8"), parent_id)
104
 
    ie.executable = mode_is_executable(mode)
105
 
    if base_hexsha == hexsha and mode_kind(base_mode) == mode_kind(mode):
106
 
        base_ie = base_inv[base_inv.path2id(path)]
 
97
    # We just have to hope this is indeed utf-8:
 
98
    ie = cls(file_id, urlutils.basename(path).decode("utf-8"), parent_id)
 
99
    ie.executable = executable
 
100
    # See if this has changed at all
 
101
    if base_ie is None:
 
102
        base_sha = None
 
103
    else:
 
104
        try:
 
105
            base_sha = shagitmap.lookup_blob(file_id, base_ie.revision)
 
106
        except KeyError:
 
107
            base_sha = None
 
108
        else:
 
109
            if (base_sha == hexsha and base_ie.executable == ie.executable
 
110
                and base_ie.kind == ie.kind):
 
111
                # If nothing has changed since the base revision, we're done
 
112
                return [], []
 
113
    if base_sha == hexsha and base_ie.kind == ie.kind:
107
114
        ie.text_size = base_ie.text_size
108
115
        ie.text_sha1 = base_ie.text_sha1
109
116
        ie.symlink_target = base_ie.symlink_target
119
126
            ie.text_size = None
120
127
            ie.text_sha1 = None
121
128
        else:
122
 
            ie.text_size = sum(imap(len, blob.chunked))
123
 
            ie.text_sha1 = osutils.sha_strings(blob.chunked)
 
129
            ie.text_size = len(blob.data)
 
130
            ie.text_sha1 = osutils.sha_string(blob.data)
124
131
    # Check what revision we should store
125
132
    parent_keys = []
126
 
    for pinv in parent_invs[1:]:
127
 
        try:
128
 
            pie = pinv[file_id]
129
 
        except NoSuchId:
130
 
            continue
 
133
    for pinv in parent_invs:
 
134
        if pinv.revision_id == base_inv.revision_id:
 
135
            pie = base_ie
 
136
            if pie is None:
 
137
                continue
 
138
        else:
 
139
            try:
 
140
                pie = pinv[file_id]
 
141
            except NoSuchId:
 
142
                continue
131
143
        if pie.text_sha1 == ie.text_sha1 and pie.executable == ie.executable and pie.symlink_target == ie.symlink_target:
132
144
            # found a revision in one of the parents to use
133
145
            ie.revision = pie.revision
136
148
    if ie.revision is None:
137
149
        # Need to store a new revision
138
150
        ie.revision = revision_id
 
151
        assert file_id is not None
139
152
        assert ie.revision is not None
140
 
        if ie.kind == 'symlink':
141
 
            chunks = []
142
 
        else: 
143
 
            chunks = blob.chunked
144
 
        texts.insert_record_stream([ChunkedContentFactory((file_id, ie.revision), tuple(parent_keys), ie.text_sha1, chunks)])
 
153
        texts.insert_record_stream([FulltextContentFactory((file_id, ie.revision), tuple(parent_keys), ie.text_sha1, blob.data)])
 
154
        shamap = [(hexsha, "blob", (ie.file_id, ie.revision))]
 
155
    else:
 
156
        shamap = []
145
157
    invdelta = []
146
 
    if base_hexsha is not None:
147
 
        old_path = path # Renames are not supported yet
148
 
        if stat.S_ISDIR(base_mode):
149
 
            invdelta.extend(remove_disappeared_children(base_inv, old_path,
150
 
                lookup_object(base_hexsha), [], lookup_object))
 
158
    if base_ie is not None:
 
159
        old_path = base_inv.id2path(file_id)
 
160
        if base_ie.kind == "directory":
 
161
            invdelta.extend(remove_disappeared_children(old_path, base_ie.children, []))
151
162
    else:
152
163
        old_path = None
153
164
    invdelta.append((old_path, path, file_id, ie))
154
 
    if base_hexsha != hexsha:
155
 
        store_updater.add_object(blob, ie)
156
 
    return invdelta
 
165
    return (invdelta, shamap)
157
166
 
158
167
 
159
168
class SubmodulesRequireSubtrees(BzrError):
161
170
    internal = False
162
171
 
163
172
 
164
 
def import_git_submodule(texts, mapping, path, name, (base_hexsha, hexsha),
165
 
    base_inv, parent_id, revision_id, parent_invs, lookup_object,
166
 
    (base_mode, mode), store_updater):
167
 
    if base_hexsha == hexsha and base_mode == mode:
168
 
        return [], {}
 
173
def import_git_submodule(texts, mapping, path, hexsha, base_inv, base_ie,
 
174
    parent_id, revision_id, parent_invs, shagitmap, lookup_object):
169
175
    file_id = mapping.generate_file_id(path)
170
 
    ie = TreeReference(file_id, name.decode("utf-8"), parent_id)
 
176
    ie = TreeReference(file_id, urlutils.basename(path.decode("utf-8")),
 
177
        parent_id)
171
178
    ie.revision = revision_id
172
 
    if base_hexsha is None:
 
179
    if base_ie is None:
173
180
        oldpath = None
174
181
    else:
175
182
        oldpath = path
 
183
        if (base_ie.kind == ie.kind and
 
184
            base_ie.reference_revision == ie.reference_revision):
 
185
            ie.revision = base_ie.revision
176
186
    ie.reference_revision = mapping.revision_id_foreign_to_bzr(hexsha)
177
 
    texts.insert_record_stream([ChunkedContentFactory((file_id, ie.revision), (), None, [])])
 
187
    texts.insert_record_stream([FulltextContentFactory((file_id, ie.revision), (), None, "")])
178
188
    invdelta = [(oldpath, path, file_id, ie)]
179
 
    return invdelta, {}
180
 
 
181
 
 
182
 
def remove_disappeared_children(base_inv, path, base_tree, existing_children,
183
 
        lookup_object):
 
189
    return invdelta, {}, {}
 
190
 
 
191
 
 
192
def remove_disappeared_children(path, base_children, existing_children):
184
193
    ret = []
185
 
    for name, mode, hexsha in base_tree.iteritems():
186
 
        if name in existing_children:
187
 
            continue
188
 
        c_path = posixpath.join(path, name.decode("utf-8"))
189
 
        ret.append((c_path, None, base_inv.path2id(c_path), None))
190
 
        if stat.S_ISDIR(mode):
191
 
            ret.extend(remove_disappeared_children(
192
 
                base_inv, c_path, lookup_object(hexsha), [], lookup_object))
 
194
    deletable = [(osutils.pathjoin(path, k), v) for k,v in base_children.iteritems() if k not in existing_children]
 
195
    while deletable:
 
196
        (path, ie) = deletable.pop()
 
197
        ret.append((path, None, ie.file_id, None))
 
198
        if ie.kind == "directory":
 
199
            for name, child_ie in ie.children.iteritems():
 
200
                deletable.append((osutils.pathjoin(path, name), child_ie))
193
201
    return ret
194
202
 
195
203
 
196
 
def import_git_tree(texts, mapping, path, name, (base_hexsha, hexsha),
197
 
        base_inv, parent_id, revision_id, parent_invs,
198
 
    lookup_object, (base_mode, mode), store_updater, allow_submodules=False):
 
204
def import_git_tree(texts, mapping, path, hexsha, base_inv, base_ie, parent_id,
 
205
    revision_id, parent_invs, shagitmap, lookup_object, allow_submodules=False):
199
206
    """Import a git tree object into a bzr repository.
200
207
 
201
208
    :param texts: VersionedFiles object to add to
204
211
    :param base_inv: Base inventory against which to return inventory delta
205
212
    :return: Inventory delta for this subtree
206
213
    """
207
 
    if base_hexsha == hexsha and base_mode == mode:
208
 
        # If nothing has changed since the base revision, we're done
209
 
        return [], {}
210
214
    invdelta = []
211
215
    file_id = mapping.generate_file_id(path)
212
216
    # We just have to hope this is indeed utf-8:
213
 
    ie = InventoryDirectory(file_id, name.decode("utf-8"), parent_id)
214
 
    tree = lookup_object(hexsha)
215
 
    if base_hexsha is None:
216
 
        base_tree = None
217
 
        old_path = None # Newly appeared here
218
 
    else:
219
 
        base_tree = lookup_object(base_hexsha)
220
 
        old_path = path # Renames aren't supported yet
221
 
    if base_tree is None or type(base_tree) is not Tree:
 
217
    ie = InventoryDirectory(file_id, urlutils.basename(path.decode("utf-8")),
 
218
        parent_id)
 
219
    if base_ie is None:
 
220
        # Newly appeared here
222
221
        ie.revision = revision_id
223
 
        invdelta.append((old_path, path, ie.file_id, ie))
224
 
        texts.insert_record_stream([ChunkedContentFactory((ie.file_id, ie.revision), (), None, [])])
 
222
        texts.insert_record_stream([FulltextContentFactory((file_id, ie.revision), (), None, "")])
 
223
        invdelta.append((None, path, file_id, ie))
 
224
    else:
 
225
        # See if this has changed at all
 
226
        try:
 
227
            base_sha = shagitmap.lookup_tree(file_id, base_inv.revision_id)
 
228
        except KeyError:
 
229
            pass
 
230
        else:
 
231
            if base_sha == hexsha:
 
232
                # If nothing has changed since the base revision, we're done
 
233
                return [], {}, []
 
234
        if base_ie.kind != "directory":
 
235
            ie.revision = revision_id
 
236
            texts.insert_record_stream([FulltextContentFactory((ie.file_id, ie.revision), (), None, "")])
 
237
            invdelta.append((base_inv.id2path(ie.file_id), path, ie.file_id, ie))
 
238
    if base_ie is not None and base_ie.kind == "directory":
 
239
        base_children = base_ie.children
 
240
    else:
 
241
        base_children = {}
225
242
    # Remember for next time
226
243
    existing_children = set()
227
244
    child_modes = {}
228
 
    for child_mode, name, child_hexsha in tree.entries():
229
 
        existing_children.add(name)
230
 
        child_path = posixpath.join(path, name)
231
 
        if type(base_tree) is Tree:
232
 
            try:
233
 
                child_base_mode, child_base_hexsha = base_tree[name]
234
 
            except KeyError:
235
 
                child_base_hexsha = None
236
 
                child_base_mode = 0
237
 
        else:
238
 
            child_base_hexsha = None
239
 
            child_base_mode = 0
240
 
        if stat.S_ISDIR(child_mode):
241
 
            subinvdelta, grandchildmodes = import_git_tree(
242
 
                    texts, mapping, child_path, name,
243
 
                    (child_base_hexsha, child_hexsha),
244
 
                    base_inv, file_id, revision_id, parent_invs, lookup_object,
245
 
                    (child_base_mode, child_mode), store_updater,
 
245
    shamap = []
 
246
    tree = lookup_object(hexsha)
 
247
    for mode, name, child_hexsha in tree.entries():
 
248
        basename = name.decode("utf-8")
 
249
        existing_children.add(basename)
 
250
        child_path = osutils.pathjoin(path, name)
 
251
        if stat.S_ISDIR(mode):
 
252
            subinvdelta, grandchildmodes, subshamap = import_git_tree(
 
253
                    texts, mapping, child_path, child_hexsha, base_inv,
 
254
                    base_children.get(basename), file_id, revision_id,
 
255
                    parent_invs, shagitmap, lookup_object,
246
256
                    allow_submodules=allow_submodules)
247
 
        elif S_ISGITLINK(child_mode): # submodule
 
257
            invdelta.extend(subinvdelta)
 
258
            child_modes.update(grandchildmodes)
 
259
            shamap.extend(subshamap)
 
260
        elif S_ISGITLINK(mode): # submodule
248
261
            if not allow_submodules:
249
262
                raise SubmodulesRequireSubtrees()
250
 
            subinvdelta, grandchildmodes = import_git_submodule(
251
 
                    texts, mapping, child_path, name,
252
 
                    (child_base_hexsha, child_hexsha),
253
 
                    base_inv, file_id, revision_id, parent_invs, lookup_object,
254
 
                    (child_base_mode, child_mode), store_updater)
 
263
            subinvdelta, grandchildmodes, subshamap = import_git_submodule(
 
264
                    texts, mapping, child_path, child_hexsha, base_inv, base_children.get(basename),
 
265
                    file_id, revision_id, parent_invs, shagitmap, lookup_object)
 
266
            invdelta.extend(subinvdelta)
 
267
            child_modes.update(grandchildmodes)
 
268
            shamap.extend(subshamap)
255
269
        else:
256
 
            subinvdelta = import_git_blob(texts, mapping,
257
 
                    child_path, name, (child_base_hexsha, child_hexsha),
258
 
                    base_inv, file_id, revision_id, parent_invs, lookup_object,
259
 
                    (child_base_mode, child_mode), store_updater)
260
 
            grandchildmodes = {}
261
 
        child_modes.update(grandchildmodes)
262
 
        invdelta.extend(subinvdelta)
263
 
        if child_mode not in (stat.S_IFDIR, DEFAULT_FILE_MODE,
 
270
            subinvdelta, subshamap = import_git_blob(texts, mapping,
 
271
                    child_path, child_hexsha, base_inv, base_children.get(basename), file_id,
 
272
                    revision_id, parent_invs, shagitmap, lookup_object,
 
273
                    mode_is_executable(mode), stat.S_ISLNK(mode))
 
274
            invdelta.extend(subinvdelta)
 
275
            shamap.extend(subshamap)
 
276
        if mode not in (stat.S_IFDIR, DEFAULT_FILE_MODE,
264
277
                        stat.S_IFLNK, DEFAULT_FILE_MODE|0111):
265
 
            child_modes[child_path] = child_mode
 
278
            child_modes[child_path] = mode
266
279
    # Remove any children that have disappeared
267
 
    if base_tree is not None and type(base_tree) is Tree:
268
 
        invdelta.extend(remove_disappeared_children(base_inv, old_path, 
269
 
            base_tree, existing_children, lookup_object))
270
 
    store_updater.add_object(tree, ie)
271
 
    return invdelta, child_modes
 
280
    if base_ie is not None and base_ie.kind == "directory":
 
281
        invdelta.extend(remove_disappeared_children(base_inv.id2path(file_id),
 
282
            base_children, existing_children))
 
283
    shamap.append((hexsha, "tree", (file_id, revision_id)))
 
284
    return invdelta, child_modes, shamap
 
285
 
 
286
 
 
287
def approx_inv_size(inv):
 
288
    # Very rough estimate, 1k per inventory entry
 
289
    return len(inv) * 1024
272
290
 
273
291
 
274
292
def import_git_commit(repo, mapping, head, lookup_object,
278
296
    # We have to do this here, since we have to walk the tree and
279
297
    # we need to make sure to import the blobs / trees with the right
280
298
    # path; this may involve adding them more than once.
281
 
    parent_invs = parent_invs_cache.get_inventories(rev.parent_ids)
 
299
    parent_invs = []
 
300
    for parent_id in rev.parent_ids:
 
301
        try:
 
302
            parent_invs.append(parent_invs_cache[parent_id])
 
303
        except KeyError:
 
304
            parent_inv = repo.get_inventory(parent_id)
 
305
            parent_invs.append(parent_inv)
 
306
            parent_invs_cache[parent_id] = parent_inv
282
307
    if parent_invs == []:
283
308
        base_inv = Inventory(root_id=None)
284
 
        base_tree = None
285
 
        base_mode = None
 
309
        base_ie = None
286
310
    else:
287
311
        base_inv = parent_invs[0]
288
 
        base_tree = lookup_object(o.parents[0]).tree
289
 
        base_mode = stat.S_IFDIR
290
 
    store_updater = target_git_object_retriever._get_updater(rev)
291
 
    store_updater.add_object(o, None)
292
 
    inv_delta, unusual_modes = import_git_tree(repo.texts,
293
 
            mapping, "", u"", (base_tree, o.tree), base_inv, 
294
 
            None, rev.revision_id, parent_invs, lookup_object,
295
 
            (base_mode, stat.S_IFDIR), store_updater,
 
312
        base_ie = base_inv.root
 
313
    inv_delta, unusual_modes, shamap = import_git_tree(repo.texts,
 
314
            mapping, "", o.tree, base_inv, base_ie, None, rev.revision_id,
 
315
            parent_invs, target_git_object_retriever._idmap, lookup_object,
296
316
            allow_submodules=getattr(repo._format, "supports_tree_reference", False))
297
 
    store_updater.finish()
 
317
    target_git_object_retriever._idmap.add_entries(shamap)
298
318
    if unusual_modes != {}:
299
319
        for path, mode in unusual_modes.iteritems():
300
320
            warn_unusual_mode(rev.foreign_revid, path, mode)
307
327
    rev.inventory_sha1, inv = repo.add_inventory_by_delta(basis_id,
308
328
              inv_delta, rev.revision_id, rev.parent_ids,
309
329
              base_inv)
310
 
    parent_invs_cache.add(rev.revision_id, inv)
 
330
    parent_invs_cache[rev.revision_id] = inv
311
331
    repo.add_revision(rev.revision_id, rev)
312
332
    if "verify" in debug.debug_flags:
313
333
        new_unusual_modes = mapping.export_unusual_file_modes(rev)
314
334
        if new_unusual_modes != unusual_modes:
315
335
            raise AssertionError("unusual modes don't match: %r != %r" % (unusual_modes, new_unusual_modes))
316
336
        objs = inventory_to_tree_and_blobs(inv, repo.texts, mapping, unusual_modes)
317
 
        for newsha1, newobj, path in objs:
 
337
        for sha1, newobj, path in objs:
318
338
            assert path is not None
319
 
            if path == "":
320
 
                oldsha1 = o.tree
321
 
            else:
322
 
                (oldmode, oldsha1) = tree_lookup_path(lookup_object, o.tree, path)
323
 
            if oldsha1 != newsha1:
324
 
                raise AssertionError("%r != %r in %s" % (oldsha1, newsha1, path))
325
 
 
326
 
 
327
 
def import_git_objects(repo, mapping, object_iter,
328
 
    target_git_object_retriever, heads, pb=None, limit=None):
 
339
            oldobj = tree_lookup_path(lookup_object, o.tree, path)
 
340
            if oldobj != newobj:
 
341
                raise AssertionError("%r != %r in %s" % (oldobj, newobj, path))
 
342
 
 
343
 
 
344
def import_git_objects(repo, mapping, object_iter, target_git_object_retriever,
 
345
        heads, pb=None):
329
346
    """Import a set of git objects into a bzr repository.
330
347
 
331
348
    :param repo: Target Bazaar repository
332
349
    :param mapping: Mapping to use
333
350
    :param object_iter: Iterator over Git objects.
334
 
    :return: Tuple with pack hints and last imported revision id
335
351
    """
 
352
    target_git_object_retriever._idmap.start_write_group() # FIXME: try/finally
336
353
    def lookup_object(sha):
337
354
        try:
338
355
            return object_iter[sha]
339
356
        except KeyError:
340
357
            return target_git_object_retriever[sha]
 
358
    # TODO: a more (memory-)efficient implementation of this
341
359
    graph = []
342
360
    checked = set()
343
 
    heads = list(set(heads))
344
 
    parent_invs_cache = LRUInventoryCache(repo)
 
361
    heads = list(heads)
 
362
    parent_invs_cache = lru_cache.LRUSizeCache(compute_size=approx_inv_size,
 
363
                                               max_size=MAX_INV_CACHE_SIZE)
345
364
    # Find and convert commit objects
346
365
    while heads:
347
366
        if pb is not None:
351
370
        try:
352
371
            o = lookup_object(head)
353
372
        except KeyError:
 
373
            trace.mutter('missing head %s', head)
354
374
            continue
355
375
        if isinstance(o, Commit):
356
376
            rev = mapping.import_commit(o)
358
378
                continue
359
379
            squash_revision(repo, rev)
360
380
            graph.append((o.id, o.parents))
 
381
            target_git_object_retriever._idmap.add_entry(o.id, "commit",
 
382
                    (rev.revision_id, o.tree))
361
383
            heads.extend([p for p in o.parents if p not in checked])
362
384
        elif isinstance(o, Tag):
363
 
            if o.object[1] not in checked:
364
 
                heads.append(o.object[1])
 
385
            heads.append(o.object[1])
365
386
        else:
366
387
            trace.warning("Unable to import head object %r" % o)
367
388
        checked.add(o.id)
368
389
    del checked
369
390
    # Order the revisions
370
391
    # Create the inventory objects
371
 
    batch_size = 1000
 
392
    batch_size = 100
372
393
    revision_ids = topo_sort(graph)
373
394
    pack_hints = []
374
 
    if limit is not None:
375
 
        revision_ids = revision_ids[:limit]
376
 
    last_imported = None
377
395
    for offset in range(0, len(revision_ids), batch_size):
378
 
        target_git_object_retriever.start_write_group() 
 
396
        repo.start_write_group()
379
397
        try:
380
 
            repo.start_write_group()
381
 
            try:
382
 
                for i, head in enumerate(
383
 
                    revision_ids[offset:offset+batch_size]):
384
 
                    if pb is not None:
385
 
                        pb.update("fetching revisions", offset+i,
386
 
                                  len(revision_ids))
387
 
                    import_git_commit(repo, mapping, head, lookup_object,
388
 
                                      target_git_object_retriever,
389
 
                                      parent_invs_cache)
390
 
                    last_imported = head
391
 
            except:
392
 
                repo.abort_write_group()
393
 
                raise
394
 
            else:
395
 
                hint = repo.commit_write_group()
396
 
                if hint is not None:
397
 
                    pack_hints.extend(hint)
 
398
            for i, head in enumerate(revision_ids[offset:offset+batch_size]):
 
399
                if pb is not None:
 
400
                    pb.update("fetching revisions", offset+i, len(revision_ids))
 
401
                import_git_commit(repo, mapping, head, lookup_object,
 
402
                                  target_git_object_retriever,
 
403
                                  parent_invs_cache)
398
404
        except:
399
 
            target_git_object_retriever.abort_write_group()
 
405
            repo.abort_write_group()
400
406
            raise
401
407
        else:
402
 
            target_git_object_retriever.commit_write_group()
403
 
    return pack_hints, last_imported
 
408
            hint = repo.commit_write_group()
 
409
            if hint is not None:
 
410
                pack_hints.extend(hint)
 
411
    target_git_object_retriever._idmap.commit_write_group()
 
412
    return pack_hints
404
413
 
405
414
 
406
415
class InterGitRepository(InterRepository):
415
424
        """See InterRepository.copy_content."""
416
425
        self.fetch(revision_id, pb, find_ghosts=False)
417
426
 
418
 
    def fetch(self, revision_id=None, pb=None, find_ghosts=False,
419
 
        mapping=None, fetch_spec=None):
420
 
        self.fetch_refs(revision_id=revision_id, pb=pb,
421
 
            find_ghosts=find_ghosts, mapping=mapping, fetch_spec=fetch_spec)
 
427
    def fetch(self, revision_id=None, pb=None, find_ghosts=False, mapping=None,
 
428
            fetch_spec=None):
 
429
        self.fetch_refs(revision_id=revision_id, pb=pb, find_ghosts=find_ghosts,
 
430
                mapping=mapping, fetch_spec=fetch_spec)
422
431
 
423
432
 
424
433
class InterGitNonGitRepository(InterGitRepository):
443
452
            else:
444
453
                ret = [mapping.revision_id_bzr_to_foreign(revid)[0] for revid in interesting_heads if revid not in (None, NULL_REVISION)]
445
454
            return [rev for rev in ret if not self.target.has_revision(mapping.revision_id_foreign_to_bzr(rev))]
446
 
        (pack_hint, _) = self.fetch_objects(determine_wants, mapping, pb)
 
455
        pack_hint = self.fetch_objects(determine_wants, mapping, pb)
447
456
        if pack_hint is not None and self.target._format.pack_compresses:
448
457
            self.target.pack(hint=pack_hint)
449
458
        if interesting_heads is not None:
477
486
        map(all_parents.update, parent_map.itervalues())
478
487
        return set(all_revs) - all_parents
479
488
 
480
 
    def fetch_objects(self, determine_wants, mapping, pb=None, limit=None):
 
489
    def fetch_objects(self, determine_wants, mapping, pb=None):
481
490
        def progress(text):
482
491
            report_git_progress(pb, text)
483
492
        store = BazaarObjectStore(self.target, mapping)
501
510
                            record_determine_wants, graph_walker,
502
511
                            store.get_raw, progress)
503
512
                return import_git_objects(self.target, mapping,
504
 
                    objects_iter, store, recorded_wants, pb, limit)
 
513
                    objects_iter, store, recorded_wants, pb)
505
514
            finally:
506
515
                if create_pb:
507
516
                    create_pb.finished()
521
530
    """InterRepository that copies revisions from a local Git into a non-Git
522
531
    repository."""
523
532
 
524
 
    def fetch_objects(self, determine_wants, mapping, pb=None, limit=None):
525
 
        """Fetch objects.
526
 
        """
 
533
    def fetch_objects(self, determine_wants, mapping, pb=None):
527
534
        wants = determine_wants(self.source._git.get_refs())
528
535
        create_pb = None
529
536
        if pb is None:
533
540
            self.target.lock_write()
534
541
            try:
535
542
                return import_git_objects(self.target, mapping,
536
 
                    self.source._git.object_store,
537
 
                    target_git_object_retriever, wants, pb, limit)
 
543
                    self.source._git.object_store, target_git_object_retriever,
 
544
                    wants, pb)
538
545
            finally:
539
546
                self.target.unlock()
540
547
        finally:
593
600
            determine_wants = r.object_store.determine_wants_all
594
601
        else:
595
602
            determine_wants = lambda x: [y for y in args if not y in r.object_store]
596
 
        return self.fetch_objects(determine_wants, mapping)[0]
 
603
        return self.fetch_objects(determine_wants, mapping)
597
604
 
598
605
 
599
606
    @staticmethod