merge-recursive: convert struct merge_file_info to object_id
Convert struct merge_file_info to use struct object_id. The following Coccinelle semantic patch was used to implement this, followed by the transformations in object_id.cocci: @@ struct merge_file_info o; @@ - o.sha + o.oid.hash @@ struct merge_file_info *p; @@ - p->sha + p->oid.hash 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
9b561499963d3f8b9ad15f5eae667ec5558f5af1
1 file changed
+20
-19
merge-recursive.c
+20
-19
@@ -819,7 +819,7 @@ static void update_file(struct merge_options *o,
819
/* Low level file merging, update and removal */
820
821
struct merge_file_info {
822
- unsigned char sha[20];
822
+ struct object_id oid;
823
unsigned mode;
824
unsigned clean:1,
825
merge:1;
@@ -902,10 +902,10 @@ static struct merge_file_info merge_file_1(struct merge_options *o,
902
result.clean = 0;
903
if (S_ISREG(a->mode)) {
904
result.mode = a->mode;
905
- hashcpy(result.sha, a->oid.hash);
905
+ oidcpy(&result.oid, &a->oid);
906
} else {
907
result.mode = b->mode;
908
- hashcpy(result.sha, b->oid.hash);
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))
@@ -925,9 +925,9 @@ static struct merge_file_info merge_file_1(struct merge_options *o,
925
}
926
927
if (sha_eq(a->oid.hash, b->oid.hash) || sha_eq(a->oid.hash, one->oid.hash))
928
- hashcpy(result.sha, b->oid.hash);
928
+ oidcpy(&result.oid, &b->oid);
929
else if (sha_eq(b->oid.hash, one->oid.hash))
930
- hashcpy(result.sha, a->oid.hash);
930
+ oidcpy(&result.oid, &a->oid);
931
else if (S_ISREG(a->mode)) {
932
mmbuffer_t result_buf;
933
int merge_status;
@@ -939,21 +939,21 @@ static struct merge_file_info merge_file_1(struct merge_options *o,
939
die(_("Failed to execute internal merge"));
940
941
if (write_sha1_file(result_buf.ptr, result_buf.size,
942
- blob_type, result.sha))
942
+ blob_type, result.oid.hash))
943
die(_("Unable to add %s to database"),
944
a->path);
945
946
free(result_buf.ptr);
947
result.clean = (merge_status == 0);
948
} else if (S_ISGITLINK(a->mode)) {
949
- result.clean = merge_submodule(result.sha,
949
+ result.clean = merge_submodule(result.oid.hash,
950
one->path,
951
one->oid.hash,
952
a->oid.hash,
953
b->oid.hash,
954
!o->call_depth);
955
} else if (S_ISLNK(a->mode)) {
956
- hashcpy(result.sha, a->oid.hash);
956
+ oidcpy(&result.oid, &a->oid);
957
958
if (!sha_eq(a->oid.hash, b->oid.hash))
959
result.clean = 0;
@@ -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.sha, mfi.mode, one->path);
1195
+ update_file(o, 0, mfi.oid.hash, mfi.mode, one->path);
1196
1197
/*
1198
* Above, we put the merged content at the merge-base's
@@ -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.sha, mfi_c1.mode, a->path);
1259
- update_file(o, 0, mfi_c2.sha, mfi_c2.mode, b->path);
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);
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.sha, mfi_c1.mode, new_path1);
1267
- update_file(o, 0, mfi_c2.sha, mfi_c2.mode, new_path2);
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);
1268
free(new_path2);
1269
free(new_path1);
1270
}
@@ -1474,7 +1474,8 @@ static int process_renames(struct merge_options *o,
1474
dst_other.mode,
1475
branch1, branch2);
1476
output(o, 1, _("Adding merged %s"), ren1_dst);
1477
- update_file(o, 0, mfi.sha, mfi.mode, ren1_dst);
1477
+ update_file(o, 0, mfi.oid.hash,
1478
+ mfi.mode, ren1_dst);
1479
try_merge = 0;
1480
} else {
1481
char *new_path = unique_path(o, ren1_dst, branch2);
@@ -1634,7 +1635,7 @@ static int merge_content(struct merge_options *o,
1635
o->branch2, path2);
1636
1637
if (mfi.clean && !df_conflict_remains &&
1637
- sha_eq(mfi.sha, a_sha) && mfi.mode == a_mode) {
1638
+ sha_eq(mfi.oid.hash, a_sha) && mfi.mode == a_mode) {
1639
int path_renamed_outside_HEAD;
1640
output(o, 3, _("Skipped %s (merged same as existing)"), path);
1641
/*
@@ -1645,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) {
1648
- add_cacheinfo(mfi.mode, mfi.sha, path,
1649
+ add_cacheinfo(mfi.mode, mfi.oid.hash, path,
1650
0, (!o->call_depth), 0);
1651
return mfi.clean;
1652
}
@@ -1671,7 +1672,7 @@ static int merge_content(struct merge_options *o,
1672
else {
1673
int file_from_stage2 = was_tracked(path);
1674
struct diff_filespec merged;
1674
- hashcpy(merged.oid.hash, mfi.sha);
1675
+ oidcpy(&merged.oid, &mfi.oid);
1676
merged.mode = mfi.mode;
1677
1678
update_stages(path, NULL,
@@ -1682,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);
1685
- update_file(o, 0, mfi.sha, mfi.mode, new_path);
1686
+ update_file(o, 0, mfi.oid.hash, mfi.mode, new_path);
1687
free(new_path);
1688
mfi.clean = 0;
1689
} else {
1689
- update_file(o, mfi.clean, mfi.sha, mfi.mode, path);
1690
+ update_file(o, mfi.clean, mfi.oid.hash, mfi.mode, path);
1691
}
1692
return mfi.clean;
1693