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