merge-recursive: convert struct stage_data to use object_id
Convert the anonymous struct within struct stage_data to use struct object_id. The following Coccinelle semantic patch was used to implement this, followed by the transformations in object_id.cocci: @@ struct stage_data o; expression E1; @@ - o.stages[E1].sha + o.stages[E1].oid.hash @@ struct stage_data *p; expression E1; @@ - p->stages[E1].sha + p->stages[E1].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
fd429e986de0fd380b63c0a1949b72ef076f58cc
1 file changed
+18
-20
merge-recursive.c
+18
-20
@@ -90,7 +90,7 @@ struct rename_conflict_info {
90
struct stage_data {
91
struct {
92
unsigned mode;
93
- unsigned char sha[20];
93
+ struct object_id oid;
94
} stages[4];
95
struct rename_conflict_info *rename_conflict_info;
96
unsigned processed:1;
@@ -134,13 +134,11 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type,
134
int ostage2 = ostage1 ^ 1;
135
136
ci->ren1_other.path = pair1->one->path;
137
- hashcpy(ci->ren1_other.oid.hash,
138
- src_entry1->stages[ostage1].sha);
137
+ oidcpy(&ci->ren1_other.oid, &src_entry1->stages[ostage1].oid);
138
ci->ren1_other.mode = src_entry1->stages[ostage1].mode;
139
140
ci->ren2_other.path = pair2->one->path;
142
- hashcpy(ci->ren2_other.oid.hash,
143
- src_entry2->stages[ostage2].sha);
141
+ oidcpy(&ci->ren2_other.oid, &src_entry2->stages[ostage2].oid);
142
ci->ren2_other.mode = src_entry2->stages[ostage2].mode;
143
}
144
}
@@ -316,11 +314,11 @@ static struct stage_data *insert_stage_data(const char *path,
314
struct string_list_item *item;
315
struct stage_data *e = xcalloc(1, sizeof(struct stage_data));
316
get_tree_entry(o->object.oid.hash, path,
319
- e->stages[1].sha, &e->stages[1].mode);
317
+ e->stages[1].oid.hash, &e->stages[1].mode);
318
get_tree_entry(a->object.oid.hash, path,
321
- e->stages[2].sha, &e->stages[2].mode);
319
+ e->stages[2].oid.hash, &e->stages[2].mode);
320
get_tree_entry(b->object.oid.hash, path,
323
- e->stages[3].sha, &e->stages[3].mode);
321
+ e->stages[3].oid.hash, &e->stages[3].mode);
322
item = string_list_insert(entries, path);
323
item->util = e;
324
return e;
@@ -351,7 +349,7 @@ static struct string_list *get_unmerged(void)
349
}
350
e = item->util;
351
e->stages[ce_stage(ce)].mode = ce->ce_mode;
354
- hashcpy(e->stages[ce_stage(ce)].sha, ce->sha1);
352
+ hashcpy(e->stages[ce_stage(ce)].oid.hash, ce->sha1);
353
}
354
355
return unmerged;
@@ -574,9 +572,9 @@ static void update_entry(struct stage_data *entry,
572
entry->stages[1].mode = o->mode;
573
entry->stages[2].mode = a->mode;
574
entry->stages[3].mode = b->mode;
577
- hashcpy(entry->stages[1].sha, o->oid.hash);
578
- hashcpy(entry->stages[2].sha, a->oid.hash);
579
- hashcpy(entry->stages[3].sha, b->oid.hash);
575
+ oidcpy(&entry->stages[1].oid, &o->oid);
576
+ oidcpy(&entry->stages[2].oid, &a->oid);
577
+ oidcpy(&entry->stages[3].oid, &b->oid);
578
}
579
580
static int remove_file(struct merge_options *o, int clean,
@@ -1111,7 +1109,7 @@ static struct diff_filespec *filespec_from_entry(struct diff_filespec *target,
1109
struct stage_data *entry,
1110
int stage)
1111
{
1114
- unsigned char *sha = entry->stages[stage].sha;
1112
+ unsigned char *sha = entry->stages[stage].oid.hash;
1113
unsigned mode = entry->stages[stage].mode;
1114
if (mode == 0 || is_null_sha1(sha))
1115
return NULL;
@@ -1425,11 +1423,11 @@ static int process_renames(struct merge_options *o,
1423
remove_file(o, 1, ren1_src,
1424
renamed_stage == 2 || !was_tracked(ren1_src));
1425
1428
- hashcpy(src_other.oid.hash,
1429
- ren1->src_entry->stages[other_stage].sha);
1426
+ oidcpy(&src_other.oid,
1427
+ &ren1->src_entry->stages[other_stage].oid);
1428
src_other.mode = ren1->src_entry->stages[other_stage].mode;
1431
- hashcpy(dst_other.oid.hash,
1432
- ren1->dst_entry->stages[other_stage].sha);
1429
+ oidcpy(&dst_other.oid,
1430
+ &ren1->dst_entry->stages[other_stage].oid);
1431
dst_other.mode = ren1->dst_entry->stages[other_stage].mode;
1432
try_merge = 0;
1433
@@ -1703,9 +1701,9 @@ static int process_entry(struct merge_options *o,
1701
unsigned o_mode = entry->stages[1].mode;
1702
unsigned a_mode = entry->stages[2].mode;
1703
unsigned b_mode = entry->stages[3].mode;
1706
- unsigned char *o_sha = stage_sha(entry->stages[1].sha, o_mode);
1707
- unsigned char *a_sha = stage_sha(entry->stages[2].sha, a_mode);
1708
- unsigned char *b_sha = stage_sha(entry->stages[3].sha, b_mode);
1704
+ unsigned char *o_sha = stage_sha(entry->stages[1].oid.hash, o_mode);
1705
+ unsigned char *a_sha = stage_sha(entry->stages[2].oid.hash, a_mode);
1706
+ unsigned char *b_sha = stage_sha(entry->stages[3].oid.hash, b_mode);
1707
1708
entry->processed = 1;
1709
if (entry->rename_conflict_info) {