diff mbox series

[2/5] match-trees: compute buffer offset correctly when splicing

Message ID 20190110042551.915769-3-sandals@crustytoothpaste.net (mailing list archive)
State New, archived
Headers show
Series tree-walk object_id refactor | expand

Commit Message

brian m. carlson Jan. 10, 2019, 4:25 a.m. UTC
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

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
 match-trees.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
diff mbox series


diff --git a/match-trees.c b/match-trees.c
index 2b6d31ef9d..feca48a5fd 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -199,15 +199,16 @@  static int splice_tree(const struct object_id *oid1, const char *prefix,
 	while (desc.size) {
 		const char *name;
 		unsigned mode;
-		const struct object_id *oid;
-		oid = tree_entry_extract(&desc, &name, &mode);
+		tree_entry_extract(&desc, &name, &mode);
 		if (strlen(name) == toplen &&
 		    !memcmp(name, prefix, toplen)) {
 			if (!S_ISDIR(mode))
 				die("entry %s in tree %s is not a tree", name,
-			rewrite_here = (struct object_id *)oid;
+			rewrite_here = (struct object_id *)(desc.entry.path +
+							    strlen(desc.entry.path) +
+							    1);