/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-06-02 02:35:46 UTC
  • mfrom: (7309 work)
  • mto: This revision was merged to the branch mainline in revision 7319.
  • Revision ID: jelmer@jelmer.uk-20190602023546-lqco868tnv26d8ow
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 (
 
28
    bugtracker,
29
29
    config as _mod_config,
30
30
    gpg,
31
31
    osutils,
44
44
    )
45
45
 
46
46
from dulwich.objects import (
47
 
    S_IFGITLINK,
48
47
    Blob,
49
48
    Commit,
50
49
    )
51
50
from dulwich.index import read_submodule_head
52
 
from dulwich.repo import Repo
53
51
 
54
52
 
55
53
from .mapping import (
56
 
    entry_mode,
57
54
    object_mode,
58
55
    fix_person_identifier,
59
56
    )
62
59
 
63
60
class SettingCustomFileIdsUnsupported(UnsupportedOperation):
64
61
 
65
 
    _fmt = "Unable to store addition of file with custom file ids: %(file_ids)r"
 
62
    _fmt = ("Unable to store addition of file with custom file ids: "
 
63
            "%(file_ids)r")
66
64
 
67
65
    def __init__(self, file_ids):
68
66
        BzrError.__init__(self)
93
91
        for (file_id, path, changed_content, versioned, parent, name, kind,
94
92
             executable) in iter_changes:
95
93
            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])))
 
94
                self._inv_delta.append(
 
95
                    (path[0], path[1], file_id, entry_factory[kind[1]](
 
96
                        file_id, name[1], parent[1])))
97
97
                if kind[0] in ("file", "symlink"):
98
98
                    self._blobs[path[0].encode("utf-8")] = None
99
99
                    self._any_changes = True
113
113
            if kind[1] == "file":
114
114
                entry.executable = executable[1]
115
115
                blob = Blob()
116
 
                f, st = workingtree.get_file_with_stat(path[1], file_id)
 
116
                f, st = workingtree.get_file_with_stat(path[1])
117
117
                try:
118
118
                    blob.data = f.read()
119
119
                finally:
123
123
                self.store.add_object(blob)
124
124
                sha = blob.id
125
125
            elif kind[1] == "symlink":
126
 
                symlink_target = workingtree.get_symlink_target(path[1], file_id)
 
126
                symlink_target = workingtree.get_symlink_target(path[1])
127
127
                blob = Blob()
128
128
                blob.data = symlink_target.encode("utf-8")
129
129
                self.store.add_object(blob)
132
132
                st = None
133
133
            elif kind[1] == "tree-reference":
134
134
                sha = read_submodule_head(workingtree.abspath(path[1]))
135
 
                reference_revision = workingtree.get_reference_revision(path[1], file_id)
 
135
                reference_revision = workingtree.get_reference_revision(path[1])
136
136
                entry.reference_revision = reference_revision
137
137
                st = None
138
138
            else:
142
142
            encoded_new_path = path[1].encode("utf-8")
143
143
            self._blobs[encoded_new_path] = (mode, sha)
144
144
            if st is not None:
145
 
                yield file_id, path[1], (entry.text_sha1, st)
 
145
                yield path[1], (entry.text_sha1, st)
146
146
            if self._mapping.generate_file_id(encoded_new_path) != file_id:
147
147
                self._override_fileids[encoded_new_path] = file_id
148
148
            else:
185
185
                if self._mapping.BZR_FILE_IDS_FILE is None:
186
186
                    raise SettingCustomFileIdsUnsupported(fileid_map)
187
187
                self.store.add_object(fileid_blob)
188
 
                self._blobs[self._mapping.BZR_FILE_IDS_FILE] = (stat.S_IFREG | 0o644, fileid_blob.id)
 
188
                self._blobs[self._mapping.BZR_FILE_IDS_FILE] = (
 
189
                    stat.S_IFREG | 0o644, fileid_blob.id)
189
190
            else:
190
191
                self._blobs[self._mapping.BZR_FILE_IDS_FILE] = None
191
192
        self.new_inventory = None
196
197
 
197
198
    def finish_inventory(self):
198
199
        # eliminate blobs that were removed
199
 
        self._blobs = {k: v for (k, v) in viewitems(self._blobs) if v is not None}
 
200
        self._blobs = {k: v for (k, v) in viewitems(
 
201
            self._blobs) if v is not None}
200
202
 
201
203
    def _iterblobs(self):
202
 
        return ((path, sha, mode) for (path, (mode, sha)) in viewitems(self._blobs))
 
204
        return ((path, sha, mode) for (path, (mode, sha))
 
205
                in viewitems(self._blobs))
203
206
 
204
207
    def commit(self, message):
205
208
        self._validate_unicode_text(message, 'commit message')
206
209
        c = Commit()
207
 
        c.parents = [self.repository.lookup_bzr_revision_id(revid)[0] for revid in self.parents]
 
210
        c.parents = [self.repository.lookup_bzr_revision_id(
 
211
            revid)[0] for revid in self.parents]
208
212
        c.tree = commit_tree(self.store, self._iterblobs())
209
213
        encoding = self._revprops.pop(u'git-explicit-encoding', 'utf-8')
210
214
        c.encoding = encoding.encode('ascii')
211
215
        c.committer = fix_person_identifier(self._committer.encode(encoding))
212
 
        c.author = fix_person_identifier(self._revprops.pop('author', self._committer).encode(encoding))
 
216
        try:
 
217
            author = self._revprops.pop('author')
 
218
        except KeyError:
 
219
            try:
 
220
                authors = self._revprops.pop('authors').splitlines()
 
221
            except KeyError:
 
222
                author = self._committer
 
223
            else:
 
224
                if len(authors) > 1:
 
225
                    raise Exception("Unable to convert multiple authors")
 
226
                elif len(authors) == 0:
 
227
                    author = self._committer
 
228
                else:
 
229
                    author = authors[0]
 
230
        c.author = fix_person_identifier(author.encode(encoding))
 
231
        bugstext = self._revprops.pop('bugs', None)
 
232
        if bugstext is not None:
 
233
            message += "\n"
 
234
            for url, status in bugtracker.decode_bug_urls(bugstext):
 
235
                if status == bugtracker.FIXED:
 
236
                    message += "Fixes: %s\n" % url
 
237
                elif status == bugtracker.RELATED:
 
238
                    message += "Bug: %s\n" % url
 
239
                else:
 
240
                    raise bugtracker.InvalidBugStatus(status)
213
241
        if self._revprops:
214
242
            raise NotImplementedError(self._revprops)
215
243
        c.commit_time = int(self._timestamp)
217
245
        c.commit_timezone = self._timezone
218
246
        c.author_timezone = self._timezone
219
247
        c.message = message.encode(encoding)
220
 
        if self._config_stack.get('create_signatures') == _mod_config.SIGN_ALWAYS:
 
248
        if (self._config_stack.get('create_signatures') ==
 
249
                _mod_config.SIGN_ALWAYS):
221
250
            strategy = gpg.GPGStrategy(self._config_stack)
222
251
            c.gpgsig = strategy.sign(c.as_raw_string(), gpg.MODE_DETACH)
223
252
        self.store.add_object(c)