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

  • Committer: Robert Collins
  • Date: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

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