#include "tree-walk.h"
#include "object-store.h"
-static int score_missing(unsigned mode, const char *path)
+static int score_missing(unsigned mode)
{
int score;
return score;
}
-static int score_differs(unsigned mode1, unsigned mode2, const char *path)
+static int score_differs(unsigned mode1, unsigned mode2)
{
int score;
return score;
}
-static int score_matches(unsigned mode1, unsigned mode2, const char *path)
+static int score_matches(unsigned mode1, unsigned mode2)
{
int score;
if (cmp < 0) {
/* path1 does not appear in two */
- score += score_missing(one.entry.mode, one.entry.path);
+ score += score_missing(one.entry.mode);
update_tree_entry(&one);
} else if (cmp > 0) {
/* path2 does not appear in one */
- score += score_missing(two.entry.mode, two.entry.path);
+ score += score_missing(two.entry.mode);
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,
- one.entry.path);
+ two.entry.mode);
} else {
/* same subtree or blob */
score += score_matches(one.entry.mode,
- two.entry.mode,
- one.entry.path);
+ two.entry.mode);
}
update_tree_entry(&one);
update_tree_entry(&two);
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;
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);
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;