/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-10-13 14:45:08 UTC
  • mto: This revision was merged to the branch mainline in revision 7398.
  • Revision ID: jelmer@jelmer.uk-20191013144508-ps81dykv26dmm57d
Ignore __pycache__ directories.

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
130
148
        if not seen_root and len(self.parents) == 0:
131
149
            raise RootMissing()
132
150
        if getattr(workingtree, "basis_tree", False):
142
160
            if entry.path in self._blobs:
143
161
                continue
144
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)
145
166
        self.new_inventory = None
146
167
 
147
168
    def update_basis(self, tree):
150
171
 
151
172
    def finish_inventory(self):
152
173
        # eliminate blobs that were removed
153
 
        self._blobs = {k: v for (k, v) in self._blobs.items() if v is not None}
 
174
        self._blobs = {k: v for (k, v) in viewitems(
 
175
            self._blobs) if v is not None}
154
176
 
155
177
    def _iterblobs(self):
156
178
        return ((path, sha, mode) for (path, (mode, sha))
157
 
                in self._blobs.items())
 
179
                in viewitems(self._blobs))
158
180
 
159
181
    def commit(self, message):
160
182
        self._validate_unicode_text(message, 'commit message')