Skip to content

Commit 9b56149

Browse files
bk2204gitster
authored andcommitted
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>
1 parent fd429e9 commit 9b56149

1 file changed

Lines changed: 20 additions & 19 deletions

File tree

merge-recursive.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ static void update_file(struct merge_options *o,
819819
/* Low level file merging, update and removal */
820820

821821
struct merge_file_info {
822-
unsigned char sha[20];
822+
struct object_id oid;
823823
unsigned mode;
824824
unsigned clean:1,
825825
merge:1;
@@ -902,10 +902,10 @@ static struct merge_file_info merge_file_1(struct merge_options *o,
902902
result.clean = 0;
903903
if (S_ISREG(a->mode)) {
904904
result.mode = a->mode;
905-
hashcpy(result.sha, a->oid.hash);
905+
oidcpy(&result.oid, &a->oid);
906906
} else {
907907
result.mode = b->mode;
908-
hashcpy(result.sha, b->oid.hash);
908+
oidcpy(&result.oid, &b->oid);
909909
}
910910
} else {
911911
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,
925925
}
926926

927927
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);
929929
else if (sha_eq(b->oid.hash, one->oid.hash))
930-
hashcpy(result.sha, a->oid.hash);
930+
oidcpy(&result.oid, &a->oid);
931931
else if (S_ISREG(a->mode)) {
932932
mmbuffer_t result_buf;
933933
int merge_status;
@@ -939,21 +939,21 @@ static struct merge_file_info merge_file_1(struct merge_options *o,
939939
die(_("Failed to execute internal merge"));
940940

941941
if (write_sha1_file(result_buf.ptr, result_buf.size,
942-
blob_type, result.sha))
942+
blob_type, result.oid.hash))
943943
die(_("Unable to add %s to database"),
944944
a->path);
945945

946946
free(result_buf.ptr);
947947
result.clean = (merge_status == 0);
948948
} else if (S_ISGITLINK(a->mode)) {
949-
result.clean = merge_submodule(result.sha,
949+
result.clean = merge_submodule(result.oid.hash,
950950
one->path,
951951
one->oid.hash,
952952
a->oid.hash,
953953
b->oid.hash,
954954
!o->call_depth);
955955
} else if (S_ISLNK(a->mode)) {
956-
hashcpy(result.sha, a->oid.hash);
956+
oidcpy(&result.oid, &a->oid);
957957

958958
if (!sha_eq(a->oid.hash, b->oid.hash))
959959
result.clean = 0;
@@ -1192,7 +1192,7 @@ static void conflict_rename_rename_1to2(struct merge_options *o,
11921192
* pathname and then either rename the add-source file to that
11931193
* unique path, or use that unique path instead of src here.
11941194
*/
1195-
update_file(o, 0, mfi.sha, mfi.mode, one->path);
1195+
update_file(o, 0, mfi.oid.hash, mfi.mode, one->path);
11961196

11971197
/*
11981198
* 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,
12551255
* again later for the non-recursive merge.
12561256
*/
12571257
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);
12601260
} else {
12611261
char *new_path1 = unique_path(o, path, ci->branch1);
12621262
char *new_path2 = unique_path(o, path, ci->branch2);
12631263
output(o, 1, _("Renaming %s to %s and %s to %s instead"),
12641264
a->path, new_path1, b->path, new_path2);
12651265
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);
12681268
free(new_path2);
12691269
free(new_path1);
12701270
}
@@ -1474,7 +1474,8 @@ static int process_renames(struct merge_options *o,
14741474
dst_other.mode,
14751475
branch1, branch2);
14761476
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);
14781479
try_merge = 0;
14791480
} else {
14801481
char *new_path = unique_path(o, ren1_dst, branch2);
@@ -1634,7 +1635,7 @@ static int merge_content(struct merge_options *o,
16341635
o->branch2, path2);
16351636

16361637
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) {
16381639
int path_renamed_outside_HEAD;
16391640
output(o, 3, _("Skipped %s (merged same as existing)"), path);
16401641
/*
@@ -1645,7 +1646,7 @@ static int merge_content(struct merge_options *o,
16451646
*/
16461647
path_renamed_outside_HEAD = !path2 || !strcmp(path, path2);
16471648
if (!path_renamed_outside_HEAD) {
1648-
add_cacheinfo(mfi.mode, mfi.sha, path,
1649+
add_cacheinfo(mfi.mode, mfi.oid.hash, path,
16491650
0, (!o->call_depth), 0);
16501651
return mfi.clean;
16511652
}
@@ -1671,7 +1672,7 @@ static int merge_content(struct merge_options *o,
16711672
else {
16721673
int file_from_stage2 = was_tracked(path);
16731674
struct diff_filespec merged;
1674-
hashcpy(merged.oid.hash, mfi.sha);
1675+
oidcpy(&merged.oid, &mfi.oid);
16751676
merged.mode = mfi.mode;
16761677

16771678
update_stages(path, NULL,
@@ -1682,11 +1683,11 @@ static int merge_content(struct merge_options *o,
16821683
}
16831684
new_path = unique_path(o, path, rename_conflict_info->branch1);
16841685
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);
16861687
free(new_path);
16871688
mfi.clean = 0;
16881689
} else {
1689-
update_file(o, mfi.clean, mfi.sha, mfi.mode, path);
1690+
update_file(o, mfi.clean, mfi.oid.hash, mfi.mode, path);
16901691
}
16911692
return mfi.clean;
16921693

0 commit comments

Comments
 (0)