Skip to content

Commit fd429e9

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

1 file changed

Lines changed: 18 additions & 20 deletions

File tree

merge-recursive.c

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ struct rename_conflict_info {
9090
struct stage_data {
9191
struct {
9292
unsigned mode;
93-
unsigned char sha[20];
93+
struct object_id oid;
9494
} stages[4];
9595
struct rename_conflict_info *rename_conflict_info;
9696
unsigned processed:1;
@@ -134,13 +134,11 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type,
134134
int ostage2 = ostage1 ^ 1;
135135

136136
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);
139138
ci->ren1_other.mode = src_entry1->stages[ostage1].mode;
140139

141140
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);
144142
ci->ren2_other.mode = src_entry2->stages[ostage2].mode;
145143
}
146144
}
@@ -316,11 +314,11 @@ static struct stage_data *insert_stage_data(const char *path,
316314
struct string_list_item *item;
317315
struct stage_data *e = xcalloc(1, sizeof(struct stage_data));
318316
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);
320318
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);
322320
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);
324322
item = string_list_insert(entries, path);
325323
item->util = e;
326324
return e;
@@ -351,7 +349,7 @@ static struct string_list *get_unmerged(void)
351349
}
352350
e = item->util;
353351
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);
355353
}
356354

357355
return unmerged;
@@ -574,9 +572,9 @@ static void update_entry(struct stage_data *entry,
574572
entry->stages[1].mode = o->mode;
575573
entry->stages[2].mode = a->mode;
576574
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);
580578
}
581579

582580
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,
11111109
struct stage_data *entry,
11121110
int stage)
11131111
{
1114-
unsigned char *sha = entry->stages[stage].sha;
1112+
unsigned char *sha = entry->stages[stage].oid.hash;
11151113
unsigned mode = entry->stages[stage].mode;
11161114
if (mode == 0 || is_null_sha1(sha))
11171115
return NULL;
@@ -1425,11 +1423,11 @@ static int process_renames(struct merge_options *o,
14251423
remove_file(o, 1, ren1_src,
14261424
renamed_stage == 2 || !was_tracked(ren1_src));
14271425

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);
14301428
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);
14331431
dst_other.mode = ren1->dst_entry->stages[other_stage].mode;
14341432
try_merge = 0;
14351433

@@ -1703,9 +1701,9 @@ static int process_entry(struct merge_options *o,
17031701
unsigned o_mode = entry->stages[1].mode;
17041702
unsigned a_mode = entry->stages[2].mode;
17051703
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);
17091707

17101708
entry->processed = 1;
17111709
if (entry->rename_conflict_info) {

0 commit comments

Comments
 (0)