summaryrefslogtreecommitdiff
path: root/match-trees.c
diff options
context:
space:
mode:
Diffstat (limited to 'match-trees.c')
-rw-r--r--match-trees.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/match-trees.c b/match-trees.c
index 2b6d31ef9d..18ab825bef 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -106,7 +106,7 @@ static int score_trees(const struct object_id *hash1, const struct object_id *ha
update_tree_entry(&two);
} else {
/* path appears in both */
- if (!oideq(one.entry.oid, two.entry.oid)) {
+ if (!oideq(&one.entry.oid, &two.entry.oid)) {
/* they are different */
score += score_differs(one.entry.mode,
two.entry.mode,
@@ -179,7 +179,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
char *buf;
unsigned long sz;
struct tree_desc desc;
- struct object_id *rewrite_here;
+ unsigned char *rewrite_here;
const struct object_id *rewrite_with;
struct object_id subtree;
enum object_type type;
@@ -199,15 +199,26 @@ 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,
oid_to_hex(oid1));
- rewrite_here = (struct object_id *)oid;
+
+ /*
+ * We cast here for two reasons:
+ *
+ * - to flip the "char *" (for the path) to "unsigned
+ * char *" (for the hash stored after it)
+ *
+ * - to discard the "const"; this is OK because we
+ * know it points into our non-const "buf"
+ */
+ rewrite_here = (unsigned char *)(desc.entry.path +
+ strlen(desc.entry.path) +
+ 1);
break;
}
update_tree_entry(&desc);
@@ -216,14 +227,16 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
die("entry %.*s not found in tree %s", toplen, prefix,
oid_to_hex(oid1));
if (*subpath) {
- status = splice_tree(rewrite_here, subpath, oid2, &subtree);
+ struct object_id tree_oid;
+ hashcpy(tree_oid.hash, rewrite_here);
+ status = splice_tree(&tree_oid, subpath, oid2, &subtree);
if (status)
return status;
rewrite_with = &subtree;
} else {
rewrite_with = oid2;
}
- oidcpy(rewrite_here, rewrite_with);
+ hashcpy(rewrite_here, rewrite_with->hash);
status = write_object_file(buf, sz, tree_type, result);
free(buf);
return status;