/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: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
from .tree import entry_factory
58
58
 
59
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
 
 
70
60
class GitCommitBuilder(CommitBuilder):
71
61
    """Commit builder for Git repositories."""
72
62
 
80
70
        self._blobs = {}
81
71
        self._inv_delta = []
82
72
        self._any_changes = False
83
 
        self._override_fileids = {}
84
73
        self._mapping = self.repository.get_mapping()
85
74
 
86
75
    def any_changes(self):
88
77
 
89
78
    def record_iter_changes(self, workingtree, basis_revid, iter_changes):
90
79
        seen_root = False
91
 
        for (file_id, path, changed_content, versioned, parent, name, kind,
92
 
             executable) in iter_changes:
93
 
            if kind[1] in ("directory",):
 
80
        for change in iter_changes:
 
81
            if change.kind[1] in ("directory",):
94
82
                self._inv_delta.append(
95
 
                    (path[0], path[1], file_id, entry_factory[kind[1]](
96
 
                        file_id, name[1], parent[1])))
97
 
                if kind[0] in ("file", "symlink"):
98
 
                    self._blobs[path[0].encode("utf-8")] = None
 
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
99
88
                    self._any_changes = True
100
 
                if path[1] == "":
 
89
                if change.path[1] == "":
101
90
                    seen_root = True
102
91
                continue
103
92
            self._any_changes = True
104
 
            if path[1] is None:
105
 
                self._inv_delta.append((path[0], path[1], file_id, None))
106
 
                self._blobs[path[0].encode("utf-8")] = None
 
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
107
96
                continue
108
97
            try:
109
 
                entry_kls = entry_factory[kind[1]]
 
98
                entry_kls = entry_factory[change.kind[1]]
110
99
            except KeyError:
111
 
                raise KeyError("unknown kind %s" % kind[1])
112
 
            entry = entry_kls(file_id, name[1], parent[1])
113
 
            if kind[1] == "file":
114
 
                entry.executable = executable[1]
 
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]
115
104
                blob = Blob()
116
 
                f, st = workingtree.get_file_with_stat(path[1])
 
105
                f, st = workingtree.get_file_with_stat(change.path[1])
117
106
                try:
118
107
                    blob.data = f.read()
119
108
                finally:
122
111
                entry.text_sha1 = osutils.sha_string(blob.data)
123
112
                self.store.add_object(blob)
124
113
                sha = blob.id
125
 
            elif kind[1] == "symlink":
126
 
                symlink_target = workingtree.get_symlink_target(path[1])
 
114
            elif change.kind[1] == "symlink":
 
115
                symlink_target = workingtree.get_symlink_target(change.path[1])
127
116
                blob = Blob()
128
117
                blob.data = symlink_target.encode("utf-8")
129
118
                self.store.add_object(blob)
130
119
                sha = blob.id
131
120
                entry.symlink_target = symlink_target
132
121
                st = None
133
 
            elif kind[1] == "tree-reference":
134
 
                sha = read_submodule_head(workingtree.abspath(path[1]))
135
 
                reference_revision = workingtree.get_reference_revision(path[1])
 
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])
136
125
                entry.reference_revision = reference_revision
137
126
                st = None
138
127
            else:
139
 
                raise AssertionError("Unknown kind %r" % kind[1])
140
 
            mode = object_mode(kind[1], executable[1])
141
 
            self._inv_delta.append((path[0], path[1], file_id, entry))
142
 
            encoded_new_path = path[1].encode("utf-8")
 
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")
143
132
            self._blobs[encoded_new_path] = (mode, sha)
144
133
            if st is not None:
145
 
                yield path[1], (entry.text_sha1, st)
146
 
            if self._mapping.generate_file_id(encoded_new_path) != file_id:
147
 
                self._override_fileids[encoded_new_path] = file_id
148
 
            else:
149
 
                self._override_fileids[encoded_new_path] = None
 
134
                yield change.path[1], (entry.text_sha1, st)
150
135
        if not seen_root and len(self.parents) == 0:
151
136
            raise RootMissing()
152
137
        if getattr(workingtree, "basis_tree", False):
162
147
            if entry.path in self._blobs:
163
148
                continue
164
149
            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
192
150
        self.new_inventory = None
193
151
 
194
152
    def update_basis(self, tree):
262
220
        return self.repository.revision_tree(self._new_revision_id)
263
221
 
264
222
    def get_basis_delta(self):
265
 
        # TODO(jelmer): remove this logic when lp:~jelmer/brz/remaining lands
266
 
        for (oldpath, newpath, file_id, entry) in self._inv_delta:
267
 
            if entry is not None:
268
 
                entry.revision = self._new_revision_id
269
223
        return self._inv_delta
270
224
 
271
225
    def update_basis_by_delta(self, revid, delta):