/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 breezy/git/fetch.py

  • Committer: Gustav Hartvigsson
  • Date: 2021-01-09 21:36:27 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210109213627-h1xwcutzy9m7a99b
Added 'Case Preserving Working Tree Use Cases' from Canonical Wiki

* Addod a page from the Canonical Bazaar wiki
  with information on the scmeatics of case
  perserving filesystems an a case insensitive
  filesystem works.
  
  * Needs re-work, but this will do as it is the
    same inforamoton as what was on the linked
    page in the currint documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Fetching from git into bzr."""
18
18
 
19
 
from __future__ import absolute_import
20
 
 
21
19
from dulwich.objects import (
22
20
    Commit,
23
21
    Tag,
51
49
    NULL_REVISION,
52
50
    )
53
51
from ..bzr.inventorytree import InventoryRevisionTree
54
 
from ..sixish import text_type
55
 
from ..testament import (
 
52
from ..bzr.testament import (
56
53
    StrictTestament3,
57
54
    )
 
55
from ..tree import InterTree
58
56
from ..tsort import (
59
57
    topo_sort,
60
58
    )
64
62
 
65
63
from .mapping import (
66
64
    DEFAULT_FILE_MODE,
 
65
    decode_git_path,
67
66
    mode_is_executable,
68
67
    mode_kind,
69
68
    warn_unusual_mode,
87
86
    """
88
87
    if not isinstance(path, bytes):
89
88
        raise TypeError(path)
90
 
    decoded_path = path.decode('utf-8')
 
89
    decoded_path = decode_git_path(path)
91
90
    (base_mode, mode) = modes
92
91
    (base_hexsha, hexsha) = hexshas
93
92
    if mapping.is_special_file(path):
100
99
        cls = InventoryLink
101
100
    else:
102
101
        cls = InventoryFile
103
 
    ie = cls(file_id, name.decode("utf-8"), parent_id)
 
102
    ie = cls(file_id, decode_git_path(name), parent_id)
104
103
    if ie.kind == "file":
105
104
        ie.executable = mode_is_executable(mode)
106
105
    if base_hexsha == hexsha and mode_kind(base_mode) == mode_kind(mode):
118
117
        blob = lookup_object(hexsha)
119
118
        if ie.kind == "symlink":
120
119
            ie.revision = None
121
 
            ie.symlink_target = blob.data.decode("utf-8")
 
120
            ie.symlink_target = decode_git_path(blob.data)
122
121
        else:
123
122
            ie.text_size = sum(map(len, blob.chunked))
124
123
            ie.text_sha1 = osutils.sha_strings(blob.chunked)
125
124
    # Check what revision we should store
126
125
    parent_keys = []
127
126
    for ptree in parent_bzr_trees:
 
127
        intertree = InterTree.get(ptree, base_bzr_tree)
128
128
        try:
129
 
            ppath = ptree.id2path(file_id)
130
 
        except errors.NoSuchId:
 
129
            ppath = intertree.find_source_paths(decoded_path, recurse='none')
 
130
        except errors.NoSuchFile:
 
131
            continue
 
132
        if ppath is None:
131
133
            continue
132
134
        pkind = ptree.kind(ppath)
133
135
        if (pkind == ie.kind and
182
184
    (base_mode, mode) = modes
183
185
    if base_hexsha == hexsha and base_mode == mode:
184
186
        return [], {}
 
187
    path = decode_git_path(path)
185
188
    file_id = lookup_file_id(path)
186
189
    invdelta = []
187
 
    ie = TreeReference(file_id, name.decode("utf-8"), parent_id)
 
190
    ie = TreeReference(file_id, decode_git_path(name), parent_id)
188
191
    ie.revision = revision_id
189
192
    if base_hexsha is not None:
190
 
        old_path = path.decode("utf-8")  # Renames are not supported yet
 
193
        old_path = path  # Renames are not supported yet
191
194
        if stat.S_ISDIR(base_mode):
192
195
            invdelta.extend(remove_disappeared_children(
193
196
                base_bzr_tree, old_path, lookup_object(base_hexsha), [],
213
216
    :param lookup_object: Lookup a git object by its SHA1
214
217
    :return: Inventory delta, as list
215
218
    """
216
 
    if not isinstance(path, text_type):
 
219
    if not isinstance(path, str):
217
220
        raise TypeError(path)
218
221
    ret = []
219
222
    for name, mode, hexsha in base_tree.iteritems():
220
223
        if name in existing_children:
221
224
            continue
222
 
        c_path = posixpath.join(path, name.decode("utf-8"))
 
225
        c_path = posixpath.join(path, decode_git_path(name))
223
226
        file_id = base_bzr_tree.path2id(c_path)
224
227
        if file_id is None:
225
228
            raise TypeError(file_id)
256
259
        return [], {}
257
260
    invdelta = []
258
261
    file_id = lookup_file_id(osutils.safe_unicode(path))
259
 
    # We just have to hope this is indeed utf-8:
260
 
    ie = InventoryDirectory(file_id, name.decode("utf-8"), parent_id)
 
262
    ie = InventoryDirectory(file_id, decode_git_path(name), parent_id)
261
263
    tree = lookup_object(hexsha)
262
264
    if base_hexsha is None:
263
265
        base_tree = None
264
266
        old_path = None  # Newly appeared here
265
267
    else:
266
268
        base_tree = lookup_object(base_hexsha)
267
 
        old_path = path.decode("utf-8")  # Renames aren't supported yet
268
 
    new_path = path.decode("utf-8")
 
269
        old_path = decode_git_path(path)  # Renames aren't supported yet
 
270
    new_path = decode_git_path(path)
269
271
    if base_tree is None or type(base_tree) is not Tree:
270
272
        ie.revision = revision_id
271
273
        invdelta.append((old_path, new_path, ie.file_id, ie))
378
380
 
379
381
 
380
382
def import_git_commit(repo, mapping, head, lookup_object,
381
 
                      target_git_object_retriever, trees_cache):
 
383
                      target_git_object_retriever, trees_cache, strict):
382
384
    o = lookup_object(head)
383
385
    # Note that this uses mapping.revision_id_foreign_to_bzr. If the parents
384
386
    # were bzr roundtripped revisions they would be specified in the
385
387
    # roundtrip data.
386
388
    rev, roundtrip_revid, verifiers = mapping.import_commit(
387
 
        o, mapping.revision_id_foreign_to_bzr)
 
389
        o, mapping.revision_id_foreign_to_bzr, strict)
388
390
    if roundtrip_revid is not None:
389
391
        original_revid = rev.revision_id
390
392
        rev.revision_id = roundtrip_revid
402
404
        base_tree = lookup_object(o.parents[0]).tree
403
405
        base_mode = stat.S_IFDIR
404
406
    store_updater = target_git_object_retriever._get_updater(rev)
405
 
    tree_supplement = mapping.get_fileid_map(lookup_object, o.tree)
406
407
    inv_delta, unusual_modes = import_git_tree(
407
408
        repo.texts, mapping, b"", b"", (base_tree, o.tree), base_bzr_tree,
408
409
        None, rev.revision_id, parent_trees, lookup_object,
409
410
        (base_mode, stat.S_IFDIR), store_updater,
410
 
        tree_supplement.lookup_file_id,
 
411
        mapping.generate_file_id,
411
412
        allow_submodules=repo._format.supports_tree_reference)
412
413
    if unusual_modes != {}:
413
414
        for path, mode in unusual_modes.iteritems():
483
484
            continue
484
485
        if isinstance(o, Commit):
485
486
            rev, roundtrip_revid, verifiers = mapping.import_commit(
486
 
                o, mapping.revision_id_foreign_to_bzr)
 
487
                o, mapping.revision_id_foreign_to_bzr, strict=True)
487
488
            if (repo.has_revision(rev.revision_id)
488
489
                    or (roundtrip_revid and
489
490
                        repo.has_revision(roundtrip_revid))):
516
517
                        pb.update("fetching revisions", offset + i,
517
518
                                  len(revision_ids))
518
519
                    import_git_commit(repo, mapping, head, lookup_object,
519
 
                                      target_git_object_retriever, trees_cache)
 
520
                                      target_git_object_retriever, trees_cache,
 
521
                                      strict=True)
520
522
                    last_imported = head
521
523
            except BaseException:
522
524
                repo.abort_write_group()