/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.910 by Jelmer Vernooij
update copyright years
1
# Copyright (C) 2008-2010 Jelmer Vernooij <jelmer@samba.org>
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
0.200.1594 by Jelmer Vernooij
Use absolute_import everywhere.
17
from __future__ import absolute_import
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.1350 by Jelmer Vernooij
Implement search_missing_revision_ids.
30
from dulwich.walk import Walker
0.200.830 by Jelmer Vernooij
Bump minimum dulwich version.
31
from itertools import (
32
    imap,
33
    )
0.200.819 by Jelmer Vernooij
Avoid decoding basename twice.
34
import posixpath
0.200.563 by Jelmer Vernooij
Attempt to parse progress indication from git status reports.
35
import re
0.200.352 by Jelmer Vernooij
Simplify mode handling.
36
import stat
0.200.252 by Jelmer Vernooij
Clarify history, copyright.
37
38
from bzrlib import (
0.231.2 by Jelmer Vernooij
Add -Dverify flag (not fully implemented yet).
39
    debug,
0.200.1433 by Jelmer Vernooij
Fix fetching between git repositories.
40
    errors,
0.200.252 by Jelmer Vernooij
Clarify history, copyright.
41
    osutils,
0.200.261 by Jelmer Vernooij
More formatting fixes.
42
    trace,
0.200.252 by Jelmer Vernooij
Clarify history, copyright.
43
    ui,
44
    )
45
from bzrlib.errors import (
0.239.5 by Jelmer Vernooij
Print user-understandable error message when encountering submodules.
46
    BzrError,
0.200.252 by Jelmer Vernooij
Clarify history, copyright.
47
    )
0.200.261 by Jelmer Vernooij
More formatting fixes.
48
from bzrlib.inventory import (
0.229.2 by Jelmer Vernooij
Initial work relying on inventory deltas.
49
    InventoryDirectory,
50
    InventoryFile,
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
51
    InventoryLink,
0.200.664 by Jelmer Vernooij
Support submodules during fetch.
52
    TreeReference,
0.200.261 by Jelmer Vernooij
More formatting fixes.
53
    )
54
from bzrlib.repository import (
55
    InterRepository,
56
    )
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
57
from bzrlib.revision import (
58
    NULL_REVISION,
59
    )
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
60
from bzrlib.revisiontree import InventoryRevisionTree
0.200.1023 by Jelmer Vernooij
Set and verify testament.
61
from bzrlib.testament import (
62
    StrictTestament3,
63
    )
0.200.292 by Jelmer Vernooij
Fix formatting.
64
from bzrlib.tsort import (
65
    topo_sort,
66
    )
0.200.417 by Jelmer Vernooij
use insert_record_stream rather than add_lines.
67
from bzrlib.versionedfile import (
0.200.811 by Jelmer Vernooij
Use ChunkedContentFactory when possible.
68
    ChunkedContentFactory,
0.200.417 by Jelmer Vernooij
use insert_record_stream rather than add_lines.
69
    )
0.200.135 by Jelmer Vernooij
Add stub for fetching data.
70
0.200.1403 by Jelmer Vernooij
Cope with tags pointing at tree objects when cloning local git repositories.
71
from bzrlib.plugins.git.errors import (
72
    NotCommitError,
73
    )
0.231.2 by Jelmer Vernooij
Add -Dverify flag (not fully implemented yet).
74
from bzrlib.plugins.git.mapping import (
0.200.345 by Jelmer Vernooij
Keep track of file modes to use.
75
    DEFAULT_FILE_MODE,
0.200.521 by Jelmer Vernooij
Abstract out kind mapping a bit, initial work on support tree-references.
76
    mode_is_executable,
0.200.820 by Jelmer Vernooij
Avoid relying on InventoryDirectory.children.
77
    mode_kind,
0.200.490 by Jelmer Vernooij
Warn about unusual modes and escaped XML-invalid characters.
78
    warn_unusual_mode,
0.231.2 by Jelmer Vernooij
Add -Dverify flag (not fully implemented yet).
79
    )
0.200.456 by Jelmer Vernooij
Fix git -> git fetching.
80
from bzrlib.plugins.git.object_store import (
81
    BazaarObjectStore,
0.200.852 by Jelmer Vernooij
Cache trees rather than inventories.
82
    LRUTreeCache,
0.200.883 by Jelmer Vernooij
Add function for verifying reconstruction of objects still works.
83
    _tree_to_objects,
0.200.456 by Jelmer Vernooij
Fix git -> git fetching.
84
    )
0.200.1458 by Jelmer Vernooij
Gather peeled shas rather than unpeeled.
85
from bzrlib.plugins.git.refs import (
0.200.1487 by Jelmer Vernooij
Use peeling.
86
    is_tag,
0.200.1458 by Jelmer Vernooij
Gather peeled shas rather than unpeeled.
87
    )
0.200.426 by Jelmer Vernooij
Fix import of RemoteGitRepository.
88
from bzrlib.plugins.git.remote import (
89
    RemoteGitRepository,
90
    )
0.200.169 by Jelmer Vernooij
Fix branch cloning.
91
from bzrlib.plugins.git.repository import (
0.200.664 by Jelmer Vernooij
Support submodules during fetch.
92
    GitRepository,
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
93
    GitRepositoryFormat,
0.200.426 by Jelmer Vernooij
Fix import of RemoteGitRepository.
94
    LocalGitRepository,
0.200.261 by Jelmer Vernooij
More formatting fixes.
95
    )
0.216.4 by Jelmer Vernooij
Add basic pack fetch infrastructure.
96
97
0.200.821 by Jelmer Vernooij
Remove last references to ID.children.
98
def import_git_blob(texts, mapping, path, name, (base_hexsha, hexsha), 
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
99
        base_bzr_tree, parent_id, revision_id,
100
        parent_bzr_trees, lookup_object, (base_mode, mode), store_updater,
0.200.896 by Jelmer Vernooij
Add separate function for looking up file ids.
101
        lookup_file_id):
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
102
    """Import a git blob object into a bzr repository.
103
0.200.261 by Jelmer Vernooij
More formatting fixes.
104
    :param texts: VersionedFiles to add to
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
105
    :param path: Path in the tree
106
    :param blob: A git blob
0.229.1 by Jelmer Vernooij
Start working with inventory deltas.
107
    :return: Inventory delta for this file
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
108
    """
0.252.28 by Jelmer Vernooij
Don't import control files.
109
    if mapping.is_control_file(path):
110
        return []
0.200.816 by Jelmer Vernooij
Leave mode handling for blobs to import_git_blob.
111
    if base_hexsha == hexsha and base_mode == mode:
112
        # 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.
113
        return []
0.200.896 by Jelmer Vernooij
Add separate function for looking up file ids.
114
    file_id = lookup_file_id(path)
0.200.816 by Jelmer Vernooij
Leave mode handling for blobs to import_git_blob.
115
    if stat.S_ISLNK(mode):
0.200.320 by Jelmer Vernooij
Handle lightweight checkouts.
116
        cls = InventoryLink
117
    else:
118
        cls = InventoryFile
0.200.821 by Jelmer Vernooij
Remove last references to ID.children.
119
    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.
120
    if ie.kind == "file":
121
        ie.executable = mode_is_executable(mode)
0.200.821 by Jelmer Vernooij
Remove last references to ID.children.
122
    if base_hexsha == hexsha and mode_kind(base_mode) == mode_kind(mode):
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
123
        base_file_id = base_bzr_tree.path2id(path)
0.200.1576 by Jelmer Vernooij
Merge a bunch of fixes from store-roundtrip-info.
124
        base_exec = base_bzr_tree.is_executable(base_file_id, path)
0.200.995 by Jelmer Vernooij
Support newer versions of bzr where only some InventoryFile/InventoryLink attributes are writable.
125
        if ie.kind == "symlink":
0.200.1576 by Jelmer Vernooij
Merge a bunch of fixes from store-roundtrip-info.
126
            ie.symlink_target = base_bzr_tree.get_symlink_target(
127
                base_file_id, path)
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
128
        else:
0.200.1576 by Jelmer Vernooij
Merge a bunch of fixes from store-roundtrip-info.
129
            ie.text_size = base_bzr_tree.get_file_size(base_file_id)
130
            ie.text_sha1 = base_bzr_tree.get_file_sha1(base_file_id, path)
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
131
        if ie.kind == "symlink" or ie.executable == base_exec:
132
            ie.revision = base_bzr_tree.get_file_revision(base_file_id, path)
0.200.537 by Jelmer Vernooij
Fix handling of not-executable files becoming executable without any other changes.
133
        else:
134
            blob = lookup_object(hexsha)
0.200.304 by Jelmer Vernooij
Try a bit harder to avoid fetching objects we don't need.
135
    else:
136
        blob = lookup_object(hexsha)
0.200.320 by Jelmer Vernooij
Handle lightweight checkouts.
137
        if ie.kind == "symlink":
0.200.551 by Jelmer Vernooij
Properly set InventoryEntry revision when changing symlink targets.
138
            ie.revision = None
0.200.1344 by Jelmer Vernooij
Unicode symlinks should be unicode in inventory entries.
139
            ie.symlink_target = blob.data.decode("utf-8")
0.200.320 by Jelmer Vernooij
Handle lightweight checkouts.
140
        else:
0.200.830 by Jelmer Vernooij
Bump minimum dulwich version.
141
            ie.text_size = sum(imap(len, blob.chunked))
142
            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).
143
    # Check what revision we should store
0.200.283 by Jelmer Vernooij
Avoid storing repeated texts for blobs.
144
    parent_keys = []
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
145
    for ptree in parent_bzr_trees:
0.200.1576 by Jelmer Vernooij
Merge a bunch of fixes from store-roundtrip-info.
146
        try:
147
            pkind = ptree.kind(file_id)
148
        except errors.NoSuchId:
0.200.829 by Jelmer Vernooij
Cope with the fact that _type is gone in upstream dulwich.
149
            continue
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
150
        if (pkind == ie.kind and
0.200.1576 by Jelmer Vernooij
Merge a bunch of fixes from store-roundtrip-info.
151
            ((pkind == "symlink" and ptree.get_symlink_target(file_id) == ie.symlink_target) or
152
             (pkind == "file" and ptree.get_file_sha1(file_id) == ie.text_sha1 and
153
                ptree.is_executable(file_id) == ie.executable))):
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
154
            # found a revision in one of the parents to use
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
155
            ie.revision = ptree.get_file_revision(file_id)
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
156
            break
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
157
        parent_key = (file_id, ptree.get_file_revision(file_id))
0.200.904 by Jelmer Vernooij
Fix inconsistent parents.
158
        if not parent_key in parent_keys:
159
            parent_keys.append(parent_key)
0.229.3 by Jelmer Vernooij
Use inventory deltas internally so fetch is O(changes) rather than O(tree).
160
    if ie.revision is None:
161
        # Need to store a new revision
162
        ie.revision = revision_id
163
        assert ie.revision is not None
0.200.698 by Jelmer Vernooij
Merge fixes for SHA1s of symlinks.
164
        if ie.kind == 'symlink':
0.200.811 by Jelmer Vernooij
Use ChunkedContentFactory when possible.
165
            chunks = []
0.200.1292 by Jelmer Vernooij
Fix repeeling objects when determining what to send.
166
        else:
0.200.830 by Jelmer Vernooij
Bump minimum dulwich version.
167
            chunks = blob.chunked
0.252.25 by Jelmer Vernooij
Reformatting.
168
        texts.insert_record_stream([
169
            ChunkedContentFactory((file_id, ie.revision),
170
                tuple(parent_keys), ie.text_sha1, chunks)])
0.200.572 by Jelmer Vernooij
Avoid some extra path lookups.
171
    invdelta = []
0.200.820 by Jelmer Vernooij
Avoid relying on InventoryDirectory.children.
172
    if base_hexsha is not None:
0.200.984 by Jelmer Vernooij
Handle non-ascii characters in filenames.
173
        old_path = path.decode("utf-8") # Renames are not supported yet
0.200.820 by Jelmer Vernooij
Avoid relying on InventoryDirectory.children.
174
        if stat.S_ISDIR(base_mode):
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
175
            invdelta.extend(remove_disappeared_children(base_bzr_tree, old_path,
0.200.826 by Jelmer Vernooij
Fix some long lines.
176
                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).
177
    else:
178
        old_path = None
0.200.984 by Jelmer Vernooij
Handle non-ascii characters in filenames.
179
    new_path = path.decode("utf-8")
180
    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.
181
    if base_hexsha != hexsha:
0.275.2 by Jelmer Vernooij
Pass tuples around for cache entries, rather than inventory entries.
182
        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.
183
    return invdelta
0.200.261 by Jelmer Vernooij
More formatting fixes.
184
185
0.200.664 by Jelmer Vernooij
Support submodules during fetch.
186
class SubmodulesRequireSubtrees(BzrError):
0.200.1309 by Jelmer Vernooij
Break some more long lines.
187
    _fmt = ("The repository you are fetching from contains submodules. "
188
            "To continue, upgrade your Bazaar repository to a format that "
189
            "supports nested trees, such as 'development-subtree'.")
0.239.5 by Jelmer Vernooij
Print user-understandable error message when encountering submodules.
190
    internal = False
191
192
0.200.821 by Jelmer Vernooij
Remove last references to ID.children.
193
def import_git_submodule(texts, mapping, path, name, (base_hexsha, hexsha),
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
194
    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.
195
    (base_mode, mode), store_updater, lookup_file_id):
0.200.1309 by Jelmer Vernooij
Break some more long lines.
196
    """Import a git submodule."""
0.200.817 by Jelmer Vernooij
Deal with all modes locally.
197
    if base_hexsha == hexsha and base_mode == mode:
0.200.839 by Jelmer Vernooij
Add convenience object for updating the object store caching layer.
198
        return [], {}
0.200.896 by Jelmer Vernooij
Add separate function for looking up file ids.
199
    file_id = lookup_file_id(path)
0.200.1408 by Jelmer Vernooij
Remove old ie children when converting directory into tree reference.
200
    invdelta = []
0.200.821 by Jelmer Vernooij
Remove last references to ID.children.
201
    ie = TreeReference(file_id, name.decode("utf-8"), parent_id)
0.200.664 by Jelmer Vernooij
Support submodules during fetch.
202
    ie.revision = revision_id
0.200.1408 by Jelmer Vernooij
Remove old ie children when converting directory into tree reference.
203
    if base_hexsha is not None:
204
        old_path = path.decode("utf-8") # Renames are not supported yet
205
        if stat.S_ISDIR(base_mode):
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
206
            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.
207
                lookup_object(base_hexsha), [], lookup_object))
0.200.664 by Jelmer Vernooij
Support submodules during fetch.
208
    else:
0.200.1408 by Jelmer Vernooij
Remove old ie children when converting directory into tree reference.
209
        old_path = None
0.200.664 by Jelmer Vernooij
Support submodules during fetch.
210
    ie.reference_revision = mapping.revision_id_foreign_to_bzr(hexsha)
0.252.25 by Jelmer Vernooij
Reformatting.
211
    texts.insert_record_stream([
212
        ChunkedContentFactory((file_id, ie.revision), (), None, [])])
0.200.1408 by Jelmer Vernooij
Remove old ie children when converting directory into tree reference.
213
    invdelta.append((old_path, path, file_id, ie))
0.200.839 by Jelmer Vernooij
Add convenience object for updating the object store caching layer.
214
    return invdelta, {}
0.200.540 by Jelmer Vernooij
Handle submodules explicitly.
215
216
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
217
def remove_disappeared_children(base_bzr_tree, path, base_tree, existing_children,
0.200.820 by Jelmer Vernooij
Avoid relying on InventoryDirectory.children.
218
        lookup_object):
0.200.930 by Jelmer Vernooij
Add assert demonstrating 571055 and triggering it for all target formats.
219
    """Generate an inventory delta for removed children.
220
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
221
    :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.
222
        inventory delta.
0.200.984 by Jelmer Vernooij
Handle non-ascii characters in filenames.
223
    :param path: Path to process (unicode)
0.200.930 by Jelmer Vernooij
Add assert demonstrating 571055 and triggering it for all target formats.
224
    :param base_tree: Git Tree base object
225
    :param existing_children: Children that still exist
226
    :param lookup_object: Lookup a git object by its SHA1
227
    :return: Inventory delta, as list
228
    """
0.200.984 by Jelmer Vernooij
Handle non-ascii characters in filenames.
229
    assert type(path) is unicode
0.200.552 by Jelmer Vernooij
Cope with directories becoming symlinks.
230
    ret = []
0.200.820 by Jelmer Vernooij
Avoid relying on InventoryDirectory.children.
231
    for name, mode, hexsha in base_tree.iteritems():
232
        if name in existing_children:
233
            continue
234
        c_path = posixpath.join(path, name.decode("utf-8"))
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
235
        file_id = base_bzr_tree.path2id(c_path)
0.200.930 by Jelmer Vernooij
Add assert demonstrating 571055 and triggering it for all target formats.
236
        assert file_id is not None
237
        ret.append((c_path, None, file_id, None))
0.200.820 by Jelmer Vernooij
Avoid relying on InventoryDirectory.children.
238
        if stat.S_ISDIR(mode):
239
            ret.extend(remove_disappeared_children(
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
240
                base_bzr_tree, c_path, lookup_object(hexsha), [], lookup_object))
0.200.552 by Jelmer Vernooij
Cope with directories becoming symlinks.
241
    return ret
242
243
0.200.821 by Jelmer Vernooij
Remove last references to ID.children.
244
def import_git_tree(texts, mapping, path, name, (base_hexsha, hexsha),
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
245
        base_bzr_tree, parent_id, revision_id, parent_bzr_trees,
0.200.896 by Jelmer Vernooij
Add separate function for looking up file ids.
246
        lookup_object, (base_mode, mode), store_updater,
247
        lookup_file_id, allow_submodules=False):
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
248
    """Import a git tree object into a bzr repository.
249
0.200.261 by Jelmer Vernooij
More formatting fixes.
250
    :param texts: VersionedFiles object to add to
0.200.984 by Jelmer Vernooij
Handle non-ascii characters in filenames.
251
    :param path: Path in the tree (str)
252
    :param name: Name of the tree (str)
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
253
    :param tree: A git tree object
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
254
    :param base_bzr_tree: Base inventory against which to return inventory delta
0.229.1 by Jelmer Vernooij
Start working with inventory deltas.
255
    :return: Inventory delta for this subtree
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
256
    """
0.200.984 by Jelmer Vernooij
Handle non-ascii characters in filenames.
257
    assert type(path) is str
258
    assert type(name) is str
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.883 by Jelmer Vernooij
Add function for verifying reconstruction of objects still works.
448
        verify_commit_reconstruction(target_git_object_retriever, 
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.269.8 by Jelmer Vernooij
Support push in git-remote-bzr.
478
        assert isinstance(head, str), "head is %r" % (head,)
0.200.310 by Jelmer Vernooij
Fix pull from remote branches.
479
        try:
0.248.5 by Jelmer Vernooij
Reformatting, fix dpush.
480
            o = lookup_object(head)
0.200.310 by Jelmer Vernooij
Fix pull from remote branches.
481
        except KeyError:
482
            continue
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
483
        if isinstance(o, Commit):
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
484
            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.
485
                mapping.revision_id_foreign_to_bzr)
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
486
            if (repo.has_revision(rev.revision_id) or
487
                (roundtrip_revid and repo.has_revision(roundtrip_revid))):
0.200.295 by Jelmer Vernooij
Don't re-import revisions already fetched.
488
                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.
489
            graph.append((o.id, o.parents))
0.200.296 by Jelmer Vernooij
Avoid iterating over all objects just to find the *Commits* to retrieve.
490
            heads.extend([p for p in o.parents if p not in checked])
0.200.303 by Jelmer Vernooij
Cope with tags during fetch.
491
        elif isinstance(o, Tag):
0.200.734 by Jelmer Vernooij
Don't import head revision twice when pulling from Git.
492
            if o.object[1] not in checked:
493
                heads.append(o.object[1])
0.200.296 by Jelmer Vernooij
Avoid iterating over all objects just to find the *Commits* to retrieve.
494
        else:
495
            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.
496
        checked.add(o.id)
497
    del checked
0.200.158 by Jelmer Vernooij
fetch works \o/
498
    # Order the revisions
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
499
    # Create the inventory objects
0.200.821 by Jelmer Vernooij
Remove last references to ID.children.
500
    batch_size = 1000
0.200.680 by Jelmer Vernooij
fetch revisions in batches
501
    revision_ids = topo_sort(graph)
502
    pack_hints = []
0.247.2 by Michael Hudson
this works for my tests, but i'm pretty sure it's wrong in general
503
    if limit is not None:
504
        revision_ids = revision_ids[:limit]
0.247.3 by Michael Hudson
oh, so it wasn't (particularly) wrong, but it was a bit obscure
505
    last_imported = None
0.200.680 by Jelmer Vernooij
fetch revisions in batches
506
    for offset in range(0, len(revision_ids), batch_size):
0.254.33 by Jelmer Vernooij
Merge trunk.
507
        target_git_object_retriever.start_write_group() 
0.200.680 by Jelmer Vernooij
fetch revisions in batches
508
        try:
0.254.33 by Jelmer Vernooij
Merge trunk.
509
            repo.start_write_group()
510
            try:
0.200.824 by Jelmer Vernooij
Commit cache data in batches as well.
511
                for i, head in enumerate(
512
                    revision_ids[offset:offset+batch_size]):
0.254.33 by Jelmer Vernooij
Merge trunk.
513
                    if pb is not None:
0.200.824 by Jelmer Vernooij
Commit cache data in batches as well.
514
                        pb.update("fetching revisions", offset+i,
515
                                  len(revision_ids))
0.254.33 by Jelmer Vernooij
Merge trunk.
516
                    import_git_commit(repo, mapping, head, lookup_object,
0.252.25 by Jelmer Vernooij
Reformatting.
517
                        target_git_object_retriever, trees_cache)
0.254.33 by Jelmer Vernooij
Merge trunk.
518
                    last_imported = head
519
            except:
520
                repo.abort_write_group()
521
                raise
522
            else:
523
                hint = repo.commit_write_group()
524
                if hint is not None:
525
                    pack_hints.extend(hint)
0.200.680 by Jelmer Vernooij
fetch revisions in batches
526
        except:
0.254.33 by Jelmer Vernooij
Merge trunk.
527
            target_git_object_retriever.abort_write_group()
0.200.680 by Jelmer Vernooij
fetch revisions in batches
528
            raise
529
        else:
0.254.33 by Jelmer Vernooij
Merge trunk.
530
            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
531
    return pack_hints, last_imported
0.200.141 by Jelmer Vernooij
Separate out local and remote fetching.
532
533
0.200.1350 by Jelmer Vernooij
Implement search_missing_revision_ids.
534
class InterFromGitRepository(InterRepository):
0.200.135 by Jelmer Vernooij
Add stub for fetching data.
535
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
536
    _matching_repo_format = GitRepositoryFormat()
0.200.143 by Jelmer Vernooij
Reoncile InterGitRepository objects.
537
0.200.1154 by Jelmer Vernooij
Share more code in InterGitRepository.
538
    def _target_has_shas(self, shas):
539
        raise NotImplementedError(self._target_has_shas)
540
541
    def get_determine_wants_heads(self, wants, include_tags=False):
0.200.1490 by Jelmer Vernooij
Fix target_has_shas.
542
        raise NotImplementedError(self.get_determine_wants_heads)
0.200.1154 by Jelmer Vernooij
Share more code in InterGitRepository.
543
544
    def determine_wants_all(self, refs):
0.200.1490 by Jelmer Vernooij
Fix target_has_shas.
545
        raise NotImplementedError(self.determine_wants_all)
0.200.1154 by Jelmer Vernooij
Share more code in InterGitRepository.
546
0.200.143 by Jelmer Vernooij
Reoncile InterGitRepository objects.
547
    @staticmethod
548
    def _get_repo_format_to_test():
549
        return None
550
0.200.1492 by Jelmer Vernooij
Fix test
551
    def copy_content(self, revision_id=None):
0.200.135 by Jelmer Vernooij
Add stub for fetching data.
552
        """See InterRepository.copy_content."""
0.200.1492 by Jelmer Vernooij
Fix test
553
        self.fetch(revision_id, find_ghosts=False)
0.200.135 by Jelmer Vernooij
Add stub for fetching data.
554
0.200.1350 by Jelmer Vernooij
Implement search_missing_revision_ids.
555
    def search_missing_revision_ids(self,
556
            find_ghosts=True, revision_ids=None, if_present_ids=None,
557
            limit=None):
558
        git_shas = []
559
        todo = []
560
        if revision_ids:
561
            todo.extend(revision_ids)
562
        if if_present_ids:
563
            todo.extend(revision_ids)
564
        for revid in revision_ids:
565
            if revid == NULL_REVISION:
566
                continue
567
            git_sha, mapping = self.source.lookup_bzr_revision_id(revid)
568
            git_shas.append(git_sha)
569
        walker = Walker(self.source._git.object_store,
0.200.1493 by Jelmer Vernooij
Test fixes.
570
            include=git_shas, exclude=[sha for sha in self.target.bzrdir.get_refs_container().as_dict().values() if sha != ZERO_SHA])
0.200.1350 by Jelmer Vernooij
Implement search_missing_revision_ids.
571
        missing_revids = set()
572
        for entry in walker:
573
            missing_revids.add(self.source.lookup_foreign_revision_id(entry.commit.id))
574
        return self.source.revision_ids_to_search_result(missing_revids)
575
576
577
class InterGitNonGitRepository(InterFromGitRepository):
0.200.664 by Jelmer Vernooij
Support submodules during fetch.
578
    """Base InterRepository that copies revisions from a Git into a non-Git
0.200.456 by Jelmer Vernooij
Fix git -> git fetching.
579
    repository."""
580
0.259.4 by Jelmer Vernooij
Put determine_wants methods on InterRepo.
581
    def _target_has_shas(self, shas):
0.200.1456 by Jelmer Vernooij
Fix target_has_shas.
582
        revids = {}
0.200.1403 by Jelmer Vernooij
Cope with tags pointing at tree objects when cloning local git repositories.
583
        for sha in shas:
584
            try:
585
                revid = self.source.lookup_foreign_revision_id(sha)
586
            except NotCommitError:
0.200.1456 by Jelmer Vernooij
Fix target_has_shas.
587
                # Commit is definitely not present
0.200.1403 by Jelmer Vernooij
Cope with tags pointing at tree objects when cloning local git repositories.
588
                continue
589
            else:
0.200.1456 by Jelmer Vernooij
Fix target_has_shas.
590
                revids[revid] = sha
591
        return set([revids[r] for r in self.target.has_revisions(revids)])
0.259.4 by Jelmer Vernooij
Put determine_wants methods on InterRepo.
592
0.200.1489 by Jelmer Vernooij
More fixes to peel handling.
593
    def determine_wants_all(self, refs):
594
        potential = set()
595
        for k, v in refs.as_dict().iteritems():
596
            # For non-git target repositories, only worry about peeled
0.200.1513 by Jelmer Vernooij
Cope with zero shas.
597
            if v == ZERO_SHA:
598
                continue
0.200.1489 by Jelmer Vernooij
More fixes to peel handling.
599
            potential.add(self.source.bzrdir.get_peeled(k))
600
        return list(potential - self._target_has_shas(potential))
601
0.200.1490 by Jelmer Vernooij
Fix target_has_shas.
602
    def get_determine_wants_heads(self, wants, include_tags=False):
603
        wants = set(wants)
604
        def determine_wants(refs):
605
            potential = set(wants)
606
            if include_tags:
607
                for k, unpeeled in refs.as_dict().iteritems():
608
                    if not is_tag(k):
609
                        continue
0.200.1513 by Jelmer Vernooij
Cope with zero shas.
610
                    if unpeeled == ZERO_SHA:
611
                        continue
0.200.1490 by Jelmer Vernooij
Fix target_has_shas.
612
                    potential.add(self.source.bzrdir.get_peeled(k))
613
            return list(potential - self._target_has_shas(potential))
614
        return determine_wants
615
0.259.6 by Jelmer Vernooij
Fetch tags during pull.
616
    def get_determine_wants_revids(self, revids, include_tags=False):
617
        wants = set()
618
        for revid in set(revids):
0.200.1388 by Jelmer Vernooij
Don't fetch revision already present.
619
            if self.target.has_revision(revid):
620
                continue
0.259.6 by Jelmer Vernooij
Fetch tags during pull.
621
            git_sha, mapping = self.source.lookup_bzr_revision_id(revid)
622
            wants.add(git_sha)
0.200.1489 by Jelmer Vernooij
More fixes to peel handling.
623
        return self.get_determine_wants_heads(wants, include_tags=include_tags)
0.259.6 by Jelmer Vernooij
Fetch tags during pull.
624
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
625
    def fetch_objects(self, determine_wants, mapping, limit=None):
0.200.1001 by Jelmer Vernooij
Simplify handling of determine wants, add stub for fetch_objects().
626
        """Fetch objects from a remote server.
627
628
        :param determine_wants: determine_wants callback
629
        :param mapping: BzrGitMapping to use
630
        :param limit: Maximum number of commits to import.
0.200.1002 by Jelmer Vernooij
Fix regression in git-import.
631
        :return: Tuple with pack hint, last imported revision id and remote refs
0.200.1001 by Jelmer Vernooij
Simplify handling of determine wants, add stub for fetch_objects().
632
        """
633
        raise NotImplementedError(self.fetch_objects)
634
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
635
    def fetch(self, revision_id=None, find_ghosts=False,
0.200.247 by Jelmer Vernooij
Fix git-import.
636
              mapping=None, fetch_spec=None):
0.200.225 by Jelmer Vernooij
Implement custom InterBranch to support fetching from remote git branches.
637
        if mapping is None:
638
            mapping = self.source.get_mapping()
0.226.2 by Jelmer Vernooij
Cope with new fetch_spec argument.
639
        if revision_id is not None:
640
            interesting_heads = [revision_id]
641
        elif fetch_spec is not None:
0.200.1089 by Jelmer Vernooij
Cope with fancy fetch_spec behaviour.
642
            recipe = fetch_spec.get_recipe()
643
            if recipe[0] in ("search", "proxy-search"):
644
                interesting_heads = recipe[1]
645
            else:
0.200.1300 by Jelmer Vernooij
Fix formatting.
646
                raise AssertionError("Unsupported search result type %s" %
647
                        recipe[0])
0.226.2 by Jelmer Vernooij
Cope with new fetch_spec argument.
648
        else:
649
            interesting_heads = None
0.259.4 by Jelmer Vernooij
Put determine_wants methods on InterRepo.
650
651
        if interesting_heads is not None:
0.200.1309 by Jelmer Vernooij
Break some more long lines.
652
            determine_wants = self.get_determine_wants_revids(
653
                interesting_heads, include_tags=False)
0.259.4 by Jelmer Vernooij
Put determine_wants methods on InterRepo.
654
        else:
655
            determine_wants = self.determine_wants_all
0.200.1079 by Jelmer Vernooij
Avoid looking up revid if not necessary.
656
657
        (pack_hint, _, remote_refs) = self.fetch_objects(determine_wants,
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
658
            mapping)
0.200.579 by Jelmer Vernooij
Only pack if it makes the target repo smaller.
659
        if pack_hint is not None and self.target._format.pack_compresses:
0.200.578 by Jelmer Vernooij
Only do optimal packing on bzr >= 1.17.
660
            self.target.pack(hint=pack_hint)
0.200.1002 by Jelmer Vernooij
Fix regression in git-import.
661
        return remote_refs
0.200.225 by Jelmer Vernooij
Implement custom InterBranch to support fetching from remote git branches.
662
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
663
0.200.563 by Jelmer Vernooij
Attempt to parse progress indication from git status reports.
664
_GIT_PROGRESS_RE = re.compile(r"(.*?): +(\d+)% \((\d+)/(\d+)\)")
665
def report_git_progress(pb, text):
666
    text = text.rstrip("\r\n")
667
    g = _GIT_PROGRESS_RE.match(text)
668
    if g is not None:
669
        (text, pct, current, total) = g.groups()
670
        pb.update(text, int(current), int(total))
671
    else:
672
        pb.update(text, 0, 0)
673
674
0.200.1001 by Jelmer Vernooij
Simplify handling of determine wants, add stub for fetch_objects().
675
class DetermineWantsRecorder(object):
676
677
    def __init__(self, actual):
678
        self.actual = actual
679
        self.wants = []
680
        self.remote_refs = {}
681
682
    def __call__(self, refs):
683
        self.remote_refs = refs
684
        self.wants = self.actual(refs)
685
        return self.wants
686
687
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
688
class InterRemoteGitNonGitRepository(InterGitNonGitRepository):
0.200.664 by Jelmer Vernooij
Support submodules during fetch.
689
    """InterRepository that copies revisions from a remote Git into a non-Git
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
690
    repository."""
691
0.200.582 by Jelmer Vernooij
Use more efficient algorithm for finding out heads.
692
    def get_target_heads(self):
693
        # FIXME: This should be more efficient
694
        all_revs = self.target.all_revision_ids()
695
        parent_map = self.target.get_parent_map(all_revs)
696
        all_parents = set()
697
        map(all_parents.update, parent_map.itervalues())
698
        return set(all_revs) - all_parents
699
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
700
    def fetch_objects(self, determine_wants, mapping, limit=None):
0.200.1001 by Jelmer Vernooij
Simplify handling of determine wants, add stub for fetch_objects().
701
        """See `InterGitNonGitRepository`."""
0.200.466 by Jelmer Vernooij
Fix finding of heads for fetch_objects.
702
        store = BazaarObjectStore(self.target, mapping)
0.200.1212 by Jelmer Vernooij
Support read locking object stores.
703
        store.lock_write()
0.200.465 by Jelmer Vernooij
Use dulwich standard functionality for finding missing revisions.
704
        try:
0.200.582 by Jelmer Vernooij
Use more efficient algorithm for finding out heads.
705
            heads = self.get_target_heads()
0.200.484 by Jelmer Vernooij
Cope with kind changes.
706
            graph_walker = store.get_graph_walker(
707
                    [store._lookup_revision_sha1(head) for head in heads])
0.200.1001 by Jelmer Vernooij
Simplify handling of determine wants, add stub for fetch_objects().
708
            wants_recorder = DetermineWantsRecorder(determine_wants)
0.200.664 by Jelmer Vernooij
Support submodules during fetch.
709
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
710
            pb = ui.ui_factory.nested_progress_bar()
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
711
            try:
0.200.1000 by Jelmer Vernooij
Fix fetch between local and remote git branches.
712
                objects_iter = self.source.fetch_objects(
0.200.1001 by Jelmer Vernooij
Simplify handling of determine wants, add stub for fetch_objects().
713
                    wants_recorder, graph_walker, store.get_raw,
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
714
                    progress=lambda text: report_git_progress(pb, text))
0.200.1300 by Jelmer Vernooij
Fix formatting.
715
                trace.mutter("Importing %d new revisions",
716
                             len(wants_recorder.wants))
717
                (pack_hint, last_rev) = import_git_objects(self.target,
718
                    mapping, objects_iter, store, wants_recorder.wants, pb,
719
                    limit)
0.200.1002 by Jelmer Vernooij
Fix regression in git-import.
720
                return (pack_hint, last_rev, wants_recorder.remote_refs)
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
721
            finally:
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
722
                pb.finished()
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
723
        finally:
0.200.1212 by Jelmer Vernooij
Support read locking object stores.
724
            store.unlock()
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
725
726
    @staticmethod
727
    def is_compatible(source, target):
728
        """Be compatible with GitRepository."""
0.200.1222 by Jelmer Vernooij
Better checks in is_compatible methods.
729
        if not isinstance(source, RemoteGitRepository):
730
            return False
731
        if not target.supports_rich_root():
732
            return False
733
        if isinstance(target, GitRepository):
734
            return False
0.200.1270 by Jelmer Vernooij
Cope with older versions of bzr.
735
        if not getattr(target._format, "supports_full_versioned_files", True):
0.200.1222 by Jelmer Vernooij
Better checks in is_compatible methods.
736
            return False
737
        return True
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
738
739
740
class InterLocalGitNonGitRepository(InterGitNonGitRepository):
0.200.664 by Jelmer Vernooij
Support submodules during fetch.
741
    """InterRepository that copies revisions from a local Git into a non-Git
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
742
    repository."""
743
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
744
    def fetch_objects(self, determine_wants, mapping, limit=None):
0.200.1001 by Jelmer Vernooij
Simplify handling of determine wants, add stub for fetch_objects().
745
        """See `InterGitNonGitRepository`."""
0.200.1487 by Jelmer Vernooij
Use peeling.
746
        remote_refs = self.source.bzrdir.get_refs_container()
0.200.1002 by Jelmer Vernooij
Fix regression in git-import.
747
        wants = determine_wants(remote_refs)
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
748
        create_pb = None
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
749
        pb = ui.ui_factory.nested_progress_bar()
0.200.320 by Jelmer Vernooij
Handle lightweight checkouts.
750
        target_git_object_retriever = BazaarObjectStore(self.target, mapping)
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
751
        try:
0.200.1212 by Jelmer Vernooij
Support read locking object stores.
752
            target_git_object_retriever.lock_write()
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
753
            try:
0.200.1300 by Jelmer Vernooij
Fix formatting.
754
                (pack_hint, last_rev) = import_git_objects(self.target,
755
                    mapping, self.source._git.object_store,
0.248.5 by Jelmer Vernooij
Reformatting, fix dpush.
756
                    target_git_object_retriever, wants, pb, limit)
0.200.1002 by Jelmer Vernooij
Fix regression in git-import.
757
                return (pack_hint, last_rev, remote_refs)
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
758
            finally:
0.200.1212 by Jelmer Vernooij
Support read locking object stores.
759
                target_git_object_retriever.unlock()
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
760
        finally:
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
761
            pb.finished()
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
762
763
    @staticmethod
764
    def is_compatible(source, target):
765
        """Be compatible with GitRepository."""
0.200.1222 by Jelmer Vernooij
Better checks in is_compatible methods.
766
        if not isinstance(source, LocalGitRepository):
767
            return False
768
        if not target.supports_rich_root():
769
            return False
770
        if isinstance(target, GitRepository):
771
            return False
0.200.1266 by Jelmer Vernooij
Fix 2.3 support.
772
        if not getattr(target._format, "supports_full_versioned_files", True):
0.200.1222 by Jelmer Vernooij
Better checks in is_compatible methods.
773
            return False
774
        return True
0.200.175 by Jelmer Vernooij
Add optimized handling when fetching from git to git.
775
776
0.200.1350 by Jelmer Vernooij
Implement search_missing_revision_ids.
777
class InterGitGitRepository(InterFromGitRepository):
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
778
    """InterRepository that copies between Git repositories."""
0.200.175 by Jelmer Vernooij
Add optimized handling when fetching from git to git.
779
0.200.1433 by Jelmer Vernooij
Fix fetching between git repositories.
780
    def fetch_refs(self, update_refs, lossy=False):
781
        if lossy:
782
            raise errors.LossyPushToSameVCS(self.source, self.target)
0.200.1487 by Jelmer Vernooij
Use peeling.
783
        old_refs = self.target.bzrdir.get_refs_container()
0.200.1433 by Jelmer Vernooij
Fix fetching between git repositories.
784
        ref_changes = {}
785
        def determine_wants(heads):
0.200.1524 by Jelmer Vernooij
Fix inter-git fetching.
786
            old_refs = dict([(k, (v, None)) for (k, v) in heads.as_dict().iteritems()])
0.200.1433 by Jelmer Vernooij
Fix fetching between git repositories.
787
            new_refs = update_refs(old_refs)
788
            ref_changes.update(new_refs)
789
            return [sha1 for (sha1, bzr_revid) in new_refs.itervalues()]
790
        self.fetch_objects(determine_wants)
791
        for k, (git_sha, bzr_revid) in ref_changes.iteritems():
792
            self.target._git.refs[k] = git_sha
0.200.1487 by Jelmer Vernooij
Use peeling.
793
        new_refs = self.target.bzrdir.get_refs_container()
0.200.1433 by Jelmer Vernooij
Fix fetching between git repositories.
794
        return None, old_refs, new_refs
795
0.200.1535 by Jelmer Vernooij
Support limit argument.
796
    def fetch_objects(self, determine_wants, mapping=None, limit=None):
0.200.635 by Jelmer Vernooij
Fix fetching between git repositories.
797
        graphwalker = self.target._git.get_graph_walker()
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
798
        if (isinstance(self.source, LocalGitRepository) and
799
            isinstance(self.target, LocalGitRepository)):
0.200.1493 by Jelmer Vernooij
Test fixes.
800
            def wrap_determine_wants(refs):
801
                return determine_wants(self.source._git.refs)
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
802
            pb = ui.ui_factory.nested_progress_bar()
803
            try:
0.200.1493 by Jelmer Vernooij
Test fixes.
804
                refs = self.source._git.fetch(self.target._git, wrap_determine_wants,
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
805
                    lambda text: report_git_progress(pb, text))
806
            finally:
807
                pb.finished()
0.200.1002 by Jelmer Vernooij
Fix regression in git-import.
808
            return (None, None, refs)
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
809
        elif (isinstance(self.source, LocalGitRepository) and
810
              isinstance(self.target, RemoteGitRepository)):
0.200.635 by Jelmer Vernooij
Fix fetching between git repositories.
811
            raise NotImplementedError
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
812
        elif (isinstance(self.source, RemoteGitRepository) and
813
              isinstance(self.target, LocalGitRepository)):
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
814
            pb = ui.ui_factory.nested_progress_bar()
0.200.635 by Jelmer Vernooij
Fix fetching between git repositories.
815
            try:
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
816
                f, commit = self.target._git.object_store.add_pack()
817
                try:
818
                    refs = self.source.bzrdir.fetch_pack(
819
                        determine_wants, graphwalker, f.write,
820
                        lambda text: report_git_progress(pb, text))
821
                    commit()
822
                    return (None, None, refs)
823
                except:
824
                    f.close()
825
                    raise
826
            finally:
827
                pb.finished()
0.200.635 by Jelmer Vernooij
Fix fetching between git repositories.
828
        else:
0.200.1433 by Jelmer Vernooij
Fix fetching between git repositories.
829
            raise AssertionError("fetching between %r and %r not supported" %
830
                    (self.source, self.target))
0.200.635 by Jelmer Vernooij
Fix fetching between git repositories.
831
0.200.1154 by Jelmer Vernooij
Share more code in InterGitRepository.
832
    def _target_has_shas(self, shas):
0.200.1490 by Jelmer Vernooij
Fix target_has_shas.
833
        return set([sha for sha in shas if sha in self.target._git.object_store])
0.200.1154 by Jelmer Vernooij
Share more code in InterGitRepository.
834
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
835
    def fetch(self, revision_id=None, find_ghosts=False,
0.200.1535 by Jelmer Vernooij
Support limit argument.
836
              mapping=None, fetch_spec=None, branches=None, limit=None):
0.200.175 by Jelmer Vernooij
Add optimized handling when fetching from git to git.
837
        if mapping is None:
838
            mapping = self.source.get_mapping()
839
        r = self.target._git
0.226.2 by Jelmer Vernooij
Cope with new fetch_spec argument.
840
        if revision_id is not None:
0.200.1324 by Jelmer Vernooij
More work on roundtripping support.
841
            args = [self.source.lookup_bzr_revision_id(revision_id)[0]]
0.226.2 by Jelmer Vernooij
Cope with new fetch_spec argument.
842
        elif fetch_spec is not None:
0.200.1089 by Jelmer Vernooij
Cope with fancy fetch_spec behaviour.
843
            recipe = fetch_spec.get_recipe()
844
            if recipe[0] in ("search", "proxy-search"):
845
                heads = recipe[1]
846
            else:
0.200.1309 by Jelmer Vernooij
Break some more long lines.
847
                raise AssertionError(
848
                    "Unsupported search result type %s" % recipe[0])
0.200.1350 by Jelmer Vernooij
Implement search_missing_revision_ids.
849
            args = [self.source.lookup_bzr_revision_id(revid)[0] for revid in heads]
0.200.456 by Jelmer Vernooij
Fix git -> git fetching.
850
        if branches is not None:
0.200.1176 by Jelmer Vernooij
Fix fetch return value for inter git fetching.
851
            determine_wants = lambda x: [x[y] for y in branches if not x[y] in r.object_store and x[y] != ZERO_SHA]
0.200.456 by Jelmer Vernooij
Fix git -> git fetching.
852
        elif fetch_spec is None and revision_id is None:
0.200.1154 by Jelmer Vernooij
Share more code in InterGitRepository.
853
            determine_wants = self.determine_wants_all
0.226.2 by Jelmer Vernooij
Cope with new fetch_spec argument.
854
        else:
0.200.1176 by Jelmer Vernooij
Fix fetch return value for inter git fetching.
855
            determine_wants = lambda x: [y for y in args if not y in r.object_store and y != ZERO_SHA]
856
        wants_recorder = DetermineWantsRecorder(determine_wants)
857
        self.fetch_objects(wants_recorder, mapping)
858
        return wants_recorder.remote_refs
0.200.175 by Jelmer Vernooij
Add optimized handling when fetching from git to git.
859
860
    @staticmethod
861
    def is_compatible(source, target):
862
        """Be compatible with GitRepository."""
0.200.664 by Jelmer Vernooij
Support submodules during fetch.
863
        return (isinstance(source, GitRepository) and
0.200.175 by Jelmer Vernooij
Add optimized handling when fetching from git to git.
864
                isinstance(target, GitRepository))
0.200.1174 by Jelmer Vernooij
Fix specific revision fetching between git repositories.
865
866
    def get_determine_wants_revids(self, revids, include_tags=False):
867
        wants = set()
868
        for revid in set(revids):
0.200.1388 by Jelmer Vernooij
Don't fetch revision already present.
869
            if self.target.has_revision(revid):
870
                continue
0.200.1174 by Jelmer Vernooij
Fix specific revision fetching between git repositories.
871
            git_sha, mapping = self.source.lookup_bzr_revision_id(revid)
872
            wants.add(git_sha)
0.200.1309 by Jelmer Vernooij
Break some more long lines.
873
        return self.get_determine_wants_heads(wants,
874
            include_tags=include_tags)
0.200.1489 by Jelmer Vernooij
More fixes to peel handling.
875
876
    def determine_wants_all(self, refs):
0.200.1513 by Jelmer Vernooij
Cope with zero shas.
877
        potential = set([v for v in refs.as_dict().values() if not v == ZERO_SHA])
0.200.1489 by Jelmer Vernooij
More fixes to peel handling.
878
        return list(potential - self._target_has_shas(potential))
0.200.1490 by Jelmer Vernooij
Fix target_has_shas.
879
880
    def get_determine_wants_heads(self, wants, include_tags=False):
881
        wants = set(wants)
882
        def determine_wants(refs):
883
            potential = set(wants)
884
            if include_tags:
885
                for k, unpeeled in refs.as_dict().iteritems():
886
                    if not is_tag(k):
887
                        continue
0.200.1513 by Jelmer Vernooij
Cope with zero shas.
888
                    if unpeeled == ZERO_SHA:
889
                        continue
0.200.1490 by Jelmer Vernooij
Fix target_has_shas.
890
                    potential.add(unpeeled)
891
            return list(potential - self._target_has_shas(potential))
892
        return determine_wants
893
894