75
73
def record_iter_changes(self, workingtree, basis_revid, iter_changes):
77
75
for change in iter_changes:
78
if change.kind == (None, None):
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])
88
parent_id_new = self._mapping.generate_file_id(osutils.dirname(change.path[1]))
91
76
if change.kind[1] in ("directory",):
92
77
self._inv_delta.append(
93
(change.path[0], change.path[1], file_id,
78
(change.path[0], change.path[1], change.file_id,
94
79
entry_factory[change.kind[1]](
95
file_id, change.name[1], parent_id_new)))
80
change.file_id, change.name[1], change.parent_id[1])))
96
81
if change.kind[0] in ("file", "symlink"):
97
self._blobs[encode_git_path(change.path[0])] = None
82
self._blobs[change.path[0].encode("utf-8")] = None
98
83
self._any_changes = True
99
84
if change.path[1] == "":
102
87
self._any_changes = True
103
88
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]))
89
self._inv_delta.append((change.path[0], change.path[1], change.file_id, None))
90
self._blobs[change.path[0].encode("utf-8")] = None
108
93
entry_kls = entry_factory[change.kind[1]]
110
95
raise KeyError("unknown kind %s" % change.kind[1])
111
entry = entry_kls(file_id, change.name[1], parent_id_new)
96
entry = entry_kls(change.file_id, change.name[1], change.parent_id[1])
112
97
if change.kind[1] == "file":
113
98
entry.executable = change.executable[1]
117
102
blob.data = f.read()
105
entry.text_size = len(blob.data)
106
entry.text_sha1 = osutils.sha_string(blob.data)
107
self.store.add_object(blob)
122
entry.text_size = st.st_size
124
entry.text_size = len(blob.data)
126
self.store.add_object(blob)
127
109
elif change.kind[1] == "symlink":
128
110
symlink_target = workingtree.get_symlink_target(change.path[1])
130
blob.data = encode_git_path(symlink_target)
112
blob.data = symlink_target.encode("utf-8")
131
113
self.store.add_object(blob)
133
115
entry.symlink_target = symlink_target
141
123
raise AssertionError("Unknown kind %r" % change.kind[1])
142
124
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)
125
self._inv_delta.append((change.path[0], change.path[1], change.file_id, entry))
126
encoded_new_path = change.path[1].encode("utf-8")
127
self._blobs[encoded_new_path] = (mode, sha)
147
128
if st is not None:
148
yield change.path[1], (entry.git_sha1, st)
129
yield change.path[1], (entry.text_sha1, st)
149
130
if not seen_root and len(self.parents) == 0:
150
131
raise RootMissing()
151
132
if getattr(workingtree, "basis_tree", False):
160
141
for entry in basis_tree._iter_tree_contents(include_trees=False):
161
142
if entry.path in self._blobs:
163
if entry.path in self._deleted_paths:
165
144
self._blobs[entry.path] = (entry.mode, entry.sha)
166
145
self.new_inventory = None
172
151
def finish_inventory(self):
173
152
# eliminate blobs that were removed
174
self._blobs = {k: v for (k, v) in self._blobs.items()}
153
self._blobs = {k: v for (k, v) in self._blobs.items() if v is not None}
176
155
def _iterblobs(self):
177
156
return ((path, sha, mode) for (path, (mode, sha))