/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-02-13 23:57:28 UTC
  • mfrom: (7490 work)
  • mto: This revision was merged to the branch mainline in revision 7492.
  • Revision ID: jelmer@jelmer.uk-20200213235728-m6ds0mm3mbs4y182
Merge trunk.

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
 
    read_submodule_head,
23
24
    )
24
25
import stat
25
26
 
43
44
    Blob,
44
45
    Commit,
45
46
    )
 
47
from dulwich.index import read_submodule_head
46
48
 
47
49
 
48
50
from .mapping import (
49
 
    encode_git_path,
50
51
    object_mode,
51
52
    fix_person_identifier,
52
53
    )
65
66
        self.store = self.repository._git.object_store
66
67
        self._blobs = {}
67
68
        self._inv_delta = []
68
 
        self._deleted_paths = set()
69
69
        self._any_changes = False
70
70
        self._mapping = self.repository.get_mapping()
71
71
 
75
75
    def record_iter_changes(self, workingtree, basis_revid, iter_changes):
76
76
        seen_root = False
77
77
        for change in iter_changes:
78
 
            if change.kind == (None, None):
79
 
                # Ephemeral
80
 
                continue
81
 
            if change.versioned[0] and not change.copied:
82
 
                file_id = self._mapping.generate_file_id(change.path[0])
83
 
            elif change.versioned[1]:
84
 
                file_id = self._mapping.generate_file_id(change.path[1])
85
 
            else:
86
 
                file_id = None
87
 
            if change.path[1]:
88
 
                parent_id_new = self._mapping.generate_file_id(osutils.dirname(change.path[1]))
89
 
            else:
90
 
                parent_id_new = None
91
78
            if change.kind[1] in ("directory",):
92
79
                self._inv_delta.append(
93
 
                    (change.path[0], change.path[1], file_id,
 
80
                    (change.path[0], change.path[1], change.file_id,
94
81
                     entry_factory[change.kind[1]](
95
 
                         file_id, change.name[1], parent_id_new)))
 
82
                         change.file_id, change.name[1], change.parent_id[1])))
96
83
                if change.kind[0] in ("file", "symlink"):
97
 
                    self._blobs[encode_git_path(change.path[0])] = None
 
84
                    self._blobs[change.path[0].encode("utf-8")] = None
98
85
                    self._any_changes = True
99
86
                if change.path[1] == "":
100
87
                    seen_root = True
101
88
                continue
102
89
            self._any_changes = True
103
90
            if change.path[1] is None:
104
 
                self._inv_delta.append((change.path[0], change.path[1], file_id, None))
105
 
                self._deleted_paths.add(encode_git_path(change.path[0]))
 
91
                self._inv_delta.append((change.path[0], change.path[1], change.file_id, None))
 
92
                self._blobs[change.path[0].encode("utf-8")] = None
106
93
                continue
107
94
            try:
108
95
                entry_kls = entry_factory[change.kind[1]]
109
96
            except KeyError:
110
97
                raise KeyError("unknown kind %s" % change.kind[1])
111
 
            entry = entry_kls(file_id, change.name[1], parent_id_new)
 
98
            entry = entry_kls(change.file_id, change.name[1], change.parent_id[1])
112
99
            if change.kind[1] == "file":
113
100
                entry.executable = change.executable[1]
114
101
                blob = Blob()
117
104
                    blob.data = f.read()
118
105
                finally:
119
106
                    f.close()
 
107
                entry.text_size = len(blob.data)
 
108
                entry.text_sha1 = osutils.sha_string(blob.data)
 
109
                self.store.add_object(blob)
120
110
                sha = blob.id
121
 
                if st is not None:
122
 
                    entry.text_size = st.st_size
123
 
                else:
124
 
                    entry.text_size = len(blob.data)
125
 
                entry.git_sha1 = sha
126
 
                self.store.add_object(blob)
127
111
            elif change.kind[1] == "symlink":
128
112
                symlink_target = workingtree.get_symlink_target(change.path[1])
129
113
                blob = Blob()
130
 
                blob.data = encode_git_path(symlink_target)
 
114
                blob.data = symlink_target.encode("utf-8")
131
115
                self.store.add_object(blob)
132
116
                sha = blob.id
133
117
                entry.symlink_target = symlink_target
140
124
            else:
141
125
                raise AssertionError("Unknown kind %r" % change.kind[1])
142
126
            mode = object_mode(change.kind[1], change.executable[1])
143
 
            self._inv_delta.append((change.path[0], change.path[1], file_id, entry))
144
 
            if change.path[0] is not None:
145
 
                self._deleted_paths.add(encode_git_path(change.path[0]))
146
 
            self._blobs[encode_git_path(change.path[1])] = (mode, sha)
 
127
            self._inv_delta.append((change.path[0], change.path[1], change.file_id, entry))
 
128
            encoded_new_path = change.path[1].encode("utf-8")
 
129
            self._blobs[encoded_new_path] = (mode, sha)
147
130
            if st is not None:
148
 
                yield change.path[1], (entry.git_sha1, st)
 
131
                yield change.path[1], (entry.text_sha1, st)
149
132
        if not seen_root and len(self.parents) == 0:
150
133
            raise RootMissing()
151
134
        if getattr(workingtree, "basis_tree", False):
160
143
        for entry in basis_tree._iter_tree_contents(include_trees=False):
161
144
            if entry.path in self._blobs:
162
145
                continue
163
 
            if entry.path in self._deleted_paths:
164
 
                continue
165
146
            self._blobs[entry.path] = (entry.mode, entry.sha)
166
147
        self.new_inventory = None
167
148
 
171
152
 
172
153
    def finish_inventory(self):
173
154
        # eliminate blobs that were removed
174
 
        self._blobs = {k: v for (k, v) in self._blobs.items()}
 
155
        self._blobs = {k: v for (k, v) in self._blobs.items() if v is not None}
175
156
 
176
157
    def _iterblobs(self):
177
158
        return ((path, sha, mode) for (path, (mode, sha))