Skip to content

Commit 763a59e

Browse files
newrengitster
authored andcommitted
merge-recursive: remove unnecessary oid_eq function
Back when merge-recursive was first introduced in commit 6d297f8 (Status update on merge-recursive in C, 2006-07-08), it created a sha_eq() function. This function pre-dated the introduction of hashcmp() to cache.h by about a month, but was switched over to using hashcmp() as part of commit 9047ebb (Split out merge_recursive() to merge-recursive.c, 2008-08-12). In commit b4da9d6 (merge-recursive: convert leaf functions to use struct object_id, 2016-06-24), sha_eq() was renamed to oid_eq() and its hashcmp() call was switched to oideq(). oid_eq() is basically just a wrapper around oideq() that has some extra checks to protect against NULL arguments or to allow short-circuiting if one of the arguments is NULL. I don't know if any caller ever tried to call with NULL arguments, but certainly none do now which means the extra checks serve no purpose. (Also, if these checks were genuinely useful, then they probably should be added to the main oideq() so all callers could benefit from them.) Reduce the cognitive overhead of having both oid_eq() and oideq(), by getting rid of merge-recursive's special oid_eq() wrapper. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 53a06cf commit 763a59e

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

merge-recursive.c

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,6 @@ static struct commit *make_virtual_commit(struct repository *repo,
224224
return commit;
225225
}
226226

227-
/*
228-
* Since we use get_tree_entry(), which does not put the read object into
229-
* the object pool, we cannot rely on a == b.
230-
*/
231-
static int oid_eq(const struct object_id *a, const struct object_id *b)
232-
{
233-
if (!a && !b)
234-
return 2;
235-
return a && b && oideq(a, b);
236-
}
237-
238227
enum rename_type {
239228
RENAME_NORMAL = 0,
240229
RENAME_VIA_DIR,
@@ -805,7 +794,7 @@ static int was_tracked_and_matches(struct merge_options *opt, const char *path,
805794

806795
/* See if the file we were tracking before matches */
807796
ce = opt->priv->orig_index.cache[pos];
808-
return (oid_eq(&ce->oid, &blob->oid) && ce->ce_mode == blob->mode);
797+
return (oideq(&ce->oid, &blob->oid) && ce->ce_mode == blob->mode);
809798
}
810799

811800
/*
@@ -1317,7 +1306,7 @@ static int merge_mode_and_contents(struct merge_options *opt,
13171306
oidcpy(&result->blob.oid, &b->oid);
13181307
}
13191308
} else {
1320-
if (!oid_eq(&a->oid, &o->oid) && !oid_eq(&b->oid, &o->oid))
1309+
if (!oideq(&a->oid, &o->oid) && !oideq(&b->oid, &o->oid))
13211310
result->merge = 1;
13221311

13231312
/*
@@ -1333,9 +1322,9 @@ static int merge_mode_and_contents(struct merge_options *opt,
13331322
}
13341323
}
13351324

1336-
if (oid_eq(&a->oid, &b->oid) || oid_eq(&a->oid, &o->oid))
1325+
if (oideq(&a->oid, &b->oid) || oideq(&a->oid, &o->oid))
13371326
oidcpy(&result->blob.oid, &b->oid);
1338-
else if (oid_eq(&b->oid, &o->oid))
1327+
else if (oideq(&b->oid, &o->oid))
13391328
oidcpy(&result->blob.oid, &a->oid);
13401329
else if (S_ISREG(a->mode)) {
13411330
mmbuffer_t result_buf;
@@ -1368,7 +1357,7 @@ static int merge_mode_and_contents(struct merge_options *opt,
13681357
switch (opt->recursive_variant) {
13691358
case MERGE_VARIANT_NORMAL:
13701359
oidcpy(&result->blob.oid, &a->oid);
1371-
if (!oid_eq(&a->oid, &b->oid))
1360+
if (!oideq(&a->oid, &b->oid))
13721361
result->clean = 0;
13731362
break;
13741363
case MERGE_VARIANT_OURS:
@@ -2778,15 +2767,15 @@ static int process_renames(struct merge_options *opt,
27782767
dst_other.mode = ren1->dst_entry->stages[other_stage].mode;
27792768
try_merge = 0;
27802769

2781-
if (oid_eq(&src_other.oid, &null_oid) &&
2770+
if (oideq(&src_other.oid, &null_oid) &&
27822771
ren1->dir_rename_original_type == 'A') {
27832772
setup_rename_conflict_info(RENAME_VIA_DIR,
27842773
opt, ren1, NULL);
2785-
} else if (oid_eq(&src_other.oid, &null_oid)) {
2774+
} else if (oideq(&src_other.oid, &null_oid)) {
27862775
setup_rename_conflict_info(RENAME_DELETE,
27872776
opt, ren1, NULL);
27882777
} else if ((dst_other.mode == ren1->pair->two->mode) &&
2789-
oid_eq(&dst_other.oid, &ren1->pair->two->oid)) {
2778+
oideq(&dst_other.oid, &ren1->pair->two->oid)) {
27902779
/*
27912780
* Added file on the other side identical to
27922781
* the file being renamed: clean merge.
@@ -2801,7 +2790,7 @@ static int process_renames(struct merge_options *opt,
28012790
1, /* update_cache */
28022791
0 /* update_wd */))
28032792
clean_merge = -1;
2804-
} else if (!oid_eq(&dst_other.oid, &null_oid)) {
2793+
} else if (!oideq(&dst_other.oid, &null_oid)) {
28052794
/*
28062795
* Probably not a clean merge, but it's
28072796
* premature to set clean_merge to 0 here,
@@ -2979,7 +2968,7 @@ static int blob_unchanged(struct merge_options *opt,
29792968

29802969
if (a->mode != o->mode)
29812970
return 0;
2982-
if (oid_eq(&o->oid, &a->oid))
2971+
if (oideq(&o->oid, &a->oid))
29832972
return 1;
29842973
if (!renormalize)
29852974
return 0;
@@ -3420,7 +3409,7 @@ static int merge_trees_internal(struct merge_options *opt,
34203409
opt->subtree_shift);
34213410
}
34223411

3423-
if (oid_eq(&merge_base->object.oid, &merge->object.oid)) {
3412+
if (oideq(&merge_base->object.oid, &merge->object.oid)) {
34243413
output(opt, 0, _("Already up to date!"));
34253414
*result = head;
34263415
return 1;

0 commit comments

Comments
 (0)