/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.358.2 by Jelmer Vernooij
Refresh copyright headers, add my email.
1
# Copyright (C) 2008-2018 Jelmer Vernooij <jelmer@jelmer.uk>
0.200.135 by Jelmer Vernooij
Add stub for fetching data.
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
0.358.1 by Jelmer Vernooij
Fix FSF address.
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.200.135 by Jelmer Vernooij
Add stub for fetching data.
16
0.358.3 by Jelmer Vernooij
Enable absolute import.
17
"""Fetching from git into bzr."""
18
0.200.261 by Jelmer Vernooij
More formatting fixes.
19
from dulwich.objects import (
20
    Commit,
0.200.303 by Jelmer Vernooij
Cope with tags during fetch.
21
    Tag,
0.200.814 by Jelmer Vernooij
Avoid the use of InventoryDirectory.children. This speeds up
22
    Tree,
0.200.1407 by Jelmer Vernooij
Don't consider submodule modes unusual.
23
    S_IFGITLINK,
0.200.540 by Jelmer Vernooij
Handle submodules explicitly.
24
    S_ISGITLINK,
0.200.1176 by Jelmer Vernooij
Fix fetch return value for inter git fetching.
25
    ZERO_SHA,
0.200.261 by Jelmer Vernooij
More formatting fixes.
26
    )
0.200.883 by Jelmer Vernooij
Add function for verifying reconstruction of objects still works.
27
from dulwich.object_store import (
28
    tree_lookup_path,
29
    )
0.200.819 by Jelmer Vernooij
Avoid decoding basename twice.
30
import posixpath
0.200.352 by Jelmer Vernooij
Simplify mode handling.
31
import stat
0.200.252 by Jelmer Vernooij
Clarify history, copyright.
32
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
33
from .. import (
0.231.2 by Jelmer Vernooij
Add -Dverify flag (not fully implemented yet).
34
    debug,
0.200.1433 by Jelmer Vernooij
Fix fetching between git repositories.
35
    errors,
0.200.252 by Jelmer Vernooij
Clarify history, copyright.
36
    osutils,
0.200.261 by Jelmer Vernooij
More formatting fixes.
37
    trace,
0.200.252 by Jelmer Vernooij
Clarify history, copyright.
38
    )
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
39
from ..errors import (
0.239.5 by Jelmer Vernooij
Print user-understandable error message when encountering submodules.
40
    BzrError,
0.200.252 by Jelmer Vernooij
Clarify history, copyright.
41
    )
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
42
from ..bzr.inventory import (
0.229.2 by Jelmer Vernooij
Initial work relying on inventory deltas.
43
    InventoryDirectory,
44
    InventoryFile,
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
45
    InventoryLink,
0.200.664 by Jelmer Vernooij
Support submodules during fetch.
46
    TreeReference,
0.200.261 by Jelmer Vernooij
More formatting fixes.
47
    )
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
48
from ..revision import (
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
49
    NULL_REVISION,
50
    )
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
51
from ..bzr.inventorytree import InventoryRevisionTree
7206.4.1 by Jelmer Vernooij
Move breezy.testament to breezy.bzr.testament.
52
from ..bzr.testament import (
0.200.1023 by Jelmer Vernooij
Set and verify testament.
53
    StrictTestament3,
54
    )
7357.1.8 by Jelmer Vernooij
Remove the InterTree object.
55
from ..tree import InterTree
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
56
from ..tsort import (
0.200.292 by Jelmer Vernooij
Fix formatting.
57
    topo_sort,
58
    )
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
59
from ..bzr.versionedfile import (
0.200.811 by Jelmer Vernooij
Use ChunkedContentFactory when possible.
60
    ChunkedContentFactory,
0.200.417 by Jelmer Vernooij
use insert_record_stream rather than add_lines.
61
    )
0.200.135 by Jelmer Vernooij
Add stub for fetching data.
62
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
63
from .mapping import (
0.200.345 by Jelmer Vernooij
Keep track of file modes to use.
64
    DEFAULT_FILE_MODE,
0.200.521 by Jelmer Vernooij
Abstract out kind mapping a bit, initial work on support tree-references.
65
    mode_is_executable,
0.200.820 by Jelmer Vernooij
Avoid relying on InventoryDirectory.children.
66
    mode_kind,
0.200.490 by Jelmer Vernooij
Warn about unusual modes and escaped XML-invalid characters.
67
    warn_unusual_mode,
0.231.2 by Jelmer Vernooij
Add -Dverify flag (not fully implemented yet).
68
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
69
from .object_store import (
0.200.852 by Jelmer Vernooij
Cache trees rather than inventories.
70
    LRUTreeCache,
0.423.1 by Jelmer Vernooij
Some performance fixes.
71
    _tree_to_objects,
0.200.456 by Jelmer Vernooij
Fix git -> git fetching.
72
    )
0.216.4 by Jelmer Vernooij
Add basic pack fetch infrastructure.
73
74
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
75
def import_git_blob(texts, mapping, path, name, hexshas,
7143.15.2 by Jelmer Vernooij
Run autopep8.
76
                    base_bzr_tree, parent_id, revision_id,
77
                    parent_bzr_trees, lookup_object, modes, store_updater,
78
                    lookup_file_id):
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
79
    """Import a git blob object into a bzr repository.
80
0.200.261 by Jelmer Vernooij
More formatting fixes.
81
    :param texts: VersionedFiles to add to
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
82
    :param path: Path in the tree
83
    :param blob: A git blob
0.229.1 by Jelmer Vernooij
Start working with inventory deltas.
84
    :return: Inventory delta for this file
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
85
    """
7027.4.8 by Jelmer Vernooij
Fix tests, drop broken tests.
86
    if not isinstance(path, bytes):
87
        raise TypeError(path)
88
    decoded_path = path.decode('utf-8')
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
89
    (base_mode, mode) = modes
90
    (base_hexsha, hexsha) = hexshas
0.200.1752 by Jelmer Vernooij
Don't traverse nested trees in WorkingTree.smart_add.
91
    if mapping.is_special_file(path):
0.252.28 by Jelmer Vernooij
Don't import control files.
92
        return []
0.200.816 by Jelmer Vernooij
Leave mode handling for blobs to import_git_blob.
93
    if base_hexsha == hexsha and base_mode == mode:
94
        # If nothing has changed since the base revision, we're done
0.200.839 by Jelmer Vernooij
Add convenience object for updating the object store caching layer.
95
        return []
7027.4.8 by Jelmer Vernooij
Fix tests, drop broken tests.
96
    file_id = lookup_file_id(decoded_path)
0.200.816 by Jelmer Vernooij
Leave mode handling for blobs to import_git_blob.
97
    if stat.S_ISLNK(mode):
0.200.320 by Jelmer Vernooij
Handle lightweight checkouts.
98
        cls = InventoryLink
99
    else:
100
        cls = InventoryFile
0.200.821 by Jelmer Vernooij
Remove last references to ID.children.
101
    ie = cls(file_id, name.decode("utf-8"), parent_id)
0.200.995 by Jelmer Vernooij
Support newer versions of bzr where only some InventoryFile/InventoryLink attributes are writable.
102
    if ie.kind == "file":
103
        ie.executable = mode_is_executable(mode)
0.200.821 by Jelmer Vernooij
Remove last references to ID.children.
104
    if base_hexsha == hexsha and mode_kind(base_mode) == mode_kind(mode):
7027.4.8 by Jelmer Vernooij
Fix tests, drop broken tests.
105
        base_exec = base_bzr_tree.is_executable(decoded_path)
0.200.995 by Jelmer Vernooij
Support newer versions of bzr where only some InventoryFile/InventoryLink attributes are writable.
106
        if ie.kind == "symlink":
7027.4.8 by Jelmer Vernooij
Fix tests, drop broken tests.
107
            ie.symlink_target = base_bzr_tree.get_symlink_target(decoded_path)
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
108
        else:
7027.4.8 by Jelmer Vernooij
Fix tests, drop broken tests.
109
            ie.text_size = base_bzr_tree.get_file_size(decoded_path)
110
            ie.text_sha1 = base_bzr_tree.get_file_sha1(decoded_path)
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
111
        if ie.kind == "symlink" or ie.executable == base_exec:
7027.4.8 by Jelmer Vernooij
Fix tests, drop broken tests.
112
            ie.revision = base_bzr_tree.get_file_revision(decoded_path)
0.200.537 by Jelmer Vernooij
Fix handling of not-executable files becoming executable without any other changes.
113
        else:
114
            blob = lookup_object(hexsha)
0.200.304 by Jelmer Vernooij
Try a bit harder to avoid fetching objects we don't need.
115
    else:
116
        blob = lookup_object(hexsha)
0.200.320 by Jelmer Vernooij
Handle lightweight checkouts.
117
        if ie.kind == "symlink":
0.200.551 by Jelmer Vernooij
Properly set InventoryEntry revision when changing symlink targets.
118
            ie.revision = None
0.200.1344 by Jelmer Vernooij
Unicode symlinks should be unicode in inventory entries.
119
            ie.symlink_target = blob.data.decode("utf-8")
0.200.320 by Jelmer Vernooij
Handle lightweight checkouts.
120
        else:
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
121
            ie.text_size = sum(map(len, blob.chunked))
0.200.830 by Jelmer Vernooij
Bump minimum dulwich version.
122
            ie.text_sha1 = osutils.sha_strings(blob.chunked)
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
123
    # Check what revision we should store
0.200.283 by Jelmer Vernooij
Avoid storing repeated texts for blobs.
124
    parent_keys = []
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
125
    for ptree in parent_bzr_trees:
7357.1.8 by Jelmer Vernooij
Remove the InterTree object.
126
        intertree = InterTree.get(ptree, base_bzr_tree)
7357.1.7 by Jelmer Vernooij
Add tests.
127
        try:
7357.1.8 by Jelmer Vernooij
Remove the InterTree object.
128
            ppath = intertree.find_source_paths(decoded_path, recurse='none')
7357.1.7 by Jelmer Vernooij
Add tests.
129
        except errors.NoSuchFile:
130
            continue
7447.1.1 by Jelmer Vernooij
Use find_previous_path rather than id2path.
131
        if ppath is None:
0.200.829 by Jelmer Vernooij
Cope with the fact that _type is gone in upstream dulwich.
132
            continue
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
133
        pkind = ptree.kind(ppath)
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
134
        if (pkind == ie.kind and
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
135
            ((pkind == "symlink" and ptree.get_symlink_target(ppath) == ie.symlink_target) or
136
             (pkind == "file" and ptree.get_file_sha1(ppath) == ie.text_sha1 and
137
                ptree.is_executable(ppath) == ie.executable))):
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
138
            # found a revision in one of the parents to use
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
139
            ie.revision = ptree.get_file_revision(ppath)
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
140
            break
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
141
        parent_key = (file_id, ptree.get_file_revision(ppath))
7183.3.1 by Martin
Fix E71* lint errors
142
        if parent_key not in parent_keys:
0.200.904 by Jelmer Vernooij
Fix inconsistent parents.
143
            parent_keys.append(parent_key)
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
144
    if ie.revision is None:
145
        # Need to store a new revision
146
        ie.revision = revision_id
0.361.1 by Jelmer Vernooij
Don't use assert.
147
        if ie.revision is None:
148
            raise ValueError("no file revision set")
0.200.698 by Jelmer Vernooij
Merge fixes for SHA1s of symlinks.
149
        if ie.kind == 'symlink':
0.200.811 by Jelmer Vernooij
Use ChunkedContentFactory when possible.
150
            chunks = []
0.200.1292 by Jelmer Vernooij
Fix repeeling objects when determining what to send.
151
        else:
0.200.830 by Jelmer Vernooij
Bump minimum dulwich version.
152
            chunks = blob.chunked
0.252.25 by Jelmer Vernooij
Reformatting.
153
        texts.insert_record_stream([
154
            ChunkedContentFactory((file_id, ie.revision),
7143.15.2 by Jelmer Vernooij
Run autopep8.
155
                                  tuple(parent_keys), ie.text_sha1, chunks)])
0.200.572 by Jelmer Vernooij
Avoid some extra path lookups.
156
    invdelta = []
0.200.820 by Jelmer Vernooij
Avoid relying on InventoryDirectory.children.
157
    if base_hexsha is not None:
7143.15.2 by Jelmer Vernooij
Run autopep8.
158
        old_path = decoded_path  # Renames are not supported yet
0.200.820 by Jelmer Vernooij
Avoid relying on InventoryDirectory.children.
159
        if stat.S_ISDIR(base_mode):
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
160
            invdelta.extend(remove_disappeared_children(
161
                base_bzr_tree, old_path, lookup_object(base_hexsha), [],
162
                lookup_object))
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
163
    else:
164
        old_path = None
7027.4.8 by Jelmer Vernooij
Fix tests, drop broken tests.
165
    invdelta.append((old_path, decoded_path, file_id, ie))
0.200.839 by Jelmer Vernooij
Add convenience object for updating the object store caching layer.
166
    if base_hexsha != hexsha:
0.275.2 by Jelmer Vernooij
Pass tuples around for cache entries, rather than inventory entries.
167
        store_updater.add_object(blob, (ie.file_id, ie.revision), path)
0.200.839 by Jelmer Vernooij
Add convenience object for updating the object store caching layer.
168
    return invdelta
0.200.261 by Jelmer Vernooij
More formatting fixes.
169
170
0.200.664 by Jelmer Vernooij
Support submodules during fetch.
171
class SubmodulesRequireSubtrees(BzrError):
0.200.1596 by Jelmer Vernooij
Don't mention development-subtree when submodules are encountered.
172
    _fmt = ("The repository you are fetching from contains submodules, "
0.404.2 by Jelmer Vernooij
Clarify error message about nested trees.
173
            "which require a Bazaar format that supports tree references.")
0.239.5 by Jelmer Vernooij
Print user-understandable error message when encountering submodules.
174
    internal = False
175
176
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
177
def import_git_submodule(texts, mapping, path, name, hexshas,
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
178
                         base_bzr_tree, parent_id, revision_id,
179
                         parent_bzr_trees, lookup_object,
7143.15.2 by Jelmer Vernooij
Run autopep8.
180
                         modes, store_updater, lookup_file_id):
0.200.1309 by Jelmer Vernooij
Break some more long lines.
181
    """Import a git submodule."""
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
182
    (base_hexsha, hexsha) = hexshas
183
    (base_mode, mode) = modes
0.200.817 by Jelmer Vernooij
Deal with all modes locally.
184
    if base_hexsha == hexsha and base_mode == mode:
0.200.839 by Jelmer Vernooij
Add convenience object for updating the object store caching layer.
185
        return [], {}
7458.1.2 by Jelmer Vernooij
Fix tests on Python 3.
186
    path = path.decode('utf-8')
0.200.896 by Jelmer Vernooij
Add separate function for looking up file ids.
187
    file_id = lookup_file_id(path)
0.200.1408 by Jelmer Vernooij
Remove old ie children when converting directory into tree reference.
188
    invdelta = []
0.200.821 by Jelmer Vernooij
Remove last references to ID.children.
189
    ie = TreeReference(file_id, name.decode("utf-8"), parent_id)
0.200.664 by Jelmer Vernooij
Support submodules during fetch.
190
    ie.revision = revision_id
0.200.1408 by Jelmer Vernooij
Remove old ie children when converting directory into tree reference.
191
    if base_hexsha is not None:
7458.1.2 by Jelmer Vernooij
Fix tests on Python 3.
192
        old_path = path  # Renames are not supported yet
0.200.1408 by Jelmer Vernooij
Remove old ie children when converting directory into tree reference.
193
        if stat.S_ISDIR(base_mode):
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
194
            invdelta.extend(remove_disappeared_children(
195
                base_bzr_tree, old_path, lookup_object(base_hexsha), [],
196
                lookup_object))
0.200.664 by Jelmer Vernooij
Support submodules during fetch.
197
    else:
0.200.1408 by Jelmer Vernooij
Remove old ie children when converting directory into tree reference.
198
        old_path = None
0.200.664 by Jelmer Vernooij
Support submodules during fetch.
199
    ie.reference_revision = mapping.revision_id_foreign_to_bzr(hexsha)
0.252.25 by Jelmer Vernooij
Reformatting.
200
    texts.insert_record_stream([
201
        ChunkedContentFactory((file_id, ie.revision), (), None, [])])
0.200.1408 by Jelmer Vernooij
Remove old ie children when converting directory into tree reference.
202
    invdelta.append((old_path, path, file_id, ie))
0.200.839 by Jelmer Vernooij
Add convenience object for updating the object store caching layer.
203
    return invdelta, {}
0.200.540 by Jelmer Vernooij
Handle submodules explicitly.
204
205
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
206
def remove_disappeared_children(base_bzr_tree, path, base_tree,
207
                                existing_children, lookup_object):
0.200.930 by Jelmer Vernooij
Add assert demonstrating 571055 and triggering it for all target formats.
208
    """Generate an inventory delta for removed children.
209
0.200.1636 by Jelmer Vernooij
Some formatting fixes.
210
    :param base_bzr_tree: Base bzr tree against which to generate the
0.200.930 by Jelmer Vernooij
Add assert demonstrating 571055 and triggering it for all target formats.
211
        inventory delta.
0.200.984 by Jelmer Vernooij
Handle non-ascii characters in filenames.
212
    :param path: Path to process (unicode)
0.200.930 by Jelmer Vernooij
Add assert demonstrating 571055 and triggering it for all target formats.
213
    :param base_tree: Git Tree base object
214
    :param existing_children: Children that still exist
215
    :param lookup_object: Lookup a git object by its SHA1
216
    :return: Inventory delta, as list
217
    """
7479.2.1 by Jelmer Vernooij
Drop python2 support.
218
    if not isinstance(path, str):
0.361.1 by Jelmer Vernooij
Don't use assert.
219
        raise TypeError(path)
0.200.552 by Jelmer Vernooij
Cope with directories becoming symlinks.
220
    ret = []
0.200.820 by Jelmer Vernooij
Avoid relying on InventoryDirectory.children.
221
    for name, mode, hexsha in base_tree.iteritems():
222
        if name in existing_children:
223
            continue
224
        c_path = posixpath.join(path, name.decode("utf-8"))
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
225
        file_id = base_bzr_tree.path2id(c_path)
0.361.1 by Jelmer Vernooij
Don't use assert.
226
        if file_id is None:
227
            raise TypeError(file_id)
0.200.930 by Jelmer Vernooij
Add assert demonstrating 571055 and triggering it for all target formats.
228
        ret.append((c_path, None, file_id, None))
0.200.820 by Jelmer Vernooij
Avoid relying on InventoryDirectory.children.
229
        if stat.S_ISDIR(mode):
230
            ret.extend(remove_disappeared_children(
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
231
                base_bzr_tree, c_path, lookup_object(hexsha), [],
232
                lookup_object))
0.200.552 by Jelmer Vernooij
Cope with directories becoming symlinks.
233
    return ret
234
235
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
236
def import_git_tree(texts, mapping, path, name, hexshas,
7143.15.2 by Jelmer Vernooij
Run autopep8.
237
                    base_bzr_tree, parent_id, revision_id, parent_bzr_trees,
238
                    lookup_object, modes, store_updater,
239
                    lookup_file_id, allow_submodules=False):
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
240
    """Import a git tree object into a bzr repository.
241
0.200.261 by Jelmer Vernooij
More formatting fixes.
242
    :param texts: VersionedFiles object to add to
0.200.984 by Jelmer Vernooij
Handle non-ascii characters in filenames.
243
    :param path: Path in the tree (str)
244
    :param name: Name of the tree (str)
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
245
    :param tree: A git tree object
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
246
    :param base_bzr_tree: Base inventory against which to return inventory
247
        delta
0.229.1 by Jelmer Vernooij
Start working with inventory deltas.
248
    :return: Inventory delta for this subtree
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
249
    """
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
250
    (base_hexsha, hexsha) = hexshas
251
    (base_mode, mode) = modes
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
252
    if not isinstance(path, bytes):
0.361.1 by Jelmer Vernooij
Don't use assert.
253
        raise TypeError(path)
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
254
    if not isinstance(name, bytes):
0.361.1 by Jelmer Vernooij
Don't use assert.
255
        raise TypeError(name)
0.200.817 by Jelmer Vernooij
Deal with all modes locally.
256
    if base_hexsha == hexsha and base_mode == mode:
257
        # If nothing has changed since the base revision, we're done
0.200.839 by Jelmer Vernooij
Add convenience object for updating the object store caching layer.
258
        return [], {}
0.200.344 by Jelmer Vernooij
Clarify names, use convenience function
259
    invdelta = []
7018.3.2 by Jelmer Vernooij
Fix some git tests.
260
    file_id = lookup_file_id(osutils.safe_unicode(path))
0.200.297 by Jelmer Vernooij
Cope with non-ascii characters in filenames (needs a test..).
261
    # We just have to hope this is indeed utf-8:
0.200.821 by Jelmer Vernooij
Remove last references to ID.children.
262
    ie = InventoryDirectory(file_id, name.decode("utf-8"), parent_id)
0.200.817 by Jelmer Vernooij
Deal with all modes locally.
263
    tree = lookup_object(hexsha)
264
    if base_hexsha is None:
265
        base_tree = None
7143.15.2 by Jelmer Vernooij
Run autopep8.
266
        old_path = None  # Newly appeared here
0.200.817 by Jelmer Vernooij
Deal with all modes locally.
267
    else:
268
        base_tree = lookup_object(base_hexsha)
7143.15.2 by Jelmer Vernooij
Run autopep8.
269
        old_path = path.decode("utf-8")  # Renames aren't supported yet
0.200.984 by Jelmer Vernooij
Handle non-ascii characters in filenames.
270
    new_path = path.decode("utf-8")
0.200.823 by Jelmer Vernooij
Simplify logic in import_git_tree a bit.
271
    if base_tree is None or type(base_tree) is not Tree:
272
        ie.revision = revision_id
0.200.984 by Jelmer Vernooij
Handle non-ascii characters in filenames.
273
        invdelta.append((old_path, new_path, ie.file_id, ie))
0.252.24 by Jelmer Vernooij
Support reading fileid map.
274
        texts.insert_record_stream([
275
            ChunkedContentFactory((ie.file_id, ie.revision), (), None, [])])
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
276
    # Remember for next time
0.200.300 by Jelmer Vernooij
Fix recursive deletion of dirs.
277
    existing_children = set()
0.200.345 by Jelmer Vernooij
Keep track of file modes to use.
278
    child_modes = {}
0.200.1147 by Jelmer Vernooij
Use Tree.items() rather than Tree.entries().
279
    for name, child_mode, child_hexsha in tree.iteritems():
0.200.820 by Jelmer Vernooij
Avoid relying on InventoryDirectory.children.
280
        existing_children.add(name)
0.200.819 by Jelmer Vernooij
Avoid decoding basename twice.
281
        child_path = posixpath.join(path, name)
0.200.814 by Jelmer Vernooij
Avoid the use of InventoryDirectory.children. This speeds up
282
        if type(base_tree) is Tree:
283
            try:
284
                child_base_mode, child_base_hexsha = base_tree[name]
285
            except KeyError:
286
                child_base_hexsha = None
287
                child_base_mode = 0
288
        else:
289
            child_base_hexsha = None
290
            child_base_mode = 0
0.200.816 by Jelmer Vernooij
Leave mode handling for blobs to import_git_blob.
291
        if stat.S_ISDIR(child_mode):
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
292
            subinvdelta, grandchildmodes = import_git_tree(
293
                texts, mapping, child_path, name,
294
                (child_base_hexsha, child_hexsha), base_bzr_tree, file_id,
295
                revision_id, parent_bzr_trees, lookup_object,
296
                (child_base_mode, child_mode), store_updater, lookup_file_id,
297
                allow_submodules=allow_submodules)
7143.15.2 by Jelmer Vernooij
Run autopep8.
298
        elif S_ISGITLINK(child_mode):  # submodule
0.200.666 by Jelmer Vernooij
Refuse to add tree references to non-subtree formats.
299
            if not allow_submodules:
300
                raise SubmodulesRequireSubtrees()
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
301
            subinvdelta, grandchildmodes = import_git_submodule(
302
                texts, mapping, child_path, name,
303
                (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)
0.200.352 by Jelmer Vernooij
Simplify mode handling.
307
        else:
0.200.1328 by Jelmer Vernooij
More test fixes.
308
            if not mapping.is_special_file(name):
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
309
                subinvdelta = import_git_blob(
310
                    texts, mapping, child_path, name,
311
                    (child_base_hexsha, child_hexsha), base_bzr_tree, file_id,
312
                    revision_id, parent_bzr_trees, lookup_object,
313
                    (child_base_mode, child_mode), store_updater,
314
                    lookup_file_id)
0.200.1328 by Jelmer Vernooij
More test fixes.
315
            else:
316
                subinvdelta = []
0.200.757 by Jelmer Vernooij
Use inventory deltas.
317
            grandchildmodes = {}
318
        child_modes.update(grandchildmodes)
319
        invdelta.extend(subinvdelta)
0.200.816 by Jelmer Vernooij
Leave mode handling for blobs to import_git_blob.
320
        if child_mode not in (stat.S_IFDIR, DEFAULT_FILE_MODE,
7143.15.2 by Jelmer Vernooij
Run autopep8.
321
                              stat.S_IFLNK, DEFAULT_FILE_MODE | 0o111,
322
                              S_IFGITLINK):
0.200.879 by Jelmer Vernooij
Fix unusual modes.
323
            child_modes[child_path] = child_mode
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
324
    # Remove any children that have disappeared
0.200.817 by Jelmer Vernooij
Deal with all modes locally.
325
    if base_tree is not None and type(base_tree) is Tree:
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
326
        invdelta.extend(remove_disappeared_children(
327
            base_bzr_tree, old_path, base_tree, existing_children,
328
            lookup_object))
0.421.6 by Jelmer Vernooij
Some more simplifications.
329
    store_updater.add_object(tree, (file_id, revision_id), path)
0.200.839 by Jelmer Vernooij
Add convenience object for updating the object store caching layer.
330
    return invdelta, child_modes
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
331
332
0.200.883 by Jelmer Vernooij
Add function for verifying reconstruction of objects still works.
333
def verify_commit_reconstruction(target_git_object_retriever, lookup_object,
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
334
                                 o, rev, ret_tree, parent_trees, mapping,
335
                                 unusual_modes, verifiers):
0.200.883 by Jelmer Vernooij
Add function for verifying reconstruction of objects still works.
336
    new_unusual_modes = mapping.export_unusual_file_modes(rev)
337
    if new_unusual_modes != unusual_modes:
338
        raise AssertionError("unusual modes don't match: %r != %r" % (
339
            unusual_modes, new_unusual_modes))
340
    # Verify that we can reconstruct the commit properly
0.200.1047 by Jelmer Vernooij
Fix -Dverify.
341
    rec_o = target_git_object_retriever._reconstruct_commit(rev, o.tree, True,
7143.15.2 by Jelmer Vernooij
Run autopep8.
342
                                                            verifiers)
0.200.883 by Jelmer Vernooij
Add function for verifying reconstruction of objects still works.
343
    if rec_o != o:
344
        raise AssertionError("Reconstructed commit differs: %r != %r" % (
345
            rec_o, o))
346
    diff = []
347
    new_objs = {}
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
348
    for path, obj, ie in _tree_to_objects(
349
            ret_tree, parent_trees, target_git_object_retriever._cache.idmap,
350
            unusual_modes, mapping.BZR_DUMMY_FILE):
0.200.883 by Jelmer Vernooij
Add function for verifying reconstruction of objects still works.
351
        old_obj_id = tree_lookup_path(lookup_object, o.tree, path)[1]
352
        new_objs[path] = obj
353
        if obj.id != old_obj_id:
354
            diff.append((path, lookup_object(old_obj_id), obj))
355
    for (path, old_obj, new_obj) in diff:
7143.15.2 by Jelmer Vernooij
Run autopep8.
356
        while (old_obj.type_name == "tree"
357
               and new_obj.type_name == "tree"
358
               and sorted(old_obj) == sorted(new_obj)):
0.200.883 by Jelmer Vernooij
Add function for verifying reconstruction of objects still works.
359
            for name in old_obj:
360
                if old_obj[name][0] != new_obj[name][0]:
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
361
                    raise AssertionError(
362
                        "Modes for %s differ: %o != %o" %
363
                        (path, old_obj[name][0], new_obj[name][0]))
0.200.883 by Jelmer Vernooij
Add function for verifying reconstruction of objects still works.
364
                if old_obj[name][1] != new_obj[name][1]:
365
                    # Found a differing child, delve deeper
366
                    path = posixpath.join(path, name)
367
                    old_obj = lookup_object(old_obj[name][1])
368
                    new_obj = new_objs[path]
369
                    break
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
370
        raise AssertionError(
371
            "objects differ for %s: %r != %r" % (path, old_obj, new_obj))
0.200.883 by Jelmer Vernooij
Add function for verifying reconstruction of objects still works.
372
373
0.200.1409 by Jelmer Vernooij
Support fetching into repositories that are stacked.
374
def ensure_inventories_in_repo(repo, trees):
375
    real_inv_vf = repo.inventories.without_fallbacks()
376
    for t in trees:
377
        revid = t.get_revision_id()
378
        if not real_inv_vf.get_parent_map([(revid, )]):
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
379
            repo.add_inventory(revid, t.root_inventory, t.get_parent_ids())
0.200.1409 by Jelmer Vernooij
Support fetching into repositories that are stacked.
380
381
0.200.679 by Jelmer Vernooij
Moving commit import functionality to a separate function.
382
def import_git_commit(repo, mapping, head, lookup_object,
7410.2.1 by Jelmer Vernooij
Allow unknown extras in git commits when just inspecting revisions, rather than importing.
383
                      target_git_object_retriever, trees_cache, strict):
0.200.679 by Jelmer Vernooij
Moving commit import functionality to a separate function.
384
    o = lookup_object(head)
0.261.5 by Jelmer Vernooij
Fix looking up of parents during fetch.
385
    # Note that this uses mapping.revision_id_foreign_to_bzr. If the parents
386
    # were bzr roundtripped revisions they would be specified in the
387
    # roundtrip data.
0.261.4 by Jelmer Vernooij
Fix tests.
388
    rev, roundtrip_revid, verifiers = mapping.import_commit(
7410.2.1 by Jelmer Vernooij
Allow unknown extras in git commits when just inspecting revisions, rather than importing.
389
        o, mapping.revision_id_foreign_to_bzr, strict)
0.200.1329 by Jelmer Vernooij
Fix more tests.
390
    if roundtrip_revid is not None:
391
        original_revid = rev.revision_id
392
        rev.revision_id = roundtrip_revid
0.200.679 by Jelmer Vernooij
Moving commit import functionality to a separate function.
393
    # We have to do this here, since we have to walk the tree and
394
    # we need to make sure to import the blobs / trees with the right
395
    # path; this may involve adding them more than once.
0.200.852 by Jelmer Vernooij
Cache trees rather than inventories.
396
    parent_trees = trees_cache.revision_trees(rev.parent_ids)
0.200.1409 by Jelmer Vernooij
Support fetching into repositories that are stacked.
397
    ensure_inventories_in_repo(repo, parent_trees)
0.200.852 by Jelmer Vernooij
Cache trees rather than inventories.
398
    if parent_trees == []:
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
399
        base_bzr_tree = trees_cache.revision_tree(NULL_REVISION)
0.200.814 by Jelmer Vernooij
Avoid the use of InventoryDirectory.children. This speeds up
400
        base_tree = None
0.200.817 by Jelmer Vernooij
Deal with all modes locally.
401
        base_mode = None
0.200.679 by Jelmer Vernooij
Moving commit import functionality to a separate function.
402
    else:
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
403
        base_bzr_tree = parent_trees[0]
0.200.814 by Jelmer Vernooij
Avoid the use of InventoryDirectory.children. This speeds up
404
        base_tree = lookup_object(o.parents[0]).tree
0.200.817 by Jelmer Vernooij
Deal with all modes locally.
405
        base_mode = stat.S_IFDIR
0.200.839 by Jelmer Vernooij
Add convenience object for updating the object store caching layer.
406
    store_updater = target_git_object_retriever._get_updater(rev)
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
407
    inv_delta, unusual_modes = import_git_tree(
408
        repo.texts, mapping, b"", b"", (base_tree, o.tree), base_bzr_tree,
409
        None, rev.revision_id, parent_trees, lookup_object,
410
        (base_mode, stat.S_IFDIR), store_updater,
7358.13.1 by Jelmer Vernooij
Drop file id roundtripping support in Git.
411
        mapping.generate_file_id,
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
412
        allow_submodules=repo._format.supports_tree_reference)
0.200.679 by Jelmer Vernooij
Moving commit import functionality to a separate function.
413
    if unusual_modes != {}:
414
        for path, mode in unusual_modes.iteritems():
415
            warn_unusual_mode(rev.foreign_revid, path, mode)
416
        mapping.import_unusual_file_modes(rev, unusual_modes)
417
    try:
418
        basis_id = rev.parent_ids[0]
419
    except IndexError:
420
        basis_id = NULL_REVISION
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
421
        base_bzr_inventory = None
422
    else:
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
423
        base_bzr_inventory = base_bzr_tree.root_inventory
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
424
    rev.inventory_sha1, inv = repo.add_inventory_by_delta(
425
        basis_id, inv_delta, rev.revision_id, rev.parent_ids,
426
        base_bzr_inventory)
0.200.1195 by Jelmer Vernooij
Cope with new StrictTestament3 arguments.
427
    ret_tree = InventoryRevisionTree(repo, inv, rev.revision_id)
0.200.1329 by Jelmer Vernooij
Fix more tests.
428
    # Check verifiers
429
    if verifiers and roundtrip_revid is not None:
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
430
        testament = StrictTestament3(rev, ret_tree)
7143.15.2 by Jelmer Vernooij
Run autopep8.
431
        calculated_verifiers = {"testament3-sha1": testament.as_sha1()}
0.200.1329 by Jelmer Vernooij
Fix more tests.
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
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
437
            rev.inventory_sha1, inv = repo.add_inventory_by_delta(
438
                basis_id, inv_delta, rev.revision_id, rev.parent_ids,
439
                base_bzr_tree)
0.200.1329 by Jelmer Vernooij
Fix more tests.
440
            ret_tree = InventoryRevisionTree(repo, inv, rev.revision_id)
0.200.1179 by Jelmer Vernooij
Avoid using verifiers for natively imported revisions, save a lot of time.
441
    else:
442
        calculated_verifiers = {}
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
443
    store_updater.add_object(o, calculated_verifiers, None)
444
    store_updater.finish()
0.200.883 by Jelmer Vernooij
Add function for verifying reconstruction of objects still works.
445
    trees_cache.add(ret_tree)
0.200.679 by Jelmer Vernooij
Moving commit import functionality to a separate function.
446
    repo.add_revision(rev.revision_id, rev)
447
    if "verify" in debug.debug_flags:
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
448
        verify_commit_reconstruction(
449
            target_git_object_retriever, lookup_object, o, rev, ret_tree,
450
            parent_trees, mapping, unusual_modes, verifiers)
0.200.679 by Jelmer Vernooij
Moving commit import functionality to a separate function.
451
452
0.248.5 by Jelmer Vernooij
Reformatting, fix dpush.
453
def import_git_objects(repo, mapping, object_iter,
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
454
                       target_git_object_retriever, heads, pb=None,
455
                       limit=None):
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
456
    """Import a set of git objects into a bzr repository.
457
0.200.483 by Jelmer Vernooij
Add NEWS entry about sha map.
458
    :param repo: Target Bazaar repository
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
459
    :param mapping: Mapping to use
460
    :param object_iter: Iterator over Git objects.
0.248.5 by Jelmer Vernooij
Reformatting, fix dpush.
461
    :return: Tuple with pack hints and last imported revision id
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
462
    """
0.200.469 by Jelmer Vernooij
Fix fetch when revisions are already present locally, just only mapped.
463
    def lookup_object(sha):
464
        try:
465
            return object_iter[sha]
466
        except KeyError:
467
            return target_git_object_retriever[sha]
0.200.158 by Jelmer Vernooij
fetch works \o/
468
    graph = []
0.200.296 by Jelmer Vernooij
Avoid iterating over all objects just to find the *Commits* to retrieve.
469
    checked = set()
0.200.734 by Jelmer Vernooij
Don't import head revision twice when pulling from Git.
470
    heads = list(set(heads))
0.200.852 by Jelmer Vernooij
Cache trees rather than inventories.
471
    trees_cache = LRUTreeCache(repo)
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
472
    # Find and convert commit objects
0.200.296 by Jelmer Vernooij
Avoid iterating over all objects just to find the *Commits* to retrieve.
473
    while heads:
474
        if pb is not None:
475
            pb.update("finding revisions to fetch", len(graph), None)
476
        head = heads.pop()
0.200.1350 by Jelmer Vernooij
Implement search_missing_revision_ids.
477
        if head == ZERO_SHA:
478
            continue
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
479
        if not isinstance(head, bytes):
0.361.1 by Jelmer Vernooij
Don't use assert.
480
            raise TypeError(head)
0.200.310 by Jelmer Vernooij
Fix pull from remote branches.
481
        try:
0.248.5 by Jelmer Vernooij
Reformatting, fix dpush.
482
            o = lookup_object(head)
0.200.310 by Jelmer Vernooij
Fix pull from remote branches.
483
        except KeyError:
484
            continue
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
485
        if isinstance(o, Commit):
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
486
            rev, roundtrip_revid, verifiers = mapping.import_commit(
7410.2.1 by Jelmer Vernooij
Allow unknown extras in git commits when just inspecting revisions, rather than importing.
487
                o, mapping.revision_id_foreign_to_bzr, strict=True)
7143.15.2 by Jelmer Vernooij
Run autopep8.
488
            if (repo.has_revision(rev.revision_id)
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
489
                    or (roundtrip_revid and
490
                        repo.has_revision(roundtrip_revid))):
0.200.295 by Jelmer Vernooij
Don't re-import revisions already fetched.
491
                continue
0.200.668 by Jelmer Vernooij
Fix some places where we were way too much memory for repositories with a large number of entries in the inventory and a large number of revisions.
492
            graph.append((o.id, o.parents))
0.200.296 by Jelmer Vernooij
Avoid iterating over all objects just to find the *Commits* to retrieve.
493
            heads.extend([p for p in o.parents if p not in checked])
0.200.303 by Jelmer Vernooij
Cope with tags during fetch.
494
        elif isinstance(o, Tag):
0.200.734 by Jelmer Vernooij
Don't import head revision twice when pulling from Git.
495
            if o.object[1] not in checked:
496
                heads.append(o.object[1])
0.200.296 by Jelmer Vernooij
Avoid iterating over all objects just to find the *Commits* to retrieve.
497
        else:
498
            trace.warning("Unable to import head object %r" % o)
0.200.668 by Jelmer Vernooij
Fix some places where we were way too much memory for repositories with a large number of entries in the inventory and a large number of revisions.
499
        checked.add(o.id)
500
    del checked
0.200.158 by Jelmer Vernooij
fetch works \o/
501
    # Order the revisions
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
502
    # Create the inventory objects
0.200.821 by Jelmer Vernooij
Remove last references to ID.children.
503
    batch_size = 1000
0.200.680 by Jelmer Vernooij
fetch revisions in batches
504
    revision_ids = topo_sort(graph)
505
    pack_hints = []
0.247.2 by Michael Hudson
this works for my tests, but i'm pretty sure it's wrong in general
506
    if limit is not None:
507
        revision_ids = revision_ids[:limit]
0.247.3 by Michael Hudson
oh, so it wasn't (particularly) wrong, but it was a bit obscure
508
    last_imported = None
0.200.680 by Jelmer Vernooij
fetch revisions in batches
509
    for offset in range(0, len(revision_ids), batch_size):
0.200.1636 by Jelmer Vernooij
Some formatting fixes.
510
        target_git_object_retriever.start_write_group()
0.200.680 by Jelmer Vernooij
fetch revisions in batches
511
        try:
0.254.33 by Jelmer Vernooij
Merge trunk.
512
            repo.start_write_group()
513
            try:
0.200.824 by Jelmer Vernooij
Commit cache data in batches as well.
514
                for i, head in enumerate(
7143.15.2 by Jelmer Vernooij
Run autopep8.
515
                        revision_ids[offset:offset + batch_size]):
0.254.33 by Jelmer Vernooij
Merge trunk.
516
                    if pb is not None:
7143.15.2 by Jelmer Vernooij
Run autopep8.
517
                        pb.update("fetching revisions", offset + i,
0.200.824 by Jelmer Vernooij
Commit cache data in batches as well.
518
                                  len(revision_ids))
0.254.33 by Jelmer Vernooij
Merge trunk.
519
                    import_git_commit(repo, mapping, head, lookup_object,
7410.2.1 by Jelmer Vernooij
Allow unknown extras in git commits when just inspecting revisions, rather than importing.
520
                                      target_git_object_retriever, trees_cache,
521
                                      strict=True)
0.254.33 by Jelmer Vernooij
Merge trunk.
522
                    last_imported = head
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
523
            except BaseException:
0.254.33 by Jelmer Vernooij
Merge trunk.
524
                repo.abort_write_group()
525
                raise
526
            else:
527
                hint = repo.commit_write_group()
528
                if hint is not None:
529
                    pack_hints.extend(hint)
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
530
        except BaseException:
0.254.33 by Jelmer Vernooij
Merge trunk.
531
            target_git_object_retriever.abort_write_group()
0.200.680 by Jelmer Vernooij
fetch revisions in batches
532
            raise
533
        else:
0.254.33 by Jelmer Vernooij
Merge trunk.
534
            target_git_object_retriever.commit_write_group()
0.247.2 by Michael Hudson
this works for my tests, but i'm pretty sure it's wrong in general
535
    return pack_hints, last_imported
0.200.141 by Jelmer Vernooij
Separate out local and remote fetching.
536
537
0.200.1001 by Jelmer Vernooij
Simplify handling of determine wants, add stub for fetch_objects().
538
class DetermineWantsRecorder(object):
539
540
    def __init__(self, actual):
541
        self.actual = actual
542
        self.wants = []
543
        self.remote_refs = {}
544
545
    def __call__(self, refs):
0.361.1 by Jelmer Vernooij
Don't use assert.
546
        if type(refs) is not dict:
547
            raise TypeError(refs)
0.200.1001 by Jelmer Vernooij
Simplify handling of determine wants, add stub for fetch_objects().
548
        self.remote_refs = refs
549
        self.wants = self.actual(refs)
550
        return self.wants