/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: 2018-11-17 00:47:52 UTC
  • mfrom: (7182 work)
  • mto: This revision was merged to the branch mainline in revision 7305.
  • Revision ID: jelmer@jelmer.uk-20181117004752-6ywampe5pfywlby4
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from dulwich.index import (
23
23
    commit_tree,
24
24
    )
25
 
import os
26
25
import stat
27
26
 
28
27
from .. import (
44
43
    )
45
44
 
46
45
from dulwich.objects import (
47
 
    S_IFGITLINK,
48
46
    Blob,
49
47
    Commit,
50
48
    )
51
49
from dulwich.index import read_submodule_head
52
 
from dulwich.repo import Repo
53
50
 
54
51
 
55
52
from .mapping import (
56
 
    entry_mode,
57
53
    object_mode,
58
54
    fix_person_identifier,
59
55
    )
62
58
 
63
59
class SettingCustomFileIdsUnsupported(UnsupportedOperation):
64
60
 
65
 
    _fmt = "Unable to store addition of file with custom file ids: %(file_ids)r"
 
61
    _fmt = ("Unable to store addition of file with custom file ids: "
 
62
            "%(file_ids)r")
66
63
 
67
64
    def __init__(self, file_ids):
68
65
        BzrError.__init__(self)
93
90
        for (file_id, path, changed_content, versioned, parent, name, kind,
94
91
             executable) in iter_changes:
95
92
            if kind[1] in ("directory",):
96
 
                self._inv_delta.append((path[0], path[1], file_id, entry_factory[kind[1]](file_id, name[1], parent[1])))
 
93
                self._inv_delta.append(
 
94
                    (path[0], path[1], file_id, entry_factory[kind[1]](
 
95
                        file_id, name[1], parent[1])))
97
96
                if kind[0] in ("file", "symlink"):
98
97
                    self._blobs[path[0].encode("utf-8")] = None
99
98
                    self._any_changes = True
113
112
            if kind[1] == "file":
114
113
                entry.executable = executable[1]
115
114
                blob = Blob()
116
 
                f, st = workingtree.get_file_with_stat(path[1], file_id)
 
115
                f, st = workingtree.get_file_with_stat(path[1])
117
116
                try:
118
117
                    blob.data = f.read()
119
118
                finally:
123
122
                self.store.add_object(blob)
124
123
                sha = blob.id
125
124
            elif kind[1] == "symlink":
126
 
                symlink_target = workingtree.get_symlink_target(path[1], file_id)
 
125
                symlink_target = workingtree.get_symlink_target(path[1])
127
126
                blob = Blob()
128
127
                blob.data = symlink_target.encode("utf-8")
129
128
                self.store.add_object(blob)
132
131
                st = None
133
132
            elif kind[1] == "tree-reference":
134
133
                sha = read_submodule_head(workingtree.abspath(path[1]))
135
 
                reference_revision = workingtree.get_reference_revision(path[1], file_id)
 
134
                reference_revision = workingtree.get_reference_revision(path[1])
136
135
                entry.reference_revision = reference_revision
137
136
                st = None
138
137
            else:
185
184
                if self._mapping.BZR_FILE_IDS_FILE is None:
186
185
                    raise SettingCustomFileIdsUnsupported(fileid_map)
187
186
                self.store.add_object(fileid_blob)
188
 
                self._blobs[self._mapping.BZR_FILE_IDS_FILE] = (stat.S_IFREG | 0o644, fileid_blob.id)
 
187
                self._blobs[self._mapping.BZR_FILE_IDS_FILE] = (
 
188
                    stat.S_IFREG | 0o644, fileid_blob.id)
189
189
            else:
190
190
                self._blobs[self._mapping.BZR_FILE_IDS_FILE] = None
191
191
        self.new_inventory = None
196
196
 
197
197
    def finish_inventory(self):
198
198
        # eliminate blobs that were removed
199
 
        self._blobs = {k: v for (k, v) in viewitems(self._blobs) if v is not None}
 
199
        self._blobs = {k: v for (k, v) in viewitems(
 
200
            self._blobs) if v is not None}
200
201
 
201
202
    def _iterblobs(self):
202
 
        return ((path, sha, mode) for (path, (mode, sha)) in viewitems(self._blobs))
 
203
        return ((path, sha, mode) for (path, (mode, sha))
 
204
                in viewitems(self._blobs))
203
205
 
204
206
    def commit(self, message):
205
207
        self._validate_unicode_text(message, 'commit message')
206
208
        c = Commit()
207
 
        c.parents = [self.repository.lookup_bzr_revision_id(revid)[0] for revid in self.parents]
 
209
        c.parents = [self.repository.lookup_bzr_revision_id(
 
210
            revid)[0] for revid in self.parents]
208
211
        c.tree = commit_tree(self.store, self._iterblobs())
209
212
        encoding = self._revprops.pop(u'git-explicit-encoding', 'utf-8')
210
213
        c.encoding = encoding.encode('ascii')
211
214
        c.committer = fix_person_identifier(self._committer.encode(encoding))
212
 
        c.author = fix_person_identifier(self._revprops.pop('author', self._committer).encode(encoding))
 
215
        try:
 
216
            author = self._revprops.pop('author')
 
217
        except KeyError:
 
218
            try:
 
219
                authors = self._revprops.pop('authors').splitlines()
 
220
            except KeyError:
 
221
                author = self._committer
 
222
            else:
 
223
                if len(authors) > 1:
 
224
                    raise Exception("Unable to convert multiple authors")
 
225
                elif len(authors) == 0:
 
226
                    author = self._committer
 
227
                else:
 
228
                    author = authors[0]
 
229
        c.author = fix_person_identifier(author.encode(encoding))
213
230
        if self._revprops:
214
231
            raise NotImplementedError(self._revprops)
215
232
        c.commit_time = int(self._timestamp)
217
234
        c.commit_timezone = self._timezone
218
235
        c.author_timezone = self._timezone
219
236
        c.message = message.encode(encoding)
220
 
        if self._config_stack.get('create_signatures') == _mod_config.SIGN_ALWAYS:
 
237
        if (self._config_stack.get('create_signatures') ==
 
238
                _mod_config.SIGN_ALWAYS):
221
239
            strategy = gpg.GPGStrategy(self._config_stack)
222
240
            c.gpgsig = strategy.sign(c.as_raw_string(), gpg.MODE_DETACH)
223
241
        self.store.add_object(c)