match-trees: compute buffer offset correctly when splicing

Currently, the struct object_id pointer returned from tree_entry_extract lives directly inside the parsed tree buffer. In a future commit, this will change so that it instead points to a dedicated struct member. Since in this code path, we want to modify the buffer directly, compute the buffer offset we want to modify by using the pointer to the path instead. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Jan 15, 2019 at 00:39 UTC 36775ab524a1d180aaaac089e25b5aeb87793a17
1 file changed +4 -3
match-trees.c
+4 -3
@@ -199,15 +199,16 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
199 while (desc.size) {
200 const char *name;
201 unsigned mode;
202 - const struct object_id *oid;
202
204 - oid = tree_entry_extract(&desc, &name, &mode);
203 + tree_entry_extract(&desc, &name, &mode);
204 if (strlen(name) == toplen &&
205 !memcmp(name, prefix, toplen)) {
206 if (!S_ISDIR(mode))
207 die("entry %s in tree %s is not a tree", name,
208 oid_to_hex(oid1));
210 - rewrite_here = (struct object_id *)oid;
209 + rewrite_here = (struct object_id *)(desc.entry.path +
210 + strlen(desc.entry.path) +
211 + 1);
212 break;
213 }
214 update_tree_entry(&desc);