/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/commit.py

  • Committer: Jelmer Vernooij
  • Date: 2019-11-03 00:17:16 UTC
  • mto: This revision was merged to the branch mainline in revision 7412.
  • Revision ID: jelmer@jelmer.uk-20191103001716-cexkmouumoqj0jtg
Remove trailing newline.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""Support for committing in native Git working trees."""
19
19
 
 
20
from __future__ import absolute_import
 
21
 
20
22
from dulwich.index import (
21
23
    commit_tree,
22
24
    )
37
39
from ..repository import (
38
40
    CommitBuilder,
39
41
    )
 
42
from ..sixish import (
 
43
    viewitems,
 
44
    )
40
45
 
41
46
from dulwich.objects import (
42
47
    Blob,
46
51
 
47
52
 
48
53
from .mapping import (
49
 
    encode_git_path,
50
54
    object_mode,
51
55
    fix_person_identifier,
52
56
    )
53
57
from .tree import entry_factory
54
58
 
55
59
 
 
60
class SettingCustomFileIdsUnsupported(UnsupportedOperation):
 
61
 
 
62
    _fmt = ("Unable to store addition of file with custom file ids: "
 
63
            "%(file_ids)r")
 
64
 
 
65
    def __init__(self, file_ids):
 
66
        BzrError.__init__(self)
 
67
        self.file_ids = file_ids
 
68
 
 
69
 
56
70
class GitCommitBuilder(CommitBuilder):
57
71
    """Commit builder for Git repositories."""
58
72
 
65
79
        self.store = self.repository._git.object_store
66
80
        self._blobs = {}
67
81
        self._inv_delta = []
68
 
        self._deleted_paths = set()
69
82
        self._any_changes = False
 
83
        self._override_fileids = {}
70
84
        self._mapping = self.repository.get_mapping()
71
85
 
72
86
    def any_changes(self):
81
95
                     entry_factory[change.kind[1]](
82
96
                         change.file_id, change.name[1], change.parent_id[1])))
83
97
                if change.kind[0] in ("file", "symlink"):
84
 
                    self._blobs[encode_git_path(change.path[0])] = None
 
98
                    self._blobs[change.path[0].encode("utf-8")] = None
85
99
                    self._any_changes = True
86
100
                if change.path[1] == "":
87
101
                    seen_root = True
89
103
            self._any_changes = True
90
104
            if change.path[1] is None:
91
105
                self._inv_delta.append((change.path[0], change.path[1], change.file_id, None))
92
 
                self._deleted_paths.add(encode_git_path(change.path[0]))
 
106
                self._blobs[change.path[0].encode("utf-8")] = None
93
107
                continue
94
108
            try:
95
109
                entry_kls = entry_factory[change.kind[1]]
111
125
            elif change.kind[1] == "symlink":
112
126
                symlink_target = workingtree.get_symlink_target(change.path[1])
113
127
                blob = Blob()
114
 
                blob.data = encode_git_path(symlink_target)
 
128
                blob.data = symlink_target.encode("utf-8")
115
129
                self.store.add_object(blob)
116
130
                sha = blob.id
117
131
                entry.symlink_target = symlink_target
125
139
                raise AssertionError("Unknown kind %r" % change.kind[1])
126
140
            mode = object_mode(change.kind[1], change.executable[1])
127
141
            self._inv_delta.append((change.path[0], change.path[1], change.file_id, entry))
128
 
            if change.path[0] is not None:
129
 
                self._deleted_paths.add(encode_git_path(change.path[0]))
130
 
            self._blobs[encode_git_path(change.path[1])] = (mode, sha)
 
142
            encoded_new_path = change.path[1].encode("utf-8")
 
143
            self._blobs[encoded_new_path] = (mode, sha)
131
144
            if st is not None:
132
145
                yield change.path[1], (entry.text_sha1, st)
 
146
            if self._mapping.generate_file_id(encoded_new_path) != change.file_id:
 
147
                self._override_fileids[encoded_new_path] = change.file_id
133
148
        if not seen_root and len(self.parents) == 0:
134
149
            raise RootMissing()
135
150
        if getattr(workingtree, "basis_tree", False):
144
159
        for entry in basis_tree._iter_tree_contents(include_trees=False):
145
160
            if entry.path in self._blobs:
146
161
                continue
147
 
            if entry.path in self._deleted_paths:
148
 
                continue
149
162
            self._blobs[entry.path] = (entry.mode, entry.sha)
 
163
        if not self._lossy:
 
164
            if self._override_fileids:
 
165
                raise SettingCustomFileIdsUnsupported(self._override_fileids)
150
166
        self.new_inventory = None
151
167
 
152
168
    def update_basis(self, tree):
155
171
 
156
172
    def finish_inventory(self):
157
173
        # eliminate blobs that were removed
158
 
        self._blobs = {k: v for (k, v) in self._blobs.items()}
 
174
        self._blobs = {k: v for (k, v) in viewitems(
 
175
            self._blobs) if v is not None}
159
176
 
160
177
    def _iterblobs(self):
161
178
        return ((path, sha, mode) for (path, (mode, sha))
162
 
                in self._blobs.items())
 
179
                in viewitems(self._blobs))
163
180
 
164
181
    def commit(self, message):
165
182
        self._validate_unicode_text(message, 'commit message')