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