merge-recursive: convert leaf functions to use struct object_id

Convert all but two of the static functions in this file to use struct object_id. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Jun 24, 2016 at 23:09 UTC b4da9d62f91d66ab97815007105b42a2aa5846b5
1 file changed +118 -118
merge-recursive.c
+118 -118
@@ -56,11 +56,11 @@ static struct commit *make_virtual_commit(struct tree *tree, const char *comment
56 * Since we use get_tree_entry(), which does not put the read object into
57 * the object pool, we cannot rely on a == b.
58 */
59 -static int sha_eq(const unsigned char *a, const unsigned char *b)
59 +static int oid_eq(const struct object_id *a, const struct object_id *b)
60 {
61 if (!a && !b)
62 return 2;
63 - return a && b && hashcmp(a, b) == 0;
63 + return a && b && oidcmp(a, b) == 0;
64 }
65
66 enum rename_type {
@@ -198,11 +198,11 @@ static void output_commit_title(struct merge_options *o, struct commit *commit)
198 }
199 }
200
201 -static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
201 +static int add_cacheinfo(unsigned int mode, const struct object_id *oid,
202 const char *path, int stage, int refresh, int options)
203 {
204 struct cache_entry *ce;
205 - ce = make_cache_entry(mode, sha1 ? sha1 : null_sha1, path, stage,
205 + ce = make_cache_entry(mode, oid ? oid->hash : null_sha1, path, stage,
206 (refresh ? (CE_MATCH_REFRESH |
207 CE_MATCH_IGNORE_MISSING) : 0 ));
208 if (!ce)
@@ -552,13 +552,13 @@ static int update_stages(const char *path, const struct diff_filespec *o,
552 if (remove_file_from_cache(path))
553 return -1;
554 if (o)
555 - if (add_cacheinfo(o->mode, o->oid.hash, path, 1, 0, options))
555 + if (add_cacheinfo(o->mode, &o->oid, path, 1, 0, options))
556 return -1;
557 if (a)
558 - if (add_cacheinfo(a->mode, a->oid.hash, path, 2, 0, options))
558 + if (add_cacheinfo(a->mode, &a->oid, path, 2, 0, options))
559 return -1;
560 if (b)
561 - if (add_cacheinfo(b->mode, b->oid.hash, path, 3, 0, options))
561 + if (add_cacheinfo(b->mode, &b->oid, path, 3, 0, options))
562 return -1;
563 return 0;
564 }
@@ -736,7 +736,7 @@ static int make_room_for_path(struct merge_options *o, const char *path)
736 }
737
738 static void update_file_flags(struct merge_options *o,
739 - const unsigned char *sha,
739 + const struct object_id *oid,
740 unsigned mode,
741 const char *path,
742 int update_cache,
@@ -760,11 +760,11 @@ static void update_file_flags(struct merge_options *o,
760 goto update_index;
761 }
762
763 - buf = read_sha1_file(sha, &type, &size);
763 + buf = read_sha1_file(oid->hash, &type, &size);
764 if (!buf)
765 - die(_("cannot read object %s '%s'"), sha1_to_hex(sha), path);
765 + die(_("cannot read object %s '%s'"), oid_to_hex(oid), path);
766 if (type != OBJ_BLOB)
767 - die(_("blob expected for %s '%s'"), sha1_to_hex(sha), path);
767 + die(_("blob expected for %s '%s'"), oid_to_hex(oid), path);
768 if (S_ISREG(mode)) {
769 struct strbuf strbuf = STRBUF_INIT;
770 if (convert_to_working_tree(path, buf, size, &strbuf)) {
@@ -799,21 +799,21 @@ static void update_file_flags(struct merge_options *o,
799 free(lnk);
800 } else
801 die(_("do not know what to do with %06o %s '%s'"),
802 - mode, sha1_to_hex(sha), path);
802 + mode, oid_to_hex(oid), path);
803 free(buf);
804 }
805 update_index:
806 if (update_cache)
807 - add_cacheinfo(mode, sha, path, 0, update_wd, ADD_CACHE_OK_TO_ADD);
807 + add_cacheinfo(mode, oid, path, 0, update_wd, ADD_CACHE_OK_TO_ADD);
808 }
809
810 static void update_file(struct merge_options *o,
811 int clean,
812 - const unsigned char *sha,
812 + const struct object_id *oid,
813 unsigned mode,
814 const char *path)
815 {
816 - update_file_flags(o, sha, mode, path, o->call_depth || clean, !o->call_depth);
816 + update_file_flags(o, oid, mode, path, o->call_depth || clean, !o->call_depth);
817 }
818
819 /* Low level file merging, update and removal */
@@ -908,7 +908,7 @@ static struct merge_file_info merge_file_1(struct merge_options *o,
908 oidcpy(&result.oid, &b->oid);
909 }
910 } else {
911 - if (!sha_eq(a->oid.hash, one->oid.hash) && !sha_eq(b->oid.hash, one->oid.hash))
911 + if (!oid_eq(&a->oid, &one->oid) && !oid_eq(&b->oid, &one->oid))
912 result.merge = 1;
913
914 /*
@@ -924,9 +924,9 @@ static struct merge_file_info merge_file_1(struct merge_options *o,
924 }
925 }
926
927 - if (sha_eq(a->oid.hash, b->oid.hash) || sha_eq(a->oid.hash, one->oid.hash))
927 + if (oid_eq(&a->oid, &b->oid) || oid_eq(&a->oid, &one->oid))
928 oidcpy(&result.oid, &b->oid);
929 - else if (sha_eq(b->oid.hash, one->oid.hash))
929 + else if (oid_eq(&b->oid, &one->oid))
930 oidcpy(&result.oid, &a->oid);
931 else if (S_ISREG(a->mode)) {
932 mmbuffer_t result_buf;
@@ -955,7 +955,7 @@ static struct merge_file_info merge_file_1(struct merge_options *o,
955 } else if (S_ISLNK(a->mode)) {
956 oidcpy(&result.oid, &a->oid);
957
958 - if (!sha_eq(a->oid.hash, b->oid.hash))
958 + if (!oid_eq(&a->oid, &b->oid))
959 result.clean = 0;
960 } else {
961 die(_("unsupported object type in the tree"));
@@ -993,34 +993,34 @@ merge_file_special_markers(struct merge_options *o,
993
994 static struct merge_file_info merge_file_one(struct merge_options *o,
995 const char *path,
996 - const unsigned char *o_sha, int o_mode,
997 - const unsigned char *a_sha, int a_mode,
998 - const unsigned char *b_sha, int b_mode,
996 + const struct object_id *o_oid, int o_mode,
997 + const struct object_id *a_oid, int a_mode,
998 + const struct object_id *b_oid, int b_mode,
999 const char *branch1,
1000 const char *branch2)
1001 {
1002 struct diff_filespec one, a, b;
1003
1004 one.path = a.path = b.path = (char *)path;
1005 - hashcpy(one.oid.hash, o_sha);
1005 + oidcpy(&one.oid, o_oid);
1006 one.mode = o_mode;
1007 - hashcpy(a.oid.hash, a_sha);
1007 + oidcpy(&a.oid, a_oid);
1008 a.mode = a_mode;
1009 - hashcpy(b.oid.hash, b_sha);
1009 + oidcpy(&b.oid, b_oid);
1010 b.mode = b_mode;
1011 return merge_file_1(o, &one, &a, &b, branch1, branch2);
1012 }
1013
1014 static void handle_change_delete(struct merge_options *o,
1015 const char *path,
1016 - const unsigned char *o_sha, int o_mode,
1017 - const unsigned char *a_sha, int a_mode,
1018 - const unsigned char *b_sha, int b_mode,
1016 + const struct object_id *o_oid, int o_mode,
1017 + const struct object_id *a_oid, int a_mode,
1018 + const struct object_id *b_oid, int b_mode,
1019 const char *change, const char *change_past)
1020 {
1021 char *renamed = NULL;
1022 if (dir_in_way(path, !o->call_depth)) {
1023 - renamed = unique_path(o, path, a_sha ? o->branch1 : o->branch2);
1023 + renamed = unique_path(o, path, a_oid ? o->branch1 : o->branch2);
1024 }
1025
1026 if (o->call_depth) {
@@ -1030,20 +1030,20 @@ static void handle_change_delete(struct merge_options *o,
1030 * them, simply reuse the base version for virtual merge base.
1031 */
1032 remove_file_from_cache(path);
1033 - update_file(o, 0, o_sha, o_mode, renamed ? renamed : path);
1034 - } else if (!a_sha) {
1033 + update_file(o, 0, o_oid, o_mode, renamed ? renamed : path);
1034 + } else if (!a_oid) {
1035 if (!renamed) {
1036 output(o, 1, _("CONFLICT (%s/delete): %s deleted in %s "
1037 "and %s in %s. Version %s of %s left in tree."),
1038 change, path, o->branch1, change_past,
1039 o->branch2, o->branch2, path);
1040 - update_file(o, 0, b_sha, b_mode, path);
1040 + update_file(o, 0, b_oid, b_mode, path);
1041 } else {
1042 output(o, 1, _("CONFLICT (%s/delete): %s deleted in %s "
1043 "and %s in %s. Version %s of %s left in tree at %s."),
1044 change, path, o->branch1, change_past,
1045 o->branch2, o->branch2, path, renamed);
1046 - update_file(o, 0, b_sha, b_mode, renamed);
1046 + update_file(o, 0, b_oid, b_mode, renamed);
1047 }
1048 } else {
1049 if (!renamed) {
@@ -1056,7 +1056,7 @@ static void handle_change_delete(struct merge_options *o,
1056 "and %s in %s. Version %s of %s left in tree at %s."),
1057 change, path, o->branch2, change_past,
1058 o->branch1, o->branch1, path, renamed);
1059 - update_file(o, 0, a_sha, a_mode, renamed);
1059 + update_file(o, 0, a_oid, a_mode, renamed);
1060 }
1061 /*
1062 * No need to call update_file() on path when !renamed, since
@@ -1075,24 +1075,24 @@ static void conflict_rename_delete(struct merge_options *o,
1075 {
1076 const struct diff_filespec *orig = pair->one;
1077 const struct diff_filespec *dest = pair->two;
1078 - const unsigned char *a_sha = NULL;
1079 - const unsigned char *b_sha = NULL;
1078 + const struct object_id *a_oid = NULL;
1079 + const struct object_id *b_oid = NULL;
1080 int a_mode = 0;
1081 int b_mode = 0;
1082
1083 if (rename_branch == o->branch1) {
1084 - a_sha = dest->oid.hash;
1084 + a_oid = &dest->oid;
1085 a_mode = dest->mode;
1086 } else {
1087 - b_sha = dest->oid.hash;
1087 + b_oid = &dest->oid;
1088 b_mode = dest->mode;
1089 }
1090
1091 handle_change_delete(o,
1092 o->call_depth ? orig->path : dest->path,
1093 - orig->oid.hash, orig->mode,
1094 - a_sha, a_mode,
1095 - b_sha, b_mode,
1093 + &orig->oid, orig->mode,
1094 + a_oid, a_mode,
1095 + b_oid, b_mode,
1096 _("rename"), _("renamed"));
1097
1098 if (o->call_depth) {
@@ -1109,11 +1109,11 @@ static struct diff_filespec *filespec_from_entry(struct diff_filespec *target,
1109 struct stage_data *entry,
1110 int stage)
1111 {
1112 - unsigned char *sha = entry->stages[stage].oid.hash;
1112 + struct object_id *oid = &entry->stages[stage].oid;
1113 unsigned mode = entry->stages[stage].mode;
1114 - if (mode == 0 || is_null_sha1(sha))
1114 + if (mode == 0 || is_null_oid(oid))
1115 return NULL;
1116 - hashcpy(target->oid.hash, sha);
1116 + oidcpy(&target->oid, oid);
1117 target->mode = mode;
1118 return target;
1119 }
@@ -1142,7 +1142,7 @@ static void handle_file(struct merge_options *o,
1142 add = filespec_from_entry(&other, dst_entry, stage ^ 1);
1143 if (add) {
1144 char *add_name = unique_path(o, rename->path, other_branch);
1145 - update_file(o, 0, add->oid.hash, add->mode, add_name);
1145 + update_file(o, 0, &add->oid, add->mode, add_name);
1146
1147 remove_file(o, 0, rename->path, 0);
1148 dst_name = unique_path(o, rename->path, cur_branch);
@@ -1153,7 +1153,7 @@ static void handle_file(struct merge_options *o,
1153 rename->path, other_branch, dst_name);
1154 }
1155 }
1156 - update_file(o, 0, rename->oid.hash, rename->mode, dst_name);
1156 + update_file(o, 0, &rename->oid, rename->mode, dst_name);
1157 if (stage == 2)
1158 update_stages(rename->path, NULL, rename, add);
1159 else
@@ -1182,9 +1182,9 @@ static void conflict_rename_rename_1to2(struct merge_options *o,
1182 struct diff_filespec other;
1183 struct diff_filespec *add;
1184 mfi = merge_file_one(o, one->path,
1185 - one->oid.hash, one->mode,
1186 - a->oid.hash, a->mode,
1187 - b->oid.hash, b->mode,
1185 + &one->oid, one->mode,
1186 + &a->oid, a->mode,
1187 + &b->oid, b->mode,
1188 ci->branch1, ci->branch2);
1189 /*
1190 * FIXME: For rename/add-source conflicts (if we could detect
@@ -1192,7 +1192,7 @@ static void conflict_rename_rename_1to2(struct merge_options *o,
1192 * pathname and then either rename the add-source file to that
1193 * unique path, or use that unique path instead of src here.
1194 */
1195 - update_file(o, 0, mfi.oid.hash, mfi.mode, one->path);
1195 + update_file(o, 0, &mfi.oid, mfi.mode, one->path);
1196
1197 /*
1198 * Above, we put the merged content at the merge-base's
@@ -1204,12 +1204,12 @@ static void conflict_rename_rename_1to2(struct merge_options *o,
1204 */
1205 add = filespec_from_entry(&other, ci->dst_entry1, 2 ^ 1);
1206 if (add)
1207 - update_file(o, 0, add->oid.hash, add->mode, a->path);
1207 + update_file(o, 0, &add->oid, add->mode, a->path);
1208 else
1209 remove_file_from_cache(a->path);
1210 add = filespec_from_entry(&other, ci->dst_entry2, 3 ^ 1);
1211 if (add)
1212 - update_file(o, 0, add->oid.hash, add->mode, b->path);
1212 + update_file(o, 0, &add->oid, add->mode, b->path);
1213 else
1214 remove_file_from_cache(b->path);
1215 } else {
@@ -1255,16 +1255,16 @@ static void conflict_rename_rename_2to1(struct merge_options *o,
1255 * again later for the non-recursive merge.
1256 */
1257 remove_file(o, 0, path, 0);
1258 - update_file(o, 0, mfi_c1.oid.hash, mfi_c1.mode, a->path);
1259 - update_file(o, 0, mfi_c2.oid.hash, mfi_c2.mode, b->path);
1258 + update_file(o, 0, &mfi_c1.oid, mfi_c1.mode, a->path);
1259 + update_file(o, 0, &mfi_c2.oid, mfi_c2.mode, b->path);
1260 } else {
1261 char *new_path1 = unique_path(o, path, ci->branch1);
1262 char *new_path2 = unique_path(o, path, ci->branch2);
1263 output(o, 1, _("Renaming %s to %s and %s to %s instead"),
1264 a->path, new_path1, b->path, new_path2);
1265 remove_file(o, 0, path, 0);
1266 - update_file(o, 0, mfi_c1.oid.hash, mfi_c1.mode, new_path1);
1267 - update_file(o, 0, mfi_c2.oid.hash, mfi_c2.mode, new_path2);
1266 + update_file(o, 0, &mfi_c1.oid, mfi_c1.mode, new_path1);
1267 + update_file(o, 0, &mfi_c2.oid, mfi_c2.mode, new_path2);
1268 free(new_path2);
1269 free(new_path1);
1270 }
@@ -1431,7 +1431,7 @@ static int process_renames(struct merge_options *o,
1431 dst_other.mode = ren1->dst_entry->stages[other_stage].mode;
1432 try_merge = 0;
1433
1434 - if (sha_eq(src_other.oid.hash, null_sha1)) {
1434 + if (oid_eq(&src_other.oid, &null_oid)) {
1435 setup_rename_conflict_info(RENAME_DELETE,
1436 ren1->pair,
1437 NULL,
@@ -1443,7 +1443,7 @@ static int process_renames(struct merge_options *o,
1443 NULL,
1444 NULL);
1445 } else if ((dst_other.mode == ren1->pair->two->mode) &&
1446 - sha_eq(dst_other.oid.hash, ren1->pair->two->oid.hash)) {
1446 + oid_eq(&dst_other.oid, &ren1->pair->two->oid)) {
1447 /*
1448 * Added file on the other side identical to
1449 * the file being renamed: clean merge.
@@ -1453,12 +1453,12 @@ static int process_renames(struct merge_options *o,
1453 * update_file().
1454 */
1455 update_file_flags(o,
1456 - ren1->pair->two->oid.hash,
1456 + &ren1->pair->two->oid,
1457 ren1->pair->two->mode,
1458 ren1_dst,
1459 1, /* update_cache */
1460 0 /* update_wd */);
1461 - } else if (!sha_eq(dst_other.oid.hash, null_sha1)) {
1461 + } else if (!oid_eq(&dst_other.oid, &null_oid)) {
1462 clean_merge = 0;
1463 try_merge = 1;
1464 output(o, 1, _("CONFLICT (rename/add): Rename %s->%s in %s. "
@@ -1467,20 +1467,20 @@ static int process_renames(struct merge_options *o,
1467 ren1_dst, branch2);
1468 if (o->call_depth) {
1469 struct merge_file_info mfi;
1470 - mfi = merge_file_one(o, ren1_dst, null_sha1, 0,
1471 - ren1->pair->two->oid.hash,
1470 + mfi = merge_file_one(o, ren1_dst, &null_oid, 0,
1471 + &ren1->pair->two->oid,
1472 ren1->pair->two->mode,
1473 - dst_other.oid.hash,
1473 + &dst_other.oid,
1474 dst_other.mode,
1475 branch1, branch2);
1476 output(o, 1, _("Adding merged %s"), ren1_dst);
1477 - update_file(o, 0, mfi.oid.hash,
1477 + update_file(o, 0, &mfi.oid,
1478 mfi.mode, ren1_dst);
1479 try_merge = 0;
1480 } else {
1481 char *new_path = unique_path(o, ren1_dst, branch2);
1482 output(o, 1, _("Adding as %s instead"), new_path);
1483 - update_file(o, 0, dst_other.oid.hash,
1483 + update_file(o, 0, &dst_other.oid,
1484 dst_other.mode, new_path);
1485 free(new_path);
1486 }
@@ -1519,30 +1519,30 @@ static int process_renames(struct merge_options *o,
1519 return clean_merge;
1520 }
1521
1522 -static unsigned char *stage_sha(const unsigned char *sha, unsigned mode)
1522 +static struct object_id *stage_oid(const struct object_id *oid, unsigned mode)
1523 {
1524 - return (is_null_sha1(sha) || mode == 0) ? NULL: (unsigned char *)sha;
1524 + return (is_null_oid(oid) || mode == 0) ? NULL: (struct object_id *)oid;
1525 }
1526
1527 -static int read_sha1_strbuf(const unsigned char *sha1, struct strbuf *dst)
1527 +static int read_oid_strbuf(const struct object_id *oid, struct strbuf *dst)
1528 {
1529 void *buf;
1530 enum object_type type;
1531 unsigned long size;
1532 - buf = read_sha1_file(sha1, &type, &size);
1532 + buf = read_sha1_file(oid->hash, &type, &size);
1533 if (!buf)
1534 - return error(_("cannot read object %s"), sha1_to_hex(sha1));
1534 + return error(_("cannot read object %s"), oid_to_hex(oid));
1535 if (type != OBJ_BLOB) {
1536 free(buf);
1537 - return error(_("object %s is not a blob"), sha1_to_hex(sha1));
1537 + return error(_("object %s is not a blob"), oid_to_hex(oid));
1538 }
1539 strbuf_attach(dst, buf, size, size + 1);
1540 return 0;
1541 }
1542
1543 -static int blob_unchanged(const unsigned char *o_sha,
1543 +static int blob_unchanged(const struct object_id *o_oid,
1544 unsigned o_mode,
1545 - const unsigned char *a_sha,
1545 + const struct object_id *a_oid,
1546 unsigned a_mode,
1547 int renormalize, const char *path)
1548 {
@@ -1552,13 +1552,13 @@ static int blob_unchanged(const unsigned char *o_sha,
1552
1553 if (a_mode != o_mode)
1554 return 0;
1555 - if (sha_eq(o_sha, a_sha))
1555 + if (oid_eq(o_oid, a_oid))
1556 return 1;
1557 if (!renormalize)
1558 return 0;
1559
1560 - assert(o_sha && a_sha);
1561 - if (read_sha1_strbuf(o_sha, &o) || read_sha1_strbuf(a_sha, &a))
1560 + assert(o_oid && a_oid);
1561 + if (read_oid_strbuf(o_oid, &o) || read_oid_strbuf(a_oid, &a))
1562 goto error_return;
1563 /*
1564 * Note: binary | is used so that both renormalizations are
@@ -1577,23 +1577,23 @@ error_return:
1577
1578 static void handle_modify_delete(struct merge_options *o,
1579 const char *path,
1580 - unsigned char *o_sha, int o_mode,
1581 - unsigned char *a_sha, int a_mode,
1582 - unsigned char *b_sha, int b_mode)
1580 + struct object_id *o_oid, int o_mode,
1581 + struct object_id *a_oid, int a_mode,
1582 + struct object_id *b_oid, int b_mode)
1583 {
1584 handle_change_delete(o,
1585 path,
1586 - o_sha, o_mode,
1587 - a_sha, a_mode,
1588 - b_sha, b_mode,
1586 + o_oid, o_mode,
1587 + a_oid, a_mode,
1588 + b_oid, b_mode,
1589 _("modify"), _("modified"));
1590 }
1591
1592 static int merge_content(struct merge_options *o,
1593 const char *path,
1594 - unsigned char *o_sha, int o_mode,
1595 - unsigned char *a_sha, int a_mode,
1596 - unsigned char *b_sha, int b_mode,
1594 + struct object_id *o_oid, int o_mode,
1595 + struct object_id *a_oid, int a_mode,
1596 + struct object_id *b_oid, int b_mode,
1597 struct rename_conflict_info *rename_conflict_info)
1598 {
1599 const char *reason = _("content");
@@ -1602,16 +1602,16 @@ static int merge_content(struct merge_options *o,
1602 struct diff_filespec one, a, b;
1603 unsigned df_conflict_remains = 0;
1604
1605 - if (!o_sha) {
1605 + if (!o_oid) {
1606 reason = _("add/add");
1607 - o_sha = (unsigned char *)null_sha1;
1607 + o_oid = (struct object_id *)&null_oid;
1608 }
1609 one.path = a.path = b.path = (char *)path;
1610 - hashcpy(one.oid.hash, o_sha);
1610 + oidcpy(&one.oid, o_oid);
1611 one.mode = o_mode;
1612 - hashcpy(a.oid.hash, a_sha);
1612 + oidcpy(&a.oid, a_oid);
1613 a.mode = a_mode;
1614 - hashcpy(b.oid.hash, b_sha);
1614 + oidcpy(&b.oid, b_oid);
1615 b.mode = b_mode;
1616
1617 if (rename_conflict_info) {
@@ -1635,7 +1635,7 @@ static int merge_content(struct merge_options *o,
1635 o->branch2, path2);
1636
1637 if (mfi.clean && !df_conflict_remains &&
1638 - sha_eq(mfi.oid.hash, a_sha) && mfi.mode == a_mode) {
1638 + oid_eq(&mfi.oid, a_oid) && mfi.mode == a_mode) {
1639 int path_renamed_outside_HEAD;
1640 output(o, 3, _("Skipped %s (merged same as existing)"), path);
1641 /*
@@ -1646,7 +1646,7 @@ static int merge_content(struct merge_options *o,
1646 */
1647 path_renamed_outside_HEAD = !path2 || !strcmp(path, path2);
1648 if (!path_renamed_outside_HEAD) {
1649 - add_cacheinfo(mfi.mode, mfi.oid.hash, path,
1649 + add_cacheinfo(mfi.mode, &mfi.oid, path,
1650 0, (!o->call_depth), 0);
1651 return mfi.clean;
1652 }
@@ -1683,11 +1683,11 @@ static int merge_content(struct merge_options *o,
1683 }
1684 new_path = unique_path(o, path, rename_conflict_info->branch1);
1685 output(o, 1, _("Adding as %s instead"), new_path);
1686 - update_file(o, 0, mfi.oid.hash, mfi.mode, new_path);
1686 + update_file(o, 0, &mfi.oid, mfi.mode, new_path);
1687 free(new_path);
1688 mfi.clean = 0;
1689 } else {
1690 - update_file(o, mfi.clean, mfi.oid.hash, mfi.mode, path);
1690 + update_file(o, mfi.clean, &mfi.oid, mfi.mode, path);
1691 }
1692 return mfi.clean;
1693
@@ -1702,9 +1702,9 @@ static int process_entry(struct merge_options *o,
1702 unsigned o_mode = entry->stages[1].mode;
1703 unsigned a_mode = entry->stages[2].mode;
1704 unsigned b_mode = entry->stages[3].mode;
1705 - unsigned char *o_sha = stage_sha(entry->stages[1].oid.hash, o_mode);
1706 - unsigned char *a_sha = stage_sha(entry->stages[2].oid.hash, a_mode);
1707 - unsigned char *b_sha = stage_sha(entry->stages[3].oid.hash, b_mode);
1705 + struct object_id *o_oid = stage_oid(&entry->stages[1].oid, o_mode);
1706 + struct object_id *a_oid = stage_oid(&entry->stages[2].oid, a_mode);
1707 + struct object_id *b_oid = stage_oid(&entry->stages[3].oid, b_mode);
1708
1709 entry->processed = 1;
1710 if (entry->rename_conflict_info) {
@@ -1713,7 +1713,7 @@ static int process_entry(struct merge_options *o,
1713 case RENAME_NORMAL:
1714 case RENAME_ONE_FILE_TO_ONE:
1715 clean_merge = merge_content(o, path,
1716 - o_sha, o_mode, a_sha, a_mode, b_sha, b_mode,
1716 + o_oid, o_mode, a_oid, a_mode, b_oid, b_mode,
1717 conflict_info);
1718 break;
1719 case RENAME_DELETE:
@@ -1734,45 +1734,45 @@ static int process_entry(struct merge_options *o,
1734 entry->processed = 0;
1735 break;
1736 }
1737 - } else if (o_sha && (!a_sha || !b_sha)) {
1737 + } else if (o_oid && (!a_oid || !b_oid)) {
1738 /* Case A: Deleted in one */
1739 - if ((!a_sha && !b_sha) ||
1740 - (!b_sha && blob_unchanged(o_sha, o_mode, a_sha, a_mode, normalize, path)) ||
1741 - (!a_sha && blob_unchanged(o_sha, o_mode, b_sha, b_mode, normalize, path))) {
1739 + if ((!a_oid && !b_oid) ||
1740 + (!b_oid && blob_unchanged(o_oid, o_mode, a_oid, a_mode, normalize, path)) ||
1741 + (!a_oid && blob_unchanged(o_oid, o_mode, b_oid, b_mode, normalize, path))) {
1742 /* Deleted in both or deleted in one and
1743 * unchanged in the other */
1744 - if (a_sha)
1744 + if (a_oid)
1745 output(o, 2, _("Removing %s"), path);
1746 /* do not touch working file if it did not exist */
1747 - remove_file(o, 1, path, !a_sha);
1747 + remove_file(o, 1, path, !a_oid);
1748 } else {
1749 /* Modify/delete; deleted side may have put a directory in the way */
1750 clean_merge = 0;
1751 - handle_modify_delete(o, path, o_sha, o_mode,
1752 - a_sha, a_mode, b_sha, b_mode);
1751 + handle_modify_delete(o, path, o_oid, o_mode,
1752 + a_oid, a_mode, b_oid, b_mode);
1753 }
1754 - } else if ((!o_sha && a_sha && !b_sha) ||
1755 - (!o_sha && !a_sha && b_sha)) {
1754 + } else if ((!o_oid && a_oid && !b_oid) ||
1755 + (!o_oid && !a_oid && b_oid)) {
1756 /* Case B: Added in one. */
1757 /* [nothing|directory] -> ([nothing|directory], file) */
1758
1759 const char *add_branch;
1760 const char *other_branch;
1761 unsigned mode;
1762 - const unsigned char *sha;
1762 + const struct object_id *oid;
1763 const char *conf;
1764
1765 - if (a_sha) {
1765 + if (a_oid) {
1766 add_branch = o->branch1;
1767 other_branch = o->branch2;
1768 mode = a_mode;
1769 - sha = a_sha;
1769 + oid = a_oid;
1770 conf = _("file/directory");
1771 } else {
1772 add_branch = o->branch2;
1773 other_branch = o->branch1;
1774 mode = b_mode;
1775 - sha = b_sha;
1775 + oid = b_oid;
1776 conf = _("directory/file");
1777 }
1778 if (dir_in_way(path, !o->call_depth)) {
@@ -1781,22 +1781,22 @@ static int process_entry(struct merge_options *o,
1781 output(o, 1, _("CONFLICT (%s): There is a directory with name %s in %s. "
1782 "Adding %s as %s"),
1783 conf, path, other_branch, path, new_path);
1784 - update_file(o, 0, sha, mode, new_path);
1784 + update_file(o, 0, oid, mode, new_path);
1785 if (o->call_depth)
1786 remove_file_from_cache(path);
1787 free(new_path);
1788 } else {
1789 output(o, 2, _("Adding %s"), path);
1790 /* do not overwrite file if already present */
1791 - update_file_flags(o, sha, mode, path, 1, !a_sha);
1791 + update_file_flags(o, oid, mode, path, 1, !a_oid);
1792 }
1793 - } else if (a_sha && b_sha) {
1793 + } else if (a_oid && b_oid) {
1794 /* Case C: Added in both (check for same permissions) and */
1795 /* case D: Modified in both, but differently. */
1796 clean_merge = merge_content(o, path,
1797 - o_sha, o_mode, a_sha, a_mode, b_sha, b_mode,
1797 + o_oid, o_mode, a_oid, a_mode, b_oid, b_mode,
1798 NULL);
1799 - } else if (!o_sha && !a_sha && !b_sha) {
1799 + } else if (!o_oid && !a_oid && !b_oid) {
1800 /*
1801 * this entry was deleted altogether. a_mode == 0 means
1802 * we had that path and want to actively remove it.
@@ -1821,7 +1821,7 @@ int merge_trees(struct merge_options *o,
1821 common = shift_tree_object(head, common, o->subtree_shift);
1822 }
1823
1824 - if (sha_eq(common->object.oid.hash, merge->object.oid.hash)) {
1824 + if (oid_eq(&common->object.oid, &merge->object.oid)) {
1825 output(o, 0, _("Already up-to-date!"));
1826 *result = head;
1827 return 1;