/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: Gustav Hartvigsson
  • Date: 2021-01-09 20:22:54 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210109202254-rsbi2g544hc0ffb3
Fixed HACKING.txt

* Inicated that the old canonica wiki page
  is -- well -- old.

  * Marked with FIXME, as there is a need
    for a new plugin file.

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