/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: Martin
  • Date: 2019-06-16 01:03:51 UTC
  • mto: This revision was merged to the branch mainline in revision 7340.
  • Revision ID: gzlist@googlemail.com-20190616010351-uz89ydnwdoal4ve4
Split non-ini config methods to bedding

Functions that determine filesystem paths to use for config and default
username are now outside of the main (large) config module.

Also move cache_dir function from osutils and normalise logic.

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
 
148
            else:
 
149
                self._override_fileids[encoded_new_path] = None
133
150
        if not seen_root and len(self.parents) == 0:
134
151
            raise RootMissing()
135
152
        if getattr(workingtree, "basis_tree", False):
144
161
        for entry in basis_tree._iter_tree_contents(include_trees=False):
145
162
            if entry.path in self._blobs:
146
163
                continue
147
 
            if entry.path in self._deleted_paths:
148
 
                continue
149
164
            self._blobs[entry.path] = (entry.mode, entry.sha)
 
165
        if not self._lossy:
 
166
            try:
 
167
                fileid_map = dict(basis_tree._fileid_map.file_ids)
 
168
            except AttributeError:
 
169
                fileid_map = {}
 
170
            for path, file_id in viewitems(self._override_fileids):
 
171
                if not isinstance(path, bytes):
 
172
                    raise TypeError(path)
 
173
                if file_id is None:
 
174
                    if path in fileid_map:
 
175
                        del fileid_map[path]
 
176
                else:
 
177
                    if not isinstance(file_id, bytes):
 
178
                        raise TypeError(file_id)
 
179
                    fileid_map[path] = file_id
 
180
            if fileid_map:
 
181
                fileid_blob = self._mapping.export_fileid_map(fileid_map)
 
182
            else:
 
183
                fileid_blob = None
 
184
            if fileid_blob is not None:
 
185
                if self._mapping.BZR_FILE_IDS_FILE is None:
 
186
                    raise SettingCustomFileIdsUnsupported(fileid_map)
 
187
                self.store.add_object(fileid_blob)
 
188
                self._blobs[self._mapping.BZR_FILE_IDS_FILE] = (
 
189
                    stat.S_IFREG | 0o644, fileid_blob.id)
 
190
            else:
 
191
                self._blobs[self._mapping.BZR_FILE_IDS_FILE] = None
150
192
        self.new_inventory = None
151
193
 
152
194
    def update_basis(self, tree):
155
197
 
156
198
    def finish_inventory(self):
157
199
        # eliminate blobs that were removed
158
 
        self._blobs = {k: v for (k, v) in self._blobs.items()}
 
200
        self._blobs = {k: v for (k, v) in viewitems(
 
201
            self._blobs) if v is not None}
159
202
 
160
203
    def _iterblobs(self):
161
204
        return ((path, sha, mode) for (path, (mode, sha))
162
 
                in self._blobs.items())
 
205
                in viewitems(self._blobs))
163
206
 
164
207
    def commit(self, message):
165
208
        self._validate_unicode_text(message, 'commit message')