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