/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.1596 by Jelmer Vernooij
Don't mention development-subtree when submodules are encountered.
187
    _fmt = ("The repository you are fetching from contains submodules, "
188
            "which are not yet supported.")
0.239.5 by Jelmer Vernooij
Print user-understandable error message when encountering submodules.
189
    internal = False
190
191
0.200.821 by Jelmer Vernooij
Remove last references to ID.children.
192
def import_git_submodule(texts, mapping, path, name, (base_hexsha, hexsha),
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
193
    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.
194
    (base_mode, mode), store_updater, lookup_file_id):
0.200.1309 by Jelmer Vernooij
Break some more long lines.
195
    """Import a git submodule."""
0.200.817 by Jelmer Vernooij
Deal with all modes locally.
196
    if base_hexsha == hexsha and base_mode == mode:
0.200.839 by Jelmer Vernooij
Add convenience object for updating the object store caching layer.
197
        return [], {}
0.200.896 by Jelmer Vernooij
Add separate function for looking up file ids.
198
    file_id = lookup_file_id(path)
0.200.1408 by Jelmer Vernooij
Remove old ie children when converting directory into tree reference.
199
    invdelta = []
0.200.821 by Jelmer Vernooij
Remove last references to ID.children.
200
    ie = TreeReference(file_id, name.decode("utf-8"), parent_id)
0.200.664 by Jelmer Vernooij
Support submodules during fetch.
201
    ie.revision = revision_id
0.200.1408 by Jelmer Vernooij
Remove old ie children when converting directory into tree reference.
202
    if base_hexsha is not None:
203
        old_path = path.decode("utf-8") # Renames are not supported yet
204
        if stat.S_ISDIR(base_mode):
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
205
            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.
206
                lookup_object(base_hexsha), [], lookup_object))
0.200.664 by Jelmer Vernooij
Support submodules during fetch.
207
    else:
0.200.1408 by Jelmer Vernooij
Remove old ie children when converting directory into tree reference.
208
        old_path = None
0.200.664 by Jelmer Vernooij
Support submodules during fetch.
209
    ie.reference_revision = mapping.revision_id_foreign_to_bzr(hexsha)
0.252.25 by Jelmer Vernooij
Reformatting.
210
    texts.insert_record_stream([
211
        ChunkedContentFactory((file_id, ie.revision), (), None, [])])
0.200.1408 by Jelmer Vernooij
Remove old ie children when converting directory into tree reference.
212
    invdelta.append((old_path, path, file_id, ie))
0.200.839 by Jelmer Vernooij
Add convenience object for updating the object store caching layer.
213
    return invdelta, {}
0.200.540 by Jelmer Vernooij
Handle submodules explicitly.
214
215
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
216
def remove_disappeared_children(base_bzr_tree, path, base_tree, existing_children,
0.200.820 by Jelmer Vernooij
Avoid relying on InventoryDirectory.children.
217
        lookup_object):
0.200.930 by Jelmer Vernooij
Add assert demonstrating 571055 and triggering it for all target formats.
218
    """Generate an inventory delta for removed children.
219
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
220
    :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.
221
        inventory delta.
0.200.984 by Jelmer Vernooij
Handle non-ascii characters in filenames.
222
    :param path: Path to process (unicode)
0.200.930 by Jelmer Vernooij
Add assert demonstrating 571055 and triggering it for all target formats.
223
    :param base_tree: Git Tree base object
224
    :param existing_children: Children that still exist
225
    :param lookup_object: Lookup a git object by its SHA1
226
    :return: Inventory delta, as list
227
    """
0.200.984 by Jelmer Vernooij
Handle non-ascii characters in filenames.
228
    assert type(path) is unicode
0.200.552 by Jelmer Vernooij
Cope with directories becoming symlinks.
229
    ret = []
0.200.820 by Jelmer Vernooij
Avoid relying on InventoryDirectory.children.
230
    for name, mode, hexsha in base_tree.iteritems():
231
        if name in existing_children:
232
            continue
233
        c_path = posixpath.join(path, name.decode("utf-8"))
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
234
        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.
235
        assert file_id is not None
236
        ret.append((c_path, None, file_id, None))
0.200.820 by Jelmer Vernooij
Avoid relying on InventoryDirectory.children.
237
        if stat.S_ISDIR(mode):
238
            ret.extend(remove_disappeared_children(
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
239
                base_bzr_tree, c_path, lookup_object(hexsha), [], lookup_object))
0.200.552 by Jelmer Vernooij
Cope with directories becoming symlinks.
240
    return ret
241
242
0.200.821 by Jelmer Vernooij
Remove last references to ID.children.
243
def import_git_tree(texts, mapping, path, name, (base_hexsha, hexsha),
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
244
        base_bzr_tree, parent_id, revision_id, parent_bzr_trees,
0.200.896 by Jelmer Vernooij
Add separate function for looking up file ids.
245
        lookup_object, (base_mode, mode), store_updater,
246
        lookup_file_id, allow_submodules=False):
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
247
    """Import a git tree object into a bzr repository.
248
0.200.261 by Jelmer Vernooij
More formatting fixes.
249
    :param texts: VersionedFiles object to add to
0.200.984 by Jelmer Vernooij
Handle non-ascii characters in filenames.
250
    :param path: Path in the tree (str)
251
    :param name: Name of the tree (str)
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
252
    :param tree: A git tree object
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
253
    :param base_bzr_tree: Base inventory against which to return inventory delta
0.229.1 by Jelmer Vernooij
Start working with inventory deltas.
254
    :return: Inventory delta for this subtree
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
255
    """
0.200.984 by Jelmer Vernooij
Handle non-ascii characters in filenames.
256
    assert type(path) is str
257
    assert type(name) is str
0.200.817 by Jelmer Vernooij
Deal with all modes locally.
258
    if base_hexsha == hexsha and base_mode == mode:
259
        # 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.
260
        return [], {}
0.200.344 by Jelmer Vernooij
Clarify names, use convenience function
261
    invdelta = []
0.200.896 by Jelmer Vernooij
Add separate function for looking up file ids.
262
    file_id = lookup_file_id(path)
0.200.297 by Jelmer Vernooij
Cope with non-ascii characters in filenames (needs a test..).
263
    # We just have to hope this is indeed utf-8:
0.200.821 by Jelmer Vernooij
Remove last references to ID.children.
264
    ie = InventoryDirectory(file_id, name.decode("utf-8"), parent_id)
0.200.817 by Jelmer Vernooij
Deal with all modes locally.
265
    tree = lookup_object(hexsha)
266
    if base_hexsha is None:
267
        base_tree = None
0.200.823 by Jelmer Vernooij
Simplify logic in import_git_tree a bit.
268
        old_path = None # Newly appeared here
0.200.817 by Jelmer Vernooij
Deal with all modes locally.
269
    else:
270
        base_tree = lookup_object(base_hexsha)
0.200.984 by Jelmer Vernooij
Handle non-ascii characters in filenames.
271
        old_path = path.decode("utf-8") # Renames aren't supported yet
272
    new_path = path.decode("utf-8")
0.200.823 by Jelmer Vernooij
Simplify logic in import_git_tree a bit.
273
    if base_tree is None or type(base_tree) is not Tree:
274
        ie.revision = revision_id
0.200.984 by Jelmer Vernooij
Handle non-ascii characters in filenames.
275
        invdelta.append((old_path, new_path, ie.file_id, ie))
0.252.24 by Jelmer Vernooij
Support reading fileid map.
276
        texts.insert_record_stream([
277
            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).
278
    # Remember for next time
0.200.300 by Jelmer Vernooij
Fix recursive deletion of dirs.
279
    existing_children = set()
0.200.345 by Jelmer Vernooij
Keep track of file modes to use.
280
    child_modes = {}
0.200.1147 by Jelmer Vernooij
Use Tree.items() rather than Tree.entries().
281
    for name, child_mode, child_hexsha in tree.iteritems():
0.200.820 by Jelmer Vernooij
Avoid relying on InventoryDirectory.children.
282
        existing_children.add(name)
0.200.819 by Jelmer Vernooij
Avoid decoding basename twice.
283
        child_path = posixpath.join(path, name)
0.200.814 by Jelmer Vernooij
Avoid the use of InventoryDirectory.children. This speeds up
284
        if type(base_tree) is Tree:
285
            try:
286
                child_base_mode, child_base_hexsha = base_tree[name]
287
            except KeyError:
288
                child_base_hexsha = None
289
                child_base_mode = 0
290
        else:
291
            child_base_hexsha = None
292
            child_base_mode = 0
0.200.816 by Jelmer Vernooij
Leave mode handling for blobs to import_git_blob.
293
        if stat.S_ISDIR(child_mode):
0.252.25 by Jelmer Vernooij
Reformatting.
294
            subinvdelta, grandchildmodes = import_git_tree(texts, mapping,
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
295
                child_path, name, (child_base_hexsha, child_hexsha),
296
                base_bzr_tree, file_id, revision_id, parent_bzr_trees,
297
                lookup_object, (child_base_mode, child_mode), store_updater,
298
                lookup_file_id, allow_submodules=allow_submodules)
0.200.816 by Jelmer Vernooij
Leave mode handling for blobs to import_git_blob.
299
        elif S_ISGITLINK(child_mode): # submodule
0.200.666 by Jelmer Vernooij
Refuse to add tree references to non-subtree formats.
300
            if not allow_submodules:
301
                raise SubmodulesRequireSubtrees()
0.252.25 by Jelmer Vernooij
Reformatting.
302
            subinvdelta, grandchildmodes = import_git_submodule(texts, mapping,
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
303
                child_path, name, (child_base_hexsha, child_hexsha),
304
                base_bzr_tree, file_id, revision_id, parent_bzr_trees,
305
                lookup_object, (child_base_mode, child_mode), store_updater,
306
                lookup_file_id)
0.200.352 by Jelmer Vernooij
Simplify mode handling.
307
        else:
0.200.1328 by Jelmer Vernooij
More test fixes.
308
            if not mapping.is_special_file(name):
309
                subinvdelta = import_git_blob(texts, mapping, child_path, name,
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
310
                    (child_base_hexsha, child_hexsha), base_bzr_tree, file_id,
311
                    revision_id, parent_bzr_trees, lookup_object,
0.200.1328 by Jelmer Vernooij
More test fixes.
312
                    (child_base_mode, child_mode), store_updater, lookup_file_id)
313
            else:
314
                subinvdelta = []
0.200.757 by Jelmer Vernooij
Use inventory deltas.
315
            grandchildmodes = {}
316
        child_modes.update(grandchildmodes)
317
        invdelta.extend(subinvdelta)
0.200.816 by Jelmer Vernooij
Leave mode handling for blobs to import_git_blob.
318
        if child_mode not in (stat.S_IFDIR, DEFAULT_FILE_MODE,
0.200.1407 by Jelmer Vernooij
Don't consider submodule modes unusual.
319
                        stat.S_IFLNK, DEFAULT_FILE_MODE|0111,
320
                        S_IFGITLINK):
0.200.879 by Jelmer Vernooij
Fix unusual modes.
321
            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).
322
    # Remove any children that have disappeared
0.200.817 by Jelmer Vernooij
Deal with all modes locally.
323
    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.
324
        invdelta.extend(remove_disappeared_children(base_bzr_tree, old_path,
0.200.820 by Jelmer Vernooij
Avoid relying on InventoryDirectory.children.
325
            base_tree, existing_children, lookup_object))
0.275.2 by Jelmer Vernooij
Pass tuples around for cache entries, rather than inventory entries.
326
    store_updater.add_object(tree, (file_id, ), path)
0.200.839 by Jelmer Vernooij
Add convenience object for updating the object store caching layer.
327
    return invdelta, child_modes
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
328
329
0.200.883 by Jelmer Vernooij
Add function for verifying reconstruction of objects still works.
330
def verify_commit_reconstruction(target_git_object_retriever, lookup_object,
0.200.1047 by Jelmer Vernooij
Fix -Dverify.
331
    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.
332
    new_unusual_modes = mapping.export_unusual_file_modes(rev)
333
    if new_unusual_modes != unusual_modes:
334
        raise AssertionError("unusual modes don't match: %r != %r" % (
335
            unusual_modes, new_unusual_modes))
336
    # Verify that we can reconstruct the commit properly
0.200.1047 by Jelmer Vernooij
Fix -Dverify.
337
    rec_o = target_git_object_retriever._reconstruct_commit(rev, o.tree, True,
338
        verifiers)
0.200.883 by Jelmer Vernooij
Add function for verifying reconstruction of objects still works.
339
    if rec_o != o:
340
        raise AssertionError("Reconstructed commit differs: %r != %r" % (
341
            rec_o, o))
342
    diff = []
343
    new_objs = {}
344
    for path, obj, ie in _tree_to_objects(ret_tree, parent_trees,
0.200.1309 by Jelmer Vernooij
Break some more long lines.
345
        target_git_object_retriever._cache.idmap, unusual_modes,
346
        mapping.BZR_DUMMY_FILE):
0.200.883 by Jelmer Vernooij
Add function for verifying reconstruction of objects still works.
347
        old_obj_id = tree_lookup_path(lookup_object, o.tree, path)[1]
348
        new_objs[path] = obj
349
        if obj.id != old_obj_id:
350
            diff.append((path, lookup_object(old_obj_id), obj))
351
    for (path, old_obj, new_obj) in diff:
352
        while (old_obj.type_name == "tree" and
353
               new_obj.type_name == "tree" and
354
               sorted(old_obj) == sorted(new_obj)):
355
            for name in old_obj:
356
                if old_obj[name][0] != new_obj[name][0]:
0.252.25 by Jelmer Vernooij
Reformatting.
357
                    raise AssertionError("Modes for %s differ: %o != %o" %
358
                        (path, old_obj[name][0], new_obj[name][0]))
0.200.883 by Jelmer Vernooij
Add function for verifying reconstruction of objects still works.
359
                if old_obj[name][1] != new_obj[name][1]:
360
                    # Found a differing child, delve deeper
361
                    path = posixpath.join(path, name)
362
                    old_obj = lookup_object(old_obj[name][1])
363
                    new_obj = new_objs[path]
364
                    break
365
        raise AssertionError("objects differ for %s: %r != %r" % (path,
366
            old_obj, new_obj))
367
368
0.200.1409 by Jelmer Vernooij
Support fetching into repositories that are stacked.
369
def ensure_inventories_in_repo(repo, trees):
370
    real_inv_vf = repo.inventories.without_fallbacks()
371
    for t in trees:
372
        revid = t.get_revision_id()
373
        if not real_inv_vf.get_parent_map([(revid, )]):
374
            repo.add_inventory(revid, t.inventory, t.get_parent_ids())
375
376
0.200.679 by Jelmer Vernooij
Moving commit import functionality to a separate function.
377
def import_git_commit(repo, mapping, head, lookup_object,
0.200.852 by Jelmer Vernooij
Cache trees rather than inventories.
378
                      target_git_object_retriever, trees_cache):
0.200.679 by Jelmer Vernooij
Moving commit import functionality to a separate function.
379
    o = lookup_object(head)
0.261.5 by Jelmer Vernooij
Fix looking up of parents during fetch.
380
    # Note that this uses mapping.revision_id_foreign_to_bzr. If the parents
381
    # were bzr roundtripped revisions they would be specified in the
382
    # roundtrip data.
0.261.4 by Jelmer Vernooij
Fix tests.
383
    rev, roundtrip_revid, verifiers = mapping.import_commit(
0.261.5 by Jelmer Vernooij
Fix looking up of parents during fetch.
384
        o, mapping.revision_id_foreign_to_bzr)
0.200.1329 by Jelmer Vernooij
Fix more tests.
385
    if roundtrip_revid is not None:
386
        original_revid = rev.revision_id
387
        rev.revision_id = roundtrip_revid
0.200.679 by Jelmer Vernooij
Moving commit import functionality to a separate function.
388
    # We have to do this here, since we have to walk the tree and
389
    # we need to make sure to import the blobs / trees with the right
390
    # path; this may involve adding them more than once.
0.200.852 by Jelmer Vernooij
Cache trees rather than inventories.
391
    parent_trees = trees_cache.revision_trees(rev.parent_ids)
0.200.1409 by Jelmer Vernooij
Support fetching into repositories that are stacked.
392
    ensure_inventories_in_repo(repo, parent_trees)
0.200.852 by Jelmer Vernooij
Cache trees rather than inventories.
393
    if parent_trees == []:
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
394
        base_bzr_tree = trees_cache.revision_tree(NULL_REVISION)
0.200.814 by Jelmer Vernooij
Avoid the use of InventoryDirectory.children. This speeds up
395
        base_tree = None
0.200.817 by Jelmer Vernooij
Deal with all modes locally.
396
        base_mode = None
0.200.679 by Jelmer Vernooij
Moving commit import functionality to a separate function.
397
    else:
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
398
        base_bzr_tree = parent_trees[0]
0.200.814 by Jelmer Vernooij
Avoid the use of InventoryDirectory.children. This speeds up
399
        base_tree = lookup_object(o.parents[0]).tree
0.200.817 by Jelmer Vernooij
Deal with all modes locally.
400
        base_mode = stat.S_IFDIR
0.200.839 by Jelmer Vernooij
Add convenience object for updating the object store caching layer.
401
    store_updater = target_git_object_retriever._get_updater(rev)
0.200.1324 by Jelmer Vernooij
More work on roundtripping support.
402
    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.
403
    inv_delta, unusual_modes = import_git_tree(repo.texts,
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
404
            mapping, "", "", (base_tree, o.tree), base_bzr_tree,
405
            None, rev.revision_id, parent_trees,
0.200.852 by Jelmer Vernooij
Cache trees rather than inventories.
406
            lookup_object, (base_mode, stat.S_IFDIR), store_updater,
0.200.1324 by Jelmer Vernooij
More work on roundtripping support.
407
            tree_supplement.lookup_file_id,
0.200.1309 by Jelmer Vernooij
Break some more long lines.
408
            allow_submodules=getattr(repo._format, "supports_tree_reference",
409
                False))
0.200.679 by Jelmer Vernooij
Moving commit import functionality to a separate function.
410
    if unusual_modes != {}:
411
        for path, mode in unusual_modes.iteritems():
412
            warn_unusual_mode(rev.foreign_revid, path, mode)
413
        mapping.import_unusual_file_modes(rev, unusual_modes)
414
    try:
415
        basis_id = rev.parent_ids[0]
416
    except IndexError:
417
        basis_id = NULL_REVISION
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
418
        base_bzr_inventory = None
419
    else:
420
        try:
421
            base_bzr_inventory = base_bzr_tree.root_inventory
422
        except AttributeError: # bzr < 2.6
423
            base_bzr_inventory = base_bzr_tree.inventory
0.200.679 by Jelmer Vernooij
Moving commit import functionality to a separate function.
424
    rev.inventory_sha1, inv = repo.add_inventory_by_delta(basis_id,
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
425
              inv_delta, rev.revision_id, rev.parent_ids,
426
              base_bzr_inventory)
0.200.1195 by Jelmer Vernooij
Cope with new StrictTestament3 arguments.
427
    ret_tree = InventoryRevisionTree(repo, inv, rev.revision_id)
0.200.1329 by Jelmer Vernooij
Fix more tests.
428
    # Check verifiers
429
    if verifiers and roundtrip_revid is not None:
0.200.1559 by Jelmer Vernooij
Fix compatibility with bzr 2.5.
430
        testament = StrictTestament3(rev, ret_tree)
0.200.1329 by Jelmer Vernooij
Fix more tests.
431
        calculated_verifiers = { "testament3-sha1": testament.as_sha1() }
432
        if calculated_verifiers != verifiers:
433
            trace.mutter("Testament SHA1 %r for %r did not match %r.",
434
                         calculated_verifiers["testament3-sha1"],
435
                         rev.revision_id, verifiers["testament3-sha1"])
436
            rev.revision_id = original_revid
437
            rev.inventory_sha1, inv = repo.add_inventory_by_delta(basis_id,
0.275.3 by Jelmer Vernooij
Avoid inventories in a few more places.
438
              inv_delta, rev.revision_id, rev.parent_ids, base_bzr_tree)
0.200.1329 by Jelmer Vernooij
Fix more tests.
439
            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.
440
    else:
441
        calculated_verifiers = {}
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
442
    store_updater.add_object(o, calculated_verifiers, None)
443
    store_updater.finish()
0.200.883 by Jelmer Vernooij
Add function for verifying reconstruction of objects still works.
444
    trees_cache.add(ret_tree)
0.200.679 by Jelmer Vernooij
Moving commit import functionality to a separate function.
445
    repo.add_revision(rev.revision_id, rev)
446
    if "verify" in debug.debug_flags:
0.200.883 by Jelmer Vernooij
Add function for verifying reconstruction of objects still works.
447
        verify_commit_reconstruction(target_git_object_retriever, 
448
            lookup_object, o, rev, ret_tree, parent_trees, mapping,
0.200.1047 by Jelmer Vernooij
Fix -Dverify.
449
            unusual_modes, verifiers)
0.200.679 by Jelmer Vernooij
Moving commit import functionality to a separate function.
450
451
0.248.5 by Jelmer Vernooij
Reformatting, fix dpush.
452
def import_git_objects(repo, mapping, object_iter,
453
    target_git_object_retriever, heads, pb=None, limit=None):
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
454
    """Import a set of git objects into a bzr repository.
455
0.200.483 by Jelmer Vernooij
Add NEWS entry about sha map.
456
    :param repo: Target Bazaar repository
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
457
    :param mapping: Mapping to use
458
    :param object_iter: Iterator over Git objects.
0.248.5 by Jelmer Vernooij
Reformatting, fix dpush.
459
    :return: Tuple with pack hints and last imported revision id
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
460
    """
0.200.469 by Jelmer Vernooij
Fix fetch when revisions are already present locally, just only mapped.
461
    def lookup_object(sha):
462
        try:
463
            return object_iter[sha]
464
        except KeyError:
465
            return target_git_object_retriever[sha]
0.200.158 by Jelmer Vernooij
fetch works \o/
466
    graph = []
0.200.296 by Jelmer Vernooij
Avoid iterating over all objects just to find the *Commits* to retrieve.
467
    checked = set()
0.200.734 by Jelmer Vernooij
Don't import head revision twice when pulling from Git.
468
    heads = list(set(heads))
0.200.852 by Jelmer Vernooij
Cache trees rather than inventories.
469
    trees_cache = LRUTreeCache(repo)
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
470
    # Find and convert commit objects
0.200.296 by Jelmer Vernooij
Avoid iterating over all objects just to find the *Commits* to retrieve.
471
    while heads:
472
        if pb is not None:
473
            pb.update("finding revisions to fetch", len(graph), None)
474
        head = heads.pop()
0.200.1350 by Jelmer Vernooij
Implement search_missing_revision_ids.
475
        if head == ZERO_SHA:
476
            continue
0.269.8 by Jelmer Vernooij
Support push in git-remote-bzr.
477
        assert isinstance(head, str), "head is %r" % (head,)
0.200.310 by Jelmer Vernooij
Fix pull from remote branches.
478
        try:
0.248.5 by Jelmer Vernooij
Reformatting, fix dpush.
479
            o = lookup_object(head)
0.200.310 by Jelmer Vernooij
Fix pull from remote branches.
480
        except KeyError:
481
            continue
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
482
        if isinstance(o, Commit):
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
483
            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.
484
                mapping.revision_id_foreign_to_bzr)
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
485
            if (repo.has_revision(rev.revision_id) or
486
                (roundtrip_revid and repo.has_revision(roundtrip_revid))):
0.200.295 by Jelmer Vernooij
Don't re-import revisions already fetched.
487
                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.
488
            graph.append((o.id, o.parents))
0.200.296 by Jelmer Vernooij
Avoid iterating over all objects just to find the *Commits* to retrieve.
489
            heads.extend([p for p in o.parents if p not in checked])
0.200.303 by Jelmer Vernooij
Cope with tags during fetch.
490
        elif isinstance(o, Tag):
0.200.734 by Jelmer Vernooij
Don't import head revision twice when pulling from Git.
491
            if o.object[1] not in checked:
492
                heads.append(o.object[1])
0.200.296 by Jelmer Vernooij
Avoid iterating over all objects just to find the *Commits* to retrieve.
493
        else:
494
            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.
495
        checked.add(o.id)
496
    del checked
0.200.158 by Jelmer Vernooij
fetch works \o/
497
    # Order the revisions
0.200.151 by Jelmer Vernooij
Support converting git objects to bzr objects.
498
    # Create the inventory objects
0.200.821 by Jelmer Vernooij
Remove last references to ID.children.
499
    batch_size = 1000
0.200.680 by Jelmer Vernooij
fetch revisions in batches
500
    revision_ids = topo_sort(graph)
501
    pack_hints = []
0.247.2 by Michael Hudson
this works for my tests, but i'm pretty sure it's wrong in general
502
    if limit is not None:
503
        revision_ids = revision_ids[:limit]
0.247.3 by Michael Hudson
oh, so it wasn't (particularly) wrong, but it was a bit obscure
504
    last_imported = None
0.200.680 by Jelmer Vernooij
fetch revisions in batches
505
    for offset in range(0, len(revision_ids), batch_size):
0.254.33 by Jelmer Vernooij
Merge trunk.
506
        target_git_object_retriever.start_write_group() 
0.200.680 by Jelmer Vernooij
fetch revisions in batches
507
        try:
0.254.33 by Jelmer Vernooij
Merge trunk.
508
            repo.start_write_group()
509
            try:
0.200.824 by Jelmer Vernooij
Commit cache data in batches as well.
510
                for i, head in enumerate(
511
                    revision_ids[offset:offset+batch_size]):
0.254.33 by Jelmer Vernooij
Merge trunk.
512
                    if pb is not None:
0.200.824 by Jelmer Vernooij
Commit cache data in batches as well.
513
                        pb.update("fetching revisions", offset+i,
514
                                  len(revision_ids))
0.254.33 by Jelmer Vernooij
Merge trunk.
515
                    import_git_commit(repo, mapping, head, lookup_object,
0.252.25 by Jelmer Vernooij
Reformatting.
516
                        target_git_object_retriever, trees_cache)
0.254.33 by Jelmer Vernooij
Merge trunk.
517
                    last_imported = head
518
            except:
519
                repo.abort_write_group()
520
                raise
521
            else:
522
                hint = repo.commit_write_group()
523
                if hint is not None:
524
                    pack_hints.extend(hint)
0.200.680 by Jelmer Vernooij
fetch revisions in batches
525
        except:
0.254.33 by Jelmer Vernooij
Merge trunk.
526
            target_git_object_retriever.abort_write_group()
0.200.680 by Jelmer Vernooij
fetch revisions in batches
527
            raise
528
        else:
0.254.33 by Jelmer Vernooij
Merge trunk.
529
            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
530
    return pack_hints, last_imported
0.200.141 by Jelmer Vernooij
Separate out local and remote fetching.
531
532
0.200.1350 by Jelmer Vernooij
Implement search_missing_revision_ids.
533
class InterFromGitRepository(InterRepository):
0.200.135 by Jelmer Vernooij
Add stub for fetching data.
534
0.200.289 by Jelmer Vernooij
Cope with new member variables in RepositoryFormat.
535
    _matching_repo_format = GitRepositoryFormat()
0.200.143 by Jelmer Vernooij
Reoncile InterGitRepository objects.
536
0.200.1154 by Jelmer Vernooij
Share more code in InterGitRepository.
537
    def _target_has_shas(self, shas):
538
        raise NotImplementedError(self._target_has_shas)
539
540
    def get_determine_wants_heads(self, wants, include_tags=False):
0.200.1490 by Jelmer Vernooij
Fix target_has_shas.
541
        raise NotImplementedError(self.get_determine_wants_heads)
0.200.1154 by Jelmer Vernooij
Share more code in InterGitRepository.
542
543
    def determine_wants_all(self, refs):
0.200.1490 by Jelmer Vernooij
Fix target_has_shas.
544
        raise NotImplementedError(self.determine_wants_all)
0.200.1154 by Jelmer Vernooij
Share more code in InterGitRepository.
545
0.200.143 by Jelmer Vernooij
Reoncile InterGitRepository objects.
546
    @staticmethod
547
    def _get_repo_format_to_test():
548
        return None
549
0.200.1492 by Jelmer Vernooij
Fix test
550
    def copy_content(self, revision_id=None):
0.200.135 by Jelmer Vernooij
Add stub for fetching data.
551
        """See InterRepository.copy_content."""
0.200.1492 by Jelmer Vernooij
Fix test
552
        self.fetch(revision_id, find_ghosts=False)
0.200.135 by Jelmer Vernooij
Add stub for fetching data.
553
0.200.1350 by Jelmer Vernooij
Implement search_missing_revision_ids.
554
    def search_missing_revision_ids(self,
555
            find_ghosts=True, revision_ids=None, if_present_ids=None,
556
            limit=None):
557
        git_shas = []
558
        todo = []
559
        if revision_ids:
560
            todo.extend(revision_ids)
561
        if if_present_ids:
562
            todo.extend(revision_ids)
563
        for revid in revision_ids:
564
            if revid == NULL_REVISION:
565
                continue
566
            git_sha, mapping = self.source.lookup_bzr_revision_id(revid)
567
            git_shas.append(git_sha)
568
        walker = Walker(self.source._git.object_store,
0.200.1493 by Jelmer Vernooij
Test fixes.
569
            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.
570
        missing_revids = set()
571
        for entry in walker:
572
            missing_revids.add(self.source.lookup_foreign_revision_id(entry.commit.id))
573
        return self.source.revision_ids_to_search_result(missing_revids)
574
575
576
class InterGitNonGitRepository(InterFromGitRepository):
0.200.664 by Jelmer Vernooij
Support submodules during fetch.
577
    """Base InterRepository that copies revisions from a Git into a non-Git
0.200.456 by Jelmer Vernooij
Fix git -> git fetching.
578
    repository."""
579
0.259.4 by Jelmer Vernooij
Put determine_wants methods on InterRepo.
580
    def _target_has_shas(self, shas):
0.200.1456 by Jelmer Vernooij
Fix target_has_shas.
581
        revids = {}
0.200.1403 by Jelmer Vernooij
Cope with tags pointing at tree objects when cloning local git repositories.
582
        for sha in shas:
583
            try:
584
                revid = self.source.lookup_foreign_revision_id(sha)
585
            except NotCommitError:
0.200.1456 by Jelmer Vernooij
Fix target_has_shas.
586
                # Commit is definitely not present
0.200.1403 by Jelmer Vernooij
Cope with tags pointing at tree objects when cloning local git repositories.
587
                continue
588
            else:
0.200.1456 by Jelmer Vernooij
Fix target_has_shas.
589
                revids[revid] = sha
590
        return set([revids[r] for r in self.target.has_revisions(revids)])
0.259.4 by Jelmer Vernooij
Put determine_wants methods on InterRepo.
591
0.200.1489 by Jelmer Vernooij
More fixes to peel handling.
592
    def determine_wants_all(self, refs):
593
        potential = set()
594
        for k, v in refs.as_dict().iteritems():
595
            # For non-git target repositories, only worry about peeled
0.200.1513 by Jelmer Vernooij
Cope with zero shas.
596
            if v == ZERO_SHA:
597
                continue
0.200.1489 by Jelmer Vernooij
More fixes to peel handling.
598
            potential.add(self.source.bzrdir.get_peeled(k))
599
        return list(potential - self._target_has_shas(potential))
600
0.200.1490 by Jelmer Vernooij
Fix target_has_shas.
601
    def get_determine_wants_heads(self, wants, include_tags=False):
602
        wants = set(wants)
603
        def determine_wants(refs):
604
            potential = set(wants)
605
            if include_tags:
606
                for k, unpeeled in refs.as_dict().iteritems():
607
                    if not is_tag(k):
608
                        continue
0.200.1513 by Jelmer Vernooij
Cope with zero shas.
609
                    if unpeeled == ZERO_SHA:
610
                        continue
0.200.1490 by Jelmer Vernooij
Fix target_has_shas.
611
                    potential.add(self.source.bzrdir.get_peeled(k))
612
            return list(potential - self._target_has_shas(potential))
613
        return determine_wants
614
0.259.6 by Jelmer Vernooij
Fetch tags during pull.
615
    def get_determine_wants_revids(self, revids, include_tags=False):
616
        wants = set()
617
        for revid in set(revids):
0.200.1388 by Jelmer Vernooij
Don't fetch revision already present.
618
            if self.target.has_revision(revid):
619
                continue
0.259.6 by Jelmer Vernooij
Fetch tags during pull.
620
            git_sha, mapping = self.source.lookup_bzr_revision_id(revid)
621
            wants.add(git_sha)
0.200.1489 by Jelmer Vernooij
More fixes to peel handling.
622
        return self.get_determine_wants_heads(wants, include_tags=include_tags)
0.259.6 by Jelmer Vernooij
Fetch tags during pull.
623
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
624
    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().
625
        """Fetch objects from a remote server.
626
627
        :param determine_wants: determine_wants callback
628
        :param mapping: BzrGitMapping to use
629
        :param limit: Maximum number of commits to import.
0.200.1002 by Jelmer Vernooij
Fix regression in git-import.
630
        :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().
631
        """
632
        raise NotImplementedError(self.fetch_objects)
633
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
634
    def fetch(self, revision_id=None, find_ghosts=False,
0.200.247 by Jelmer Vernooij
Fix git-import.
635
              mapping=None, fetch_spec=None):
0.200.225 by Jelmer Vernooij
Implement custom InterBranch to support fetching from remote git branches.
636
        if mapping is None:
637
            mapping = self.source.get_mapping()
0.226.2 by Jelmer Vernooij
Cope with new fetch_spec argument.
638
        if revision_id is not None:
639
            interesting_heads = [revision_id]
640
        elif fetch_spec is not None:
0.200.1089 by Jelmer Vernooij
Cope with fancy fetch_spec behaviour.
641
            recipe = fetch_spec.get_recipe()
642
            if recipe[0] in ("search", "proxy-search"):
643
                interesting_heads = recipe[1]
644
            else:
0.200.1300 by Jelmer Vernooij
Fix formatting.
645
                raise AssertionError("Unsupported search result type %s" %
646
                        recipe[0])
0.226.2 by Jelmer Vernooij
Cope with new fetch_spec argument.
647
        else:
648
            interesting_heads = None
0.259.4 by Jelmer Vernooij
Put determine_wants methods on InterRepo.
649
650
        if interesting_heads is not None:
0.200.1309 by Jelmer Vernooij
Break some more long lines.
651
            determine_wants = self.get_determine_wants_revids(
652
                interesting_heads, include_tags=False)
0.259.4 by Jelmer Vernooij
Put determine_wants methods on InterRepo.
653
        else:
654
            determine_wants = self.determine_wants_all
0.200.1079 by Jelmer Vernooij
Avoid looking up revid if not necessary.
655
656
        (pack_hint, _, remote_refs) = self.fetch_objects(determine_wants,
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
657
            mapping)
0.200.579 by Jelmer Vernooij
Only pack if it makes the target repo smaller.
658
        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.
659
            self.target.pack(hint=pack_hint)
0.200.1002 by Jelmer Vernooij
Fix regression in git-import.
660
        return remote_refs
0.200.225 by Jelmer Vernooij
Implement custom InterBranch to support fetching from remote git branches.
661
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
662
0.200.563 by Jelmer Vernooij
Attempt to parse progress indication from git status reports.
663
_GIT_PROGRESS_RE = re.compile(r"(.*?): +(\d+)% \((\d+)/(\d+)\)")
664
def report_git_progress(pb, text):
665
    text = text.rstrip("\r\n")
666
    g = _GIT_PROGRESS_RE.match(text)
667
    if g is not None:
668
        (text, pct, current, total) = g.groups()
669
        pb.update(text, int(current), int(total))
670
    else:
671
        pb.update(text, 0, 0)
672
673
0.200.1001 by Jelmer Vernooij
Simplify handling of determine wants, add stub for fetch_objects().
674
class DetermineWantsRecorder(object):
675
676
    def __init__(self, actual):
677
        self.actual = actual
678
        self.wants = []
679
        self.remote_refs = {}
680
681
    def __call__(self, refs):
682
        self.remote_refs = refs
683
        self.wants = self.actual(refs)
684
        return self.wants
685
686
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
687
class InterRemoteGitNonGitRepository(InterGitNonGitRepository):
0.200.664 by Jelmer Vernooij
Support submodules during fetch.
688
    """InterRepository that copies revisions from a remote Git into a non-Git
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
689
    repository."""
690
0.200.582 by Jelmer Vernooij
Use more efficient algorithm for finding out heads.
691
    def get_target_heads(self):
692
        # FIXME: This should be more efficient
693
        all_revs = self.target.all_revision_ids()
694
        parent_map = self.target.get_parent_map(all_revs)
695
        all_parents = set()
696
        map(all_parents.update, parent_map.itervalues())
697
        return set(all_revs) - all_parents
698
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
699
    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().
700
        """See `InterGitNonGitRepository`."""
0.200.466 by Jelmer Vernooij
Fix finding of heads for fetch_objects.
701
        store = BazaarObjectStore(self.target, mapping)
0.200.1212 by Jelmer Vernooij
Support read locking object stores.
702
        store.lock_write()
0.200.465 by Jelmer Vernooij
Use dulwich standard functionality for finding missing revisions.
703
        try:
0.200.582 by Jelmer Vernooij
Use more efficient algorithm for finding out heads.
704
            heads = self.get_target_heads()
0.200.484 by Jelmer Vernooij
Cope with kind changes.
705
            graph_walker = store.get_graph_walker(
706
                    [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().
707
            wants_recorder = DetermineWantsRecorder(determine_wants)
0.200.664 by Jelmer Vernooij
Support submodules during fetch.
708
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
709
            pb = ui.ui_factory.nested_progress_bar()
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
710
            try:
0.200.1000 by Jelmer Vernooij
Fix fetch between local and remote git branches.
711
                objects_iter = self.source.fetch_objects(
0.200.1001 by Jelmer Vernooij
Simplify handling of determine wants, add stub for fetch_objects().
712
                    wants_recorder, graph_walker, store.get_raw,
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
713
                    progress=lambda text: report_git_progress(pb, text))
0.200.1300 by Jelmer Vernooij
Fix formatting.
714
                trace.mutter("Importing %d new revisions",
715
                             len(wants_recorder.wants))
716
                (pack_hint, last_rev) = import_git_objects(self.target,
717
                    mapping, objects_iter, store, wants_recorder.wants, pb,
718
                    limit)
0.200.1002 by Jelmer Vernooij
Fix regression in git-import.
719
                return (pack_hint, last_rev, wants_recorder.remote_refs)
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
720
            finally:
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
721
                pb.finished()
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
722
        finally:
0.200.1212 by Jelmer Vernooij
Support read locking object stores.
723
            store.unlock()
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
724
725
    @staticmethod
726
    def is_compatible(source, target):
727
        """Be compatible with GitRepository."""
0.200.1222 by Jelmer Vernooij
Better checks in is_compatible methods.
728
        if not isinstance(source, RemoteGitRepository):
729
            return False
730
        if not target.supports_rich_root():
731
            return False
732
        if isinstance(target, GitRepository):
733
            return False
0.200.1270 by Jelmer Vernooij
Cope with older versions of bzr.
734
        if not getattr(target._format, "supports_full_versioned_files", True):
0.200.1222 by Jelmer Vernooij
Better checks in is_compatible methods.
735
            return False
736
        return True
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
737
738
739
class InterLocalGitNonGitRepository(InterGitNonGitRepository):
0.200.664 by Jelmer Vernooij
Support submodules during fetch.
740
    """InterRepository that copies revisions from a local Git into a non-Git
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
741
    repository."""
742
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
743
    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().
744
        """See `InterGitNonGitRepository`."""
0.200.1487 by Jelmer Vernooij
Use peeling.
745
        remote_refs = self.source.bzrdir.get_refs_container()
0.200.1002 by Jelmer Vernooij
Fix regression in git-import.
746
        wants = determine_wants(remote_refs)
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
747
        create_pb = None
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
748
        pb = ui.ui_factory.nested_progress_bar()
0.200.320 by Jelmer Vernooij
Handle lightweight checkouts.
749
        target_git_object_retriever = BazaarObjectStore(self.target, mapping)
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
750
        try:
0.200.1212 by Jelmer Vernooij
Support read locking object stores.
751
            target_git_object_retriever.lock_write()
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
752
            try:
0.200.1300 by Jelmer Vernooij
Fix formatting.
753
                (pack_hint, last_rev) = import_git_objects(self.target,
754
                    mapping, self.source._git.object_store,
0.248.5 by Jelmer Vernooij
Reformatting, fix dpush.
755
                    target_git_object_retriever, wants, pb, limit)
0.200.1002 by Jelmer Vernooij
Fix regression in git-import.
756
                return (pack_hint, last_rev, remote_refs)
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
757
            finally:
0.200.1212 by Jelmer Vernooij
Support read locking object stores.
758
                target_git_object_retriever.unlock()
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
759
        finally:
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
760
            pb.finished()
0.200.306 by Jelmer Vernooij
Fix tests, split up InterGitNonGitRepository.
761
762
    @staticmethod
763
    def is_compatible(source, target):
764
        """Be compatible with GitRepository."""
0.200.1222 by Jelmer Vernooij
Better checks in is_compatible methods.
765
        if not isinstance(source, LocalGitRepository):
766
            return False
767
        if not target.supports_rich_root():
768
            return False
769
        if isinstance(target, GitRepository):
770
            return False
0.200.1266 by Jelmer Vernooij
Fix 2.3 support.
771
        if not getattr(target._format, "supports_full_versioned_files", True):
0.200.1222 by Jelmer Vernooij
Better checks in is_compatible methods.
772
            return False
773
        return True
0.200.175 by Jelmer Vernooij
Add optimized handling when fetching from git to git.
774
775
0.200.1350 by Jelmer Vernooij
Implement search_missing_revision_ids.
776
class InterGitGitRepository(InterFromGitRepository):
0.200.291 by Jelmer Vernooij
Print proper error about not supporting push.
777
    """InterRepository that copies between Git repositories."""
0.200.175 by Jelmer Vernooij
Add optimized handling when fetching from git to git.
778
0.200.1433 by Jelmer Vernooij
Fix fetching between git repositories.
779
    def fetch_refs(self, update_refs, lossy=False):
780
        if lossy:
781
            raise errors.LossyPushToSameVCS(self.source, self.target)
0.200.1487 by Jelmer Vernooij
Use peeling.
782
        old_refs = self.target.bzrdir.get_refs_container()
0.200.1433 by Jelmer Vernooij
Fix fetching between git repositories.
783
        ref_changes = {}
784
        def determine_wants(heads):
0.200.1524 by Jelmer Vernooij
Fix inter-git fetching.
785
            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.
786
            new_refs = update_refs(old_refs)
787
            ref_changes.update(new_refs)
788
            return [sha1 for (sha1, bzr_revid) in new_refs.itervalues()]
789
        self.fetch_objects(determine_wants)
790
        for k, (git_sha, bzr_revid) in ref_changes.iteritems():
791
            self.target._git.refs[k] = git_sha
0.200.1487 by Jelmer Vernooij
Use peeling.
792
        new_refs = self.target.bzrdir.get_refs_container()
0.200.1433 by Jelmer Vernooij
Fix fetching between git repositories.
793
        return None, old_refs, new_refs
794
0.200.1535 by Jelmer Vernooij
Support limit argument.
795
    def fetch_objects(self, determine_wants, mapping=None, limit=None):
0.200.635 by Jelmer Vernooij
Fix fetching between git repositories.
796
        graphwalker = self.target._git.get_graph_walker()
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
797
        if (isinstance(self.source, LocalGitRepository) and
798
            isinstance(self.target, LocalGitRepository)):
0.200.1493 by Jelmer Vernooij
Test fixes.
799
            def wrap_determine_wants(refs):
800
                return determine_wants(self.source._git.refs)
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
801
            pb = ui.ui_factory.nested_progress_bar()
802
            try:
0.200.1493 by Jelmer Vernooij
Test fixes.
803
                refs = self.source._git.fetch(self.target._git, wrap_determine_wants,
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
804
                    lambda text: report_git_progress(pb, text))
805
            finally:
806
                pb.finished()
0.200.1002 by Jelmer Vernooij
Fix regression in git-import.
807
            return (None, None, refs)
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
808
        elif (isinstance(self.source, LocalGitRepository) and
809
              isinstance(self.target, RemoteGitRepository)):
0.200.635 by Jelmer Vernooij
Fix fetching between git repositories.
810
            raise NotImplementedError
0.200.695 by Jelmer Vernooij
Clean up trailing whitespace.
811
        elif (isinstance(self.source, RemoteGitRepository) and
812
              isinstance(self.target, LocalGitRepository)):
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
813
            pb = ui.ui_factory.nested_progress_bar()
0.200.635 by Jelmer Vernooij
Fix fetching between git repositories.
814
            try:
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
815
                f, commit = self.target._git.object_store.add_pack()
816
                try:
817
                    refs = self.source.bzrdir.fetch_pack(
818
                        determine_wants, graphwalker, f.write,
819
                        lambda text: report_git_progress(pb, text))
820
                    commit()
821
                    return (None, None, refs)
822
                except:
823
                    f.close()
824
                    raise
825
            finally:
826
                pb.finished()
0.200.635 by Jelmer Vernooij
Fix fetching between git repositories.
827
        else:
0.200.1433 by Jelmer Vernooij
Fix fetching between git repositories.
828
            raise AssertionError("fetching between %r and %r not supported" %
829
                    (self.source, self.target))
0.200.635 by Jelmer Vernooij
Fix fetching between git repositories.
830
0.200.1154 by Jelmer Vernooij
Share more code in InterGitRepository.
831
    def _target_has_shas(self, shas):
0.200.1490 by Jelmer Vernooij
Fix target_has_shas.
832
        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.
833
0.200.1491 by Jelmer Vernooij
Fix progress reporting for git -> git.
834
    def fetch(self, revision_id=None, find_ghosts=False,
0.200.1535 by Jelmer Vernooij
Support limit argument.
835
              mapping=None, fetch_spec=None, branches=None, limit=None):
0.200.175 by Jelmer Vernooij
Add optimized handling when fetching from git to git.
836
        if mapping is None:
837
            mapping = self.source.get_mapping()
838
        r = self.target._git
0.226.2 by Jelmer Vernooij
Cope with new fetch_spec argument.
839
        if revision_id is not None:
0.200.1324 by Jelmer Vernooij
More work on roundtripping support.
840
            args = [self.source.lookup_bzr_revision_id(revision_id)[0]]
0.226.2 by Jelmer Vernooij
Cope with new fetch_spec argument.
841
        elif fetch_spec is not None:
0.200.1089 by Jelmer Vernooij
Cope with fancy fetch_spec behaviour.
842
            recipe = fetch_spec.get_recipe()
843
            if recipe[0] in ("search", "proxy-search"):
844
                heads = recipe[1]
845
            else:
0.200.1309 by Jelmer Vernooij
Break some more long lines.
846
                raise AssertionError(
847
                    "Unsupported search result type %s" % recipe[0])
0.200.1350 by Jelmer Vernooij
Implement search_missing_revision_ids.
848
            args = [self.source.lookup_bzr_revision_id(revid)[0] for revid in heads]
0.200.456 by Jelmer Vernooij
Fix git -> git fetching.
849
        if branches is not None:
0.200.1176 by Jelmer Vernooij
Fix fetch return value for inter git fetching.
850
            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.
851
        elif fetch_spec is None and revision_id is None:
0.200.1154 by Jelmer Vernooij
Share more code in InterGitRepository.
852
            determine_wants = self.determine_wants_all
0.226.2 by Jelmer Vernooij
Cope with new fetch_spec argument.
853
        else:
0.200.1176 by Jelmer Vernooij
Fix fetch return value for inter git fetching.
854
            determine_wants = lambda x: [y for y in args if not y in r.object_store and y != ZERO_SHA]
855
        wants_recorder = DetermineWantsRecorder(determine_wants)
856
        self.fetch_objects(wants_recorder, mapping)
857
        return wants_recorder.remote_refs
0.200.175 by Jelmer Vernooij
Add optimized handling when fetching from git to git.
858
859
    @staticmethod
860
    def is_compatible(source, target):
861
        """Be compatible with GitRepository."""
0.200.664 by Jelmer Vernooij
Support submodules during fetch.
862
        return (isinstance(source, GitRepository) and
0.200.175 by Jelmer Vernooij
Add optimized handling when fetching from git to git.
863
                isinstance(target, GitRepository))
0.200.1174 by Jelmer Vernooij
Fix specific revision fetching between git repositories.
864
865
    def get_determine_wants_revids(self, revids, include_tags=False):
866
        wants = set()
867
        for revid in set(revids):
0.200.1388 by Jelmer Vernooij
Don't fetch revision already present.
868
            if self.target.has_revision(revid):
869
                continue
0.200.1174 by Jelmer Vernooij
Fix specific revision fetching between git repositories.
870
            git_sha, mapping = self.source.lookup_bzr_revision_id(revid)
871
            wants.add(git_sha)
0.200.1309 by Jelmer Vernooij
Break some more long lines.
872
        return self.get_determine_wants_heads(wants,
873
            include_tags=include_tags)
0.200.1489 by Jelmer Vernooij
More fixes to peel handling.
874
875
    def determine_wants_all(self, refs):
0.200.1513 by Jelmer Vernooij
Cope with zero shas.
876
        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.
877
        return list(potential - self._target_has_shas(potential))
0.200.1490 by Jelmer Vernooij
Fix target_has_shas.
878
879
    def get_determine_wants_heads(self, wants, include_tags=False):
880
        wants = set(wants)
881
        def determine_wants(refs):
882
            potential = set(wants)
883
            if include_tags:
884
                for k, unpeeled in refs.as_dict().iteritems():
885
                    if not is_tag(k):
886
                        continue
0.200.1513 by Jelmer Vernooij
Cope with zero shas.
887
                    if unpeeled == ZERO_SHA:
888
                        continue
0.200.1490 by Jelmer Vernooij
Fix target_has_shas.
889
                    potential.add(unpeeled)
890
            return list(potential - self._target_has_shas(potential))
891
        return determine_wants
892
893