/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 19:53:27 UTC
  • mto: This revision was merged to the branch mainline in revision 7349.
  • Revision ID: gzlist@googlemail.com-20190616195327-awvhgbjo9g6mkt57
Relocate the bzr log file out of $HOME

Now under $XDG_CACHE_HOME on nix and %LOCALAPPDATA% on windows.

Setting $BRZ_HOME will override the cache location, to simplify test
isolation, and $BRZ_LOG is still the final word.

Drive-by fix various docs around bzr/brz spelling.

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,
52
57
from .tree import entry_factory
53
58
 
54
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
 
55
70
class GitCommitBuilder(CommitBuilder):
56
71
    """Commit builder for Git repositories."""
57
72
 
65
80
        self._blobs = {}
66
81
        self._inv_delta = []
67
82
        self._any_changes = False
 
83
        self._override_fileids = {}
68
84
        self._mapping = self.repository.get_mapping()
69
85
 
70
86
    def any_changes(self):
127
143
            self._blobs[encoded_new_path] = (mode, sha)
128
144
            if st is not None:
129
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
130
150
        if not seen_root and len(self.parents) == 0:
131
151
            raise RootMissing()
132
152
        if getattr(workingtree, "basis_tree", False):
142
162
            if entry.path in self._blobs:
143
163
                continue
144
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
145
192
        self.new_inventory = None
146
193
 
147
194
    def update_basis(self, tree):
150
197
 
151
198
    def finish_inventory(self):
152
199
        # eliminate blobs that were removed
153
 
        self._blobs = {k: v for (k, v) in self._blobs.items() if v is not None}
 
200
        self._blobs = {k: v for (k, v) in viewitems(
 
201
            self._blobs) if v is not None}
154
202
 
155
203
    def _iterblobs(self):
156
204
        return ((path, sha, mode) for (path, (mode, sha))
157
 
                in self._blobs.items())
 
205
                in viewitems(self._blobs))
158
206
 
159
207
    def commit(self, message):
160
208
        self._validate_unicode_text(message, 'commit message')