/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to fetch.py

Handle lightweight checkouts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
    )
57
57
 
58
58
from bzrlib.plugins.git.converter import (
59
 
    GitObjectConverter,
 
59
    BazaarObjectStore,
60
60
    )
61
61
from bzrlib.plugins.git.repository import (
62
62
    LocalGitRepository, 
108
108
 
109
109
 
110
110
def import_git_blob(texts, mapping, path, hexsha, base_inv, parent_id, 
111
 
    revision_id, parent_invs, shagitmap, lookup_object, executable):
 
111
    revision_id, parent_invs, shagitmap, lookup_object, executable, symlink):
112
112
    """Import a git blob object into a bzr repository.
113
113
 
114
114
    :param texts: VersionedFiles to add to
117
117
    :return: Inventory delta for this file
118
118
    """
119
119
    file_id = mapping.generate_file_id(path)
 
120
    if symlink:
 
121
        cls = InventoryLink
 
122
    else:
 
123
        cls = InventoryFile
 
124
    # We just have to hope this is indeed utf-8:
 
125
    ie = cls(file_id, urlutils.basename(path).decode("utf-8"), 
 
126
                parent_id)
 
127
    ie.executable = executable
120
128
    # See if this has changed at all
121
129
    try:
122
130
        base_sha = shagitmap.lookup_blob(file_id, base_inv.revision_id)
123
131
    except KeyError:
124
132
        base_sha = None
125
133
    else:
126
 
        if base_sha == hexsha and base_inv[file_id].executable == executable:
 
134
        if (base_sha == hexsha and base_inv[file_id].executable == ie.executable
 
135
            and base_inv[file_id].kind == ie.kind):
127
136
            # If nothing has changed since the base revision, we're done
128
137
            return []
129
 
    # We just have to hope this is indeed utf-8:
130
 
    ie = InventoryFile(file_id, urlutils.basename(path).decode("utf-8"), 
131
 
        parent_id)
132
138
    if base_sha == hexsha:
133
139
        ie.text_size = base_inv[file_id].text_size
134
140
        ie.text_sha1 = base_inv[file_id].text_sha1
 
141
        ie.symlink_target = base_inv[file_id].symlink_target
135
142
        ie.revision = base_inv[file_id].revision
136
143
    else:
137
144
        blob = lookup_object(hexsha)
138
 
        ie.text_size = len(blob.data)
139
 
        ie.text_sha1 = osutils.sha_string(blob.data)
140
 
    ie.executable = executable
 
145
        if ie.kind == "symlink":
 
146
            ie.symlink_target = blob.data
 
147
            ie.text_size = None
 
148
            ie.text_sha1 = None
 
149
        else:
 
150
            ie.text_size = len(blob.data)
 
151
            ie.text_sha1 = osutils.sha_string(blob.data)
141
152
    # Check what revision we should store
142
153
    parent_keys = []
143
154
    for pinv in parent_invs:
210
221
                file_id, revision_id, parent_invs, shagitmap, lookup_object))
211
222
        elif entry_kind == 1:
212
223
            fs_mode = mode & 0777
 
224
            file_kind = (mode & 070000) / 010000
 
225
            if file_kind == 0: # regular file
 
226
                symlink = False
 
227
            elif file_kind == 2:
 
228
                symlink = True
 
229
            else:
 
230
                raise AssertionError("Unknown file kind, mode=%r" % (mode,))
213
231
            ret.extend(import_git_blob(texts, mapping, child_path, hexsha, base_inv, 
214
232
                file_id, revision_id, parent_invs, shagitmap, lookup_object,
215
 
                bool(fs_mode & 0111)))
 
233
                bool(fs_mode & 0111), symlink))
216
234
        else:
217
 
            raise AssertionError("Unknown blob kind, perms=%r." % (mode,))
 
235
            raise AssertionError("Unknown object kind, perms=%r." % (mode,))
218
236
    # Remove any children that have disappeared
219
237
    if file_id in base_inv:
220
238
        deletable = [v for k,v in base_inv[file_id].children.iteritems() if k not in existing_children]
359
377
        create_pb = None
360
378
        if pb is None:
361
379
            create_pb = pb = ui.ui_factory.nested_progress_bar()
362
 
        target_git_object_retriever = GitObjectConverter(self.target, mapping)
 
380
        target_git_object_retriever = BazaarObjectStore(self.target, mapping)
363
381
        recorded_wants = []
364
382
 
365
383
        def record_determine_wants(heads):
405
423
        create_pb = None
406
424
        if pb is None:
407
425
            create_pb = pb = ui.ui_factory.nested_progress_bar()
408
 
        target_git_object_retriever = GitObjectConverter(self.target, mapping)
 
426
        target_git_object_retriever = BazaarObjectStore(self.target, mapping)
409
427
        try:
410
428
            self.target.lock_write()
411
429
            try: