/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

  • Committer: Jelmer Vernooij
  • Date: 2018-04-02 14:59:43 UTC
  • mto: (0.200.1913 work)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180402145943-s5jmpbvvf1x42pao
Just don't touch the URL if it's already a valid URL.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2008-2018 Jelmer Vernooij <jelmer@jelmer.uk>
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
"""Fetching from git into bzr."""
 
18
 
 
19
from __future__ import absolute_import
 
20
 
 
21
from dulwich.objects import (
 
22
    Commit,
 
23
    Tag,
 
24
    Tree,
 
25
    S_IFGITLINK,
 
26
    S_ISGITLINK,
 
27
    ZERO_SHA,
 
28
    )
 
29
from dulwich.object_store import (
 
30
    tree_lookup_path,
 
31
    )
 
32
from dulwich.walk import Walker
 
33
from itertools import (
 
34
    imap,
 
35
    )
 
36
import posixpath
 
37
import stat
 
38
 
 
39
from ... import (
 
40
    debug,
 
41
    errors,
 
42
    osutils,
 
43
    trace,
 
44
    ui,
 
45
    )
 
46
from ...errors import (
 
47
    BzrError,
 
48
    )
 
49
from ...bzr.inventory import (
 
50
    InventoryDirectory,
 
51
    InventoryFile,
 
52
    InventoryLink,
 
53
    TreeReference,
 
54
    )
 
55
from ...repository import (
 
56
    InterRepository,
 
57
    )
 
58
from ...revision import (
 
59
    NULL_REVISION,
 
60
    )
 
61
from ...bzr.inventorytree import InventoryRevisionTree
 
62
from ...testament import (
 
63
    StrictTestament3,
 
64
    )
 
65
from ...tsort import (
 
66
    topo_sort,
 
67
    )
 
68
from ...bzr.versionedfile import (
 
69
    ChunkedContentFactory,
 
70
    )
 
71
 
 
72
from .mapping import (
 
73
    DEFAULT_FILE_MODE,
 
74
    mode_is_executable,
 
75
    mode_kind,
 
76
    warn_unusual_mode,
 
77
    )
 
78
from .object_store import (
 
79
    LRUTreeCache,
 
80
    )
 
81
from .refs import (
 
82
    is_tag,
 
83
    )
 
84
from .remote import (
 
85
    RemoteGitRepository,
 
86
    )
 
87
from .repository import (
 
88
    GitRepository,
 
89
    GitRepositoryFormat,
 
90
    LocalGitRepository,
 
91
    )
 
92
 
 
93
 
 
94
def import_git_blob(texts, mapping, path, name, (base_hexsha, hexsha),
 
95
        base_bzr_tree, parent_id, revision_id,
 
96
        parent_bzr_trees, lookup_object, (base_mode, mode), store_updater,
 
97
        lookup_file_id):
 
98
    """Import a git blob object into a bzr repository.
 
99
 
 
100
    :param texts: VersionedFiles to add to
 
101
    :param path: Path in the tree
 
102
    :param blob: A git blob
 
103
    :return: Inventory delta for this file
 
104
    """
 
105
    if mapping.is_special_file(path):
 
106
        return []
 
107
    if base_hexsha == hexsha and base_mode == mode:
 
108
        # If nothing has changed since the base revision, we're done
 
109
        return []
 
110
    file_id = lookup_file_id(path)
 
111
    if stat.S_ISLNK(mode):
 
112
        cls = InventoryLink
 
113
    else:
 
114
        cls = InventoryFile
 
115
    ie = cls(file_id, name.decode("utf-8"), parent_id)
 
116
    if ie.kind == "file":
 
117
        ie.executable = mode_is_executable(mode)
 
118
    if base_hexsha == hexsha and mode_kind(base_mode) == mode_kind(mode):
 
119
        base_exec = base_bzr_tree.is_executable(path)
 
120
        if ie.kind == "symlink":
 
121
            ie.symlink_target = base_bzr_tree.get_symlink_target(path)
 
122
        else:
 
123
            ie.text_size = base_bzr_tree.get_file_size(path)
 
124
            ie.text_sha1 = base_bzr_tree.get_file_sha1(path)
 
125
        if ie.kind == "symlink" or ie.executable == base_exec:
 
126
            ie.revision = base_bzr_tree.get_file_revision(path)
 
127
        else:
 
128
            blob = lookup_object(hexsha)
 
129
    else:
 
130
        blob = lookup_object(hexsha)
 
131
        if ie.kind == "symlink":
 
132
            ie.revision = None
 
133
            ie.symlink_target = blob.data.decode("utf-8")
 
134
        else:
 
135
            ie.text_size = sum(imap(len, blob.chunked))
 
136
            ie.text_sha1 = osutils.sha_strings(blob.chunked)
 
137
    # Check what revision we should store
 
138
    parent_keys = []
 
139
    for ptree in parent_bzr_trees:
 
140
        try:
 
141
            ppath = ptree.id2path(file_id)
 
142
        except errors.NoSuchId:
 
143
            continue
 
144
        pkind = ptree.kind(ppath, file_id)
 
145
        if (pkind == ie.kind and
 
146
            ((pkind == "symlink" and ptree.get_symlink_target(ppath, file_id) == ie.symlink_target) or
 
147
             (pkind == "file" and ptree.get_file_sha1(ppath, file_id) == ie.text_sha1 and
 
148
                ptree.is_executable(ppath, file_id) == ie.executable))):
 
149
            # found a revision in one of the parents to use
 
150
            ie.revision = ptree.get_file_revision(ppath, file_id)
 
151
            break
 
152
        parent_key = (file_id, ptree.get_file_revision(ppath, file_id))
 
153
        if not parent_key in parent_keys:
 
154
            parent_keys.append(parent_key)
 
155
    if ie.revision is None:
 
156
        # Need to store a new revision
 
157
        ie.revision = revision_id
 
158
        if ie.revision is None:
 
159
            raise ValueError("no file revision set")
 
160
        if ie.kind == 'symlink':
 
161
            chunks = []
 
162
        else:
 
163
            chunks = blob.chunked
 
164
        texts.insert_record_stream([
 
165
            ChunkedContentFactory((file_id, ie.revision),
 
166
                tuple(parent_keys), ie.text_sha1, chunks)])
 
167
    invdelta = []
 
168
    if base_hexsha is not None:
 
169
        old_path = path.decode("utf-8") # Renames are not supported yet
 
170
        if stat.S_ISDIR(base_mode):
 
171
            invdelta.extend(remove_disappeared_children(base_bzr_tree, old_path,
 
172
                lookup_object(base_hexsha), [], lookup_object))
 
173
    else:
 
174
        old_path = None
 
175
    new_path = path.decode("utf-8")
 
176
    invdelta.append((old_path, new_path, file_id, ie))
 
177
    if base_hexsha != hexsha:
 
178
        store_updater.add_object(blob, (ie.file_id, ie.revision), path)
 
179
    return invdelta
 
180
 
 
181
 
 
182
class SubmodulesRequireSubtrees(BzrError):
 
183
    _fmt = ("The repository you are fetching from contains submodules, "
 
184
            "which require a Bazaar format that supports tree references.")
 
185
    internal = False
 
186
 
 
187
 
 
188
def import_git_submodule(texts, mapping, path, name, (base_hexsha, hexsha),
 
189
    base_bzr_tree, parent_id, revision_id, parent_bzr_trees, lookup_object,
 
190
    (base_mode, mode), store_updater, lookup_file_id):
 
191
    """Import a git submodule."""
 
192
    if base_hexsha == hexsha and base_mode == mode:
 
193
        return [], {}
 
194
    file_id = lookup_file_id(path)
 
195
    invdelta = []
 
196
    ie = TreeReference(file_id, name.decode("utf-8"), parent_id)
 
197
    ie.revision = revision_id
 
198
    if base_hexsha is not None:
 
199
        old_path = path.decode("utf-8") # Renames are not supported yet
 
200
        if stat.S_ISDIR(base_mode):
 
201
            invdelta.extend(remove_disappeared_children(base_bzr_tree, old_path,
 
202
                lookup_object(base_hexsha), [], lookup_object))
 
203
    else:
 
204
        old_path = None
 
205
    ie.reference_revision = mapping.revision_id_foreign_to_bzr(hexsha)
 
206
    texts.insert_record_stream([
 
207
        ChunkedContentFactory((file_id, ie.revision), (), None, [])])
 
208
    invdelta.append((old_path, path, file_id, ie))
 
209
    return invdelta, {}
 
210
 
 
211
 
 
212
def remove_disappeared_children(base_bzr_tree, path, base_tree, existing_children,
 
213
        lookup_object):
 
214
    """Generate an inventory delta for removed children.
 
215
 
 
216
    :param base_bzr_tree: Base bzr tree against which to generate the
 
217
        inventory delta.
 
218
    :param path: Path to process (unicode)
 
219
    :param base_tree: Git Tree base object
 
220
    :param existing_children: Children that still exist
 
221
    :param lookup_object: Lookup a git object by its SHA1
 
222
    :return: Inventory delta, as list
 
223
    """
 
224
    if type(path) is not unicode:
 
225
        raise TypeError(path)
 
226
    ret = []
 
227
    for name, mode, hexsha in base_tree.iteritems():
 
228
        if name in existing_children:
 
229
            continue
 
230
        c_path = posixpath.join(path, name.decode("utf-8"))
 
231
        file_id = base_bzr_tree.path2id(c_path)
 
232
        if file_id is None:
 
233
            raise TypeError(file_id)
 
234
        ret.append((c_path, None, file_id, None))
 
235
        if stat.S_ISDIR(mode):
 
236
            ret.extend(remove_disappeared_children(
 
237
                base_bzr_tree, c_path, lookup_object(hexsha), [], lookup_object))
 
238
    return ret
 
239
 
 
240
 
 
241
def import_git_tree(texts, mapping, path, name, (base_hexsha, hexsha),
 
242
        base_bzr_tree, parent_id, revision_id, parent_bzr_trees,
 
243
        lookup_object, (base_mode, mode), store_updater,
 
244
        lookup_file_id, allow_submodules=False):
 
245
    """Import a git tree object into a bzr repository.
 
246
 
 
247
    :param texts: VersionedFiles object to add to
 
248
    :param path: Path in the tree (str)
 
249
    :param name: Name of the tree (str)
 
250
    :param tree: A git tree object
 
251
    :param base_bzr_tree: Base inventory against which to return inventory delta
 
252
    :return: Inventory delta for this subtree
 
253
    """
 
254
    if type(path) is not str:
 
255
        raise TypeError(path)
 
256
    if type(name) is not str:
 
257
        raise TypeError(name)
 
258
    if base_hexsha == hexsha and base_mode == mode:
 
259
        # If nothing has changed since the base revision, we're done
 
260
        return [], {}
 
261
    invdelta = []
 
262
    file_id = lookup_file_id(path)
 
263
    # We just have to hope this is indeed utf-8:
 
264
    ie = InventoryDirectory(file_id, name.decode("utf-8"), parent_id)
 
265
    tree = lookup_object(hexsha)
 
266
    if base_hexsha is None:
 
267
        base_tree = None
 
268
        old_path = None # Newly appeared here
 
269
    else:
 
270
        base_tree = lookup_object(base_hexsha)
 
271
        old_path = path.decode("utf-8") # Renames aren't supported yet
 
272
    new_path = path.decode("utf-8")
 
273
    if base_tree is None or type(base_tree) is not Tree:
 
274
        ie.revision = revision_id
 
275
        invdelta.append((old_path, new_path, ie.file_id, ie))
 
276
        texts.insert_record_stream([
 
277
            ChunkedContentFactory((ie.file_id, ie.revision), (), None, [])])
 
278
    # Remember for next time
 
279
    existing_children = set()
 
280
    child_modes = {}
 
281
    for name, child_mode, child_hexsha in tree.iteritems():
 
282
        existing_children.add(name)
 
283
        child_path = posixpath.join(path, name)
 
284
        if type(base_tree) is Tree:
 
285
            try:
 
286
                child_base_mode, child_base_hexsha = base_tree[name]
 
287
            except KeyError:
 
288
                child_base_hexsha = None
 
289
                child_base_mode = 0
 
290
        else:
 
291
            child_base_hexsha = None
 
292
            child_base_mode = 0
 
293
        if stat.S_ISDIR(child_mode):
 
294
            subinvdelta, grandchildmodes = import_git_tree(texts, mapping,
 
295
                child_path, name, (child_base_hexsha, child_hexsha),
 
296
                base_bzr_tree, file_id, revision_id, parent_bzr_trees,
 
297
                lookup_object, (child_base_mode, child_mode), store_updater,
 
298
                lookup_file_id, allow_submodules=allow_submodules)
 
299
        elif S_ISGITLINK(child_mode): # submodule
 
300
            if not allow_submodules:
 
301
                raise SubmodulesRequireSubtrees()
 
302
            subinvdelta, grandchildmodes = import_git_submodule(texts, mapping,
 
303
                child_path, name, (child_base_hexsha, child_hexsha),
 
304
                base_bzr_tree, file_id, revision_id, parent_bzr_trees,
 
305
                lookup_object, (child_base_mode, child_mode), store_updater,
 
306
                lookup_file_id)
 
307
        else:
 
308
            if not mapping.is_special_file(name):
 
309
                subinvdelta = import_git_blob(texts, mapping, child_path, name,
 
310
                    (child_base_hexsha, child_hexsha), base_bzr_tree, file_id,
 
311
                    revision_id, parent_bzr_trees, lookup_object,
 
312
                    (child_base_mode, child_mode), store_updater, lookup_file_id)
 
313
            else:
 
314
                subinvdelta = []
 
315
            grandchildmodes = {}
 
316
        child_modes.update(grandchildmodes)
 
317
        invdelta.extend(subinvdelta)
 
318
        if child_mode not in (stat.S_IFDIR, DEFAULT_FILE_MODE,
 
319
                        stat.S_IFLNK, DEFAULT_FILE_MODE|0111,
 
320
                        S_IFGITLINK):
 
321
            child_modes[child_path] = child_mode
 
322
    # Remove any children that have disappeared
 
323
    if base_tree is not None and type(base_tree) is Tree:
 
324
        invdelta.extend(remove_disappeared_children(base_bzr_tree, old_path,
 
325
            base_tree, existing_children, lookup_object))
 
326
    store_updater.add_object(tree, (file_id, ), path)
 
327
    return invdelta, child_modes
 
328
 
 
329
 
 
330
def verify_commit_reconstruction(target_git_object_retriever, lookup_object,
 
331
    o, rev, ret_tree, parent_trees, mapping, unusual_modes, verifiers):
 
332
    new_unusual_modes = mapping.export_unusual_file_modes(rev)
 
333
    if new_unusual_modes != unusual_modes:
 
334
        raise AssertionError("unusual modes don't match: %r != %r" % (
 
335
            unusual_modes, new_unusual_modes))
 
336
    # Verify that we can reconstruct the commit properly
 
337
    rec_o = target_git_object_retriever._reconstruct_commit(rev, o.tree, True,
 
338
        verifiers)
 
339
    if rec_o != o:
 
340
        raise AssertionError("Reconstructed commit differs: %r != %r" % (
 
341
            rec_o, o))
 
342
    diff = []
 
343
    new_objs = {}
 
344
    for path, obj, ie in _tree_to_objects(ret_tree, parent_trees,
 
345
        target_git_object_retriever._cache.idmap, unusual_modes,
 
346
        mapping.BZR_DUMMY_FILE):
 
347
        old_obj_id = tree_lookup_path(lookup_object, o.tree, path)[1]
 
348
        new_objs[path] = obj
 
349
        if obj.id != old_obj_id:
 
350
            diff.append((path, lookup_object(old_obj_id), obj))
 
351
    for (path, old_obj, new_obj) in diff:
 
352
        while (old_obj.type_name == "tree" and
 
353
               new_obj.type_name == "tree" and
 
354
               sorted(old_obj) == sorted(new_obj)):
 
355
            for name in old_obj:
 
356
                if old_obj[name][0] != new_obj[name][0]:
 
357
                    raise AssertionError("Modes for %s differ: %o != %o" %
 
358
                        (path, old_obj[name][0], new_obj[name][0]))
 
359
                if old_obj[name][1] != new_obj[name][1]:
 
360
                    # Found a differing child, delve deeper
 
361
                    path = posixpath.join(path, name)
 
362
                    old_obj = lookup_object(old_obj[name][1])
 
363
                    new_obj = new_objs[path]
 
364
                    break
 
365
        raise AssertionError("objects differ for %s: %r != %r" % (path,
 
366
            old_obj, new_obj))
 
367
 
 
368
 
 
369
def ensure_inventories_in_repo(repo, trees):
 
370
    real_inv_vf = repo.inventories.without_fallbacks()
 
371
    for t in trees:
 
372
        revid = t.get_revision_id()
 
373
        if not real_inv_vf.get_parent_map([(revid, )]):
 
374
            repo.add_inventory(revid, t.inventory, t.get_parent_ids())
 
375
 
 
376
 
 
377
def import_git_commit(repo, mapping, head, lookup_object,
 
378
                      target_git_object_retriever, trees_cache):
 
379
    o = lookup_object(head)
 
380
    # Note that this uses mapping.revision_id_foreign_to_bzr. If the parents
 
381
    # were bzr roundtripped revisions they would be specified in the
 
382
    # roundtrip data.
 
383
    rev, roundtrip_revid, verifiers = mapping.import_commit(
 
384
        o, mapping.revision_id_foreign_to_bzr)
 
385
    if roundtrip_revid is not None:
 
386
        original_revid = rev.revision_id
 
387
        rev.revision_id = roundtrip_revid
 
388
    # We have to do this here, since we have to walk the tree and
 
389
    # we need to make sure to import the blobs / trees with the right
 
390
    # path; this may involve adding them more than once.
 
391
    parent_trees = trees_cache.revision_trees(rev.parent_ids)
 
392
    ensure_inventories_in_repo(repo, parent_trees)
 
393
    if parent_trees == []:
 
394
        base_bzr_tree = trees_cache.revision_tree(NULL_REVISION)
 
395
        base_tree = None
 
396
        base_mode = None
 
397
    else:
 
398
        base_bzr_tree = parent_trees[0]
 
399
        base_tree = lookup_object(o.parents[0]).tree
 
400
        base_mode = stat.S_IFDIR
 
401
    store_updater = target_git_object_retriever._get_updater(rev)
 
402
    tree_supplement = mapping.get_fileid_map(lookup_object, o.tree)
 
403
    inv_delta, unusual_modes = import_git_tree(repo.texts,
 
404
            mapping, "", "", (base_tree, o.tree), base_bzr_tree,
 
405
            None, rev.revision_id, parent_trees,
 
406
            lookup_object, (base_mode, stat.S_IFDIR), store_updater,
 
407
            tree_supplement.lookup_file_id,
 
408
            allow_submodules=getattr(repo._format, "supports_tree_reference",
 
409
                False))
 
410
    if unusual_modes != {}:
 
411
        for path, mode in unusual_modes.iteritems():
 
412
            warn_unusual_mode(rev.foreign_revid, path, mode)
 
413
        mapping.import_unusual_file_modes(rev, unusual_modes)
 
414
    try:
 
415
        basis_id = rev.parent_ids[0]
 
416
    except IndexError:
 
417
        basis_id = NULL_REVISION
 
418
        base_bzr_inventory = None
 
419
    else:
 
420
        try:
 
421
            base_bzr_inventory = base_bzr_tree.root_inventory
 
422
        except AttributeError: # bzr < 2.6
 
423
            base_bzr_inventory = base_bzr_tree.inventory
 
424
    rev.inventory_sha1, inv = repo.add_inventory_by_delta(basis_id,
 
425
              inv_delta, rev.revision_id, rev.parent_ids,
 
426
              base_bzr_inventory)
 
427
    ret_tree = InventoryRevisionTree(repo, inv, rev.revision_id)
 
428
    # Check verifiers
 
429
    if verifiers and roundtrip_revid is not None:
 
430
        testament = StrictTestament3(rev, ret_tree)
 
431
        calculated_verifiers = { "testament3-sha1": testament.as_sha1() }
 
432
        if calculated_verifiers != verifiers:
 
433
            trace.mutter("Testament SHA1 %r for %r did not match %r.",
 
434
                         calculated_verifiers["testament3-sha1"],
 
435
                         rev.revision_id, verifiers["testament3-sha1"])
 
436
            rev.revision_id = original_revid
 
437
            rev.inventory_sha1, inv = repo.add_inventory_by_delta(basis_id,
 
438
              inv_delta, rev.revision_id, rev.parent_ids, base_bzr_tree)
 
439
            ret_tree = InventoryRevisionTree(repo, inv, rev.revision_id)
 
440
    else:
 
441
        calculated_verifiers = {}
 
442
    store_updater.add_object(o, calculated_verifiers, None)
 
443
    store_updater.finish()
 
444
    trees_cache.add(ret_tree)
 
445
    repo.add_revision(rev.revision_id, rev)
 
446
    if "verify" in debug.debug_flags:
 
447
        verify_commit_reconstruction(target_git_object_retriever,
 
448
            lookup_object, o, rev, ret_tree, parent_trees, mapping,
 
449
            unusual_modes, verifiers)
 
450
 
 
451
 
 
452
def import_git_objects(repo, mapping, object_iter,
 
453
    target_git_object_retriever, heads, pb=None, limit=None):
 
454
    """Import a set of git objects into a bzr repository.
 
455
 
 
456
    :param repo: Target Bazaar repository
 
457
    :param mapping: Mapping to use
 
458
    :param object_iter: Iterator over Git objects.
 
459
    :return: Tuple with pack hints and last imported revision id
 
460
    """
 
461
    def lookup_object(sha):
 
462
        try:
 
463
            return object_iter[sha]
 
464
        except KeyError:
 
465
            return target_git_object_retriever[sha]
 
466
    graph = []
 
467
    checked = set()
 
468
    heads = list(set(heads))
 
469
    trees_cache = LRUTreeCache(repo)
 
470
    # Find and convert commit objects
 
471
    while heads:
 
472
        if pb is not None:
 
473
            pb.update("finding revisions to fetch", len(graph), None)
 
474
        head = heads.pop()
 
475
        if head == ZERO_SHA:
 
476
            continue
 
477
        if type(head) is not str:
 
478
            raise TypeError(head)
 
479
        try:
 
480
            o = lookup_object(head)
 
481
        except KeyError:
 
482
            continue
 
483
        if isinstance(o, Commit):
 
484
            rev, roundtrip_revid, verifiers = mapping.import_commit(o,
 
485
                mapping.revision_id_foreign_to_bzr)
 
486
            if (repo.has_revision(rev.revision_id) or
 
487
                (roundtrip_revid and repo.has_revision(roundtrip_revid))):
 
488
                continue
 
489
            graph.append((o.id, o.parents))
 
490
            heads.extend([p for p in o.parents if p not in checked])
 
491
        elif isinstance(o, Tag):
 
492
            if o.object[1] not in checked:
 
493
                heads.append(o.object[1])
 
494
        else:
 
495
            trace.warning("Unable to import head object %r" % o)
 
496
        checked.add(o.id)
 
497
    del checked
 
498
    # Order the revisions
 
499
    # Create the inventory objects
 
500
    batch_size = 1000
 
501
    revision_ids = topo_sort(graph)
 
502
    pack_hints = []
 
503
    if limit is not None:
 
504
        revision_ids = revision_ids[:limit]
 
505
    last_imported = None
 
506
    for offset in range(0, len(revision_ids), batch_size):
 
507
        target_git_object_retriever.start_write_group()
 
508
        try:
 
509
            repo.start_write_group()
 
510
            try:
 
511
                for i, head in enumerate(
 
512
                    revision_ids[offset:offset+batch_size]):
 
513
                    if pb is not None:
 
514
                        pb.update("fetching revisions", offset+i,
 
515
                                  len(revision_ids))
 
516
                    import_git_commit(repo, mapping, head, lookup_object,
 
517
                        target_git_object_retriever, trees_cache)
 
518
                    last_imported = head
 
519
            except:
 
520
                repo.abort_write_group()
 
521
                raise
 
522
            else:
 
523
                hint = repo.commit_write_group()
 
524
                if hint is not None:
 
525
                    pack_hints.extend(hint)
 
526
        except:
 
527
            target_git_object_retriever.abort_write_group()
 
528
            raise
 
529
        else:
 
530
            target_git_object_retriever.commit_write_group()
 
531
    return pack_hints, last_imported
 
532
 
 
533
 
 
534
class DetermineWantsRecorder(object):
 
535
 
 
536
    def __init__(self, actual):
 
537
        self.actual = actual
 
538
        self.wants = []
 
539
        self.remote_refs = {}
 
540
 
 
541
    def __call__(self, refs):
 
542
        if type(refs) is not dict:
 
543
            raise TypeError(refs)
 
544
        self.remote_refs = refs
 
545
        self.wants = self.actual(refs)
 
546
        return self.wants
 
547
 
 
548
 
 
549