/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: 2018-11-18 19:48:57 UTC
  • mto: This revision was merged to the branch mainline in revision 7205.
  • Revision ID: gzlist@googlemail.com-20181118194857-mqty4xka790jf934
Fix remaining whitespace lint in codebase

Enables rules W191, W291, W293, and W391 for flake8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import stat
26
26
 
27
27
from .. import (
28
 
    bugtracker,
29
28
    config as _mod_config,
30
29
    gpg,
31
30
    osutils,
57
56
from .tree import entry_factory
58
57
 
59
58
 
 
59
class SettingCustomFileIdsUnsupported(UnsupportedOperation):
 
60
 
 
61
    _fmt = ("Unable to store addition of file with custom file ids: "
 
62
            "%(file_ids)r")
 
63
 
 
64
    def __init__(self, file_ids):
 
65
        BzrError.__init__(self)
 
66
        self.file_ids = file_ids
 
67
 
 
68
 
60
69
class GitCommitBuilder(CommitBuilder):
61
70
    """Commit builder for Git repositories."""
62
71
 
70
79
        self._blobs = {}
71
80
        self._inv_delta = []
72
81
        self._any_changes = False
 
82
        self._override_fileids = {}
73
83
        self._mapping = self.repository.get_mapping()
74
84
 
75
85
    def any_changes(self):
77
87
 
78
88
    def record_iter_changes(self, workingtree, basis_revid, iter_changes):
79
89
        seen_root = False
80
 
        for change in iter_changes:
81
 
            if change.kind[1] in ("directory",):
 
90
        for (file_id, path, changed_content, versioned, parent, name, kind,
 
91
             executable) in iter_changes:
 
92
            if kind[1] in ("directory",):
82
93
                self._inv_delta.append(
83
 
                    (change.path[0], change.path[1], change.file_id,
84
 
                     entry_factory[change.kind[1]](
85
 
                         change.file_id, change.name[1], change.parent_id[1])))
86
 
                if change.kind[0] in ("file", "symlink"):
87
 
                    self._blobs[change.path[0].encode("utf-8")] = None
 
94
                    (path[0], path[1], file_id, entry_factory[kind[1]](
 
95
                        file_id, name[1], parent[1])))
 
96
                if kind[0] in ("file", "symlink"):
 
97
                    self._blobs[path[0].encode("utf-8")] = None
88
98
                    self._any_changes = True
89
 
                if change.path[1] == "":
 
99
                if path[1] == "":
90
100
                    seen_root = True
91
101
                continue
92
102
            self._any_changes = True
93
 
            if change.path[1] is None:
94
 
                self._inv_delta.append((change.path[0], change.path[1], change.file_id, None))
95
 
                self._blobs[change.path[0].encode("utf-8")] = None
 
103
            if path[1] is None:
 
104
                self._inv_delta.append((path[0], path[1], file_id, None))
 
105
                self._blobs[path[0].encode("utf-8")] = None
96
106
                continue
97
107
            try:
98
 
                entry_kls = entry_factory[change.kind[1]]
 
108
                entry_kls = entry_factory[kind[1]]
99
109
            except KeyError:
100
 
                raise KeyError("unknown kind %s" % change.kind[1])
101
 
            entry = entry_kls(change.file_id, change.name[1], change.parent_id[1])
102
 
            if change.kind[1] == "file":
103
 
                entry.executable = change.executable[1]
 
110
                raise KeyError("unknown kind %s" % kind[1])
 
111
            entry = entry_kls(file_id, name[1], parent[1])
 
112
            if kind[1] == "file":
 
113
                entry.executable = executable[1]
104
114
                blob = Blob()
105
 
                f, st = workingtree.get_file_with_stat(change.path[1])
 
115
                f, st = workingtree.get_file_with_stat(path[1])
106
116
                try:
107
117
                    blob.data = f.read()
108
118
                finally:
111
121
                entry.text_sha1 = osutils.sha_string(blob.data)
112
122
                self.store.add_object(blob)
113
123
                sha = blob.id
114
 
            elif change.kind[1] == "symlink":
115
 
                symlink_target = workingtree.get_symlink_target(change.path[1])
 
124
            elif kind[1] == "symlink":
 
125
                symlink_target = workingtree.get_symlink_target(path[1])
116
126
                blob = Blob()
117
127
                blob.data = symlink_target.encode("utf-8")
118
128
                self.store.add_object(blob)
119
129
                sha = blob.id
120
130
                entry.symlink_target = symlink_target
121
131
                st = None
122
 
            elif change.kind[1] == "tree-reference":
123
 
                sha = read_submodule_head(workingtree.abspath(change.path[1]))
124
 
                reference_revision = workingtree.get_reference_revision(change.path[1])
 
132
            elif kind[1] == "tree-reference":
 
133
                sha = read_submodule_head(workingtree.abspath(path[1]))
 
134
                reference_revision = workingtree.get_reference_revision(path[1])
125
135
                entry.reference_revision = reference_revision
126
136
                st = None
127
137
            else:
128
 
                raise AssertionError("Unknown kind %r" % change.kind[1])
129
 
            mode = object_mode(change.kind[1], change.executable[1])
130
 
            self._inv_delta.append((change.path[0], change.path[1], change.file_id, entry))
131
 
            encoded_new_path = change.path[1].encode("utf-8")
 
138
                raise AssertionError("Unknown kind %r" % kind[1])
 
139
            mode = object_mode(kind[1], executable[1])
 
140
            self._inv_delta.append((path[0], path[1], file_id, entry))
 
141
            encoded_new_path = path[1].encode("utf-8")
132
142
            self._blobs[encoded_new_path] = (mode, sha)
133
143
            if st is not None:
134
 
                yield change.path[1], (entry.text_sha1, st)
 
144
                yield file_id, path[1], (entry.text_sha1, st)
 
145
            if self._mapping.generate_file_id(encoded_new_path) != file_id:
 
146
                self._override_fileids[encoded_new_path] = file_id
 
147
            else:
 
148
                self._override_fileids[encoded_new_path] = None
135
149
        if not seen_root and len(self.parents) == 0:
136
150
            raise RootMissing()
137
151
        if getattr(workingtree, "basis_tree", False):
147
161
            if entry.path in self._blobs:
148
162
                continue
149
163
            self._blobs[entry.path] = (entry.mode, entry.sha)
 
164
        if not self._lossy:
 
165
            try:
 
166
                fileid_map = dict(basis_tree._fileid_map.file_ids)
 
167
            except AttributeError:
 
168
                fileid_map = {}
 
169
            for path, file_id in viewitems(self._override_fileids):
 
170
                if not isinstance(path, bytes):
 
171
                    raise TypeError(path)
 
172
                if file_id is None:
 
173
                    if path in fileid_map:
 
174
                        del fileid_map[path]
 
175
                else:
 
176
                    if not isinstance(file_id, bytes):
 
177
                        raise TypeError(file_id)
 
178
                    fileid_map[path] = file_id
 
179
            if fileid_map:
 
180
                fileid_blob = self._mapping.export_fileid_map(fileid_map)
 
181
            else:
 
182
                fileid_blob = None
 
183
            if fileid_blob is not None:
 
184
                if self._mapping.BZR_FILE_IDS_FILE is None:
 
185
                    raise SettingCustomFileIdsUnsupported(fileid_map)
 
186
                self.store.add_object(fileid_blob)
 
187
                self._blobs[self._mapping.BZR_FILE_IDS_FILE] = (
 
188
                    stat.S_IFREG | 0o644, fileid_blob.id)
 
189
            else:
 
190
                self._blobs[self._mapping.BZR_FILE_IDS_FILE] = None
150
191
        self.new_inventory = None
151
192
 
152
193
    def update_basis(self, tree):
186
227
                else:
187
228
                    author = authors[0]
188
229
        c.author = fix_person_identifier(author.encode(encoding))
189
 
        bugstext = self._revprops.pop('bugs', None)
190
 
        if bugstext is not None:
191
 
            message += "\n"
192
 
            for url, status in bugtracker.decode_bug_urls(bugstext):
193
 
                if status == bugtracker.FIXED:
194
 
                    message += "Fixes: %s\n" % url
195
 
                elif status == bugtracker.RELATED:
196
 
                    message += "Bug: %s\n" % url
197
 
                else:
198
 
                    raise bugtracker.InvalidBugStatus(status)
199
230
        if self._revprops:
200
231
            raise NotImplementedError(self._revprops)
201
232
        c.commit_time = int(self._timestamp)
220
251
        return self.repository.revision_tree(self._new_revision_id)
221
252
 
222
253
    def get_basis_delta(self):
 
254
        # TODO(jelmer): remove this logic when lp:~jelmer/brz/remaining lands
 
255
        for (oldpath, newpath, file_id, entry) in self._inv_delta:
 
256
            if entry is not None:
 
257
                entry.revision = self._new_revision_id
223
258
        return self._inv_delta
224
259
 
225
260
    def update_basis_by_delta(self, revid, delta):