merge-recursive: remove unnecessary oid_eq function
cover merge-recursive: remove unnecessary oid_eq function
merge-recursive has an unnecessary wrapper for oideq. Remove it.
Elijah Newren (1):
merge-recursive: remove unnecessary oid_eq function
merge-recursive.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-)
base-commit: 0a76bd7381ec0dbb7c43776eb6d1ac906bca29e6
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-685%2Fnewren%2Fremove_oid_eq_wrapper-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-685/newren/remove_oid_eq_wrapper-v1
Pull-Request: https://github.com/git/git/pull/685
Signature · 1 line
gitgitgadget
PATCH 1/1 merge-recursive: remove unnecessary oid_eq function
From: Elijah Newren <[email protected]>
Back when merge-recursive was first introduced in commit 6d297f8137 (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 9047ebbc22 (Split out merge_recursive() to merge-recursive.c, 2008-08-12). In commit b4da9d62f9 (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.
--- merge-recursive.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-)
merge-recursive.c +11 -22
@@ -224,17 +224,6 @@ static struct commit *make_virtual_commit(struct repository *repo,return commit; } -/* -* Since we use get_tree_entry(), which does not put the read object into -* the object pool, we cannot rely on a == b. -*/ -static int oid_eq (const struct object_id *a,const struct object_id *b) -{ -if (!a && !b) -return 2 ; -return a && b &&oideq (a, b); -} -enum rename_type {RENAME_NORMAL =0 ,RENAME_VIA_DIR ,
@@ -805,7 +794,7 @@ static int was_tracked_and_matches(struct merge_options *opt, const char *path,/* See if the file we were tracking before matches */ ce = opt->priv->orig_index.cache[pos]; -return (oid_eq (&ce->oid, &blob->oid) && ce->ce_mode == blob->mode); +return (oideq (&ce->oid, &blob->oid) && ce->ce_mode == blob->mode); }/*
@@ -1317,7 +1306,7 @@ static int merge_mode_and_contents(struct merge_options *opt,oidcpy (&result->blob.oid, &b->oid); } }else { -if (!oid_eq (&a->oid, &o->oid) && !oid_eq (&b->oid, &o->oid)) +if (!oideq (&a->oid, &o->oid) && !oideq (&b->oid, &o->oid)) result->merge =1 ;/*
@@ -1333,9 +1322,9 @@ static int merge_mode_and_contents(struct merge_options *opt, } } -if (oid_eq (&a->oid, &b->oid) ||oid_eq (&a->oid, &o->oid)) +if (oideq (&a->oid, &b->oid) ||oideq (&a->oid, &o->oid))oidcpy (&result->blob.oid, &b->oid); -else if (oid_eq (&b->oid, &o->oid)) +else if (oideq (&b->oid, &o->oid))oidcpy (&result->blob.oid, &a->oid);else if (S_ISREG (a->mode)) {mmbuffer_t result_buf;
@@ -1368,7 +1357,7 @@ static int merge_mode_and_contents(struct merge_options *opt,switch (opt->recursive_variant) {case MERGE_VARIANT_NORMAL :oidcpy (&result->blob.oid, &a->oid); -if (!oid_eq (&a->oid, &b->oid)) +if (!oideq (&a->oid, &b->oid)) result->clean =0 ;break ;case MERGE_VARIANT_OURS :
@@ -2836,15 +2825,15 @@ static int process_renames(struct merge_options *opt, dst_other.mode = ren1->dst_entry->stages[other_stage].mode; try_merge =0 ; -if (oid_eq (&src_other.oid, &null_oid) && +if (oideq (&src_other.oid, &null_oid) && ren1->dir_rename_original_type =='A' ) {setup_rename_conflict_info (RENAME_VIA_DIR , opt, ren1,NULL ); - }else if (oid_eq (&src_other.oid, &null_oid)) { + }else if (oideq (&src_other.oid, &null_oid)) {setup_rename_conflict_info (RENAME_DELETE , opt, ren1,NULL ); }else if ((dst_other.mode == ren1->pair->two->mode) && -oid_eq (&dst_other.oid, &ren1->pair->two->oid)) { +oideq (&dst_other.oid, &ren1->pair->two->oid)) {/* * Added file on the other side identical to * the file being renamed: clean merge.
@@ -2859,7 +2848,7 @@ static int process_renames(struct merge_options *opt, 1, /* update_cache */ 0 /* update_wd */)) clean_merge =-1 ; - }else if (!oid_eq (&dst_other.oid, &null_oid)) { + }else if (!oideq (&dst_other.oid, &null_oid)) {/* * Probably not a clean merge, but it's * premature to set clean_merge to 0 here,
@@ -3037,7 +3026,7 @@ static int blob_unchanged(struct merge_options *opt,if (a->mode != o->mode)return 0 ; -if (oid_eq (&o->oid, &a->oid)) +if (oideq (&o->oid, &a->oid))return 1 ;if (!renormalize)return 0 ;
@@ -3478,7 +3467,7 @@ static int merge_trees_internal(struct merge_options *opt, opt->subtree_shift); } -if (oid_eq (&merge_base->object.oid, &merge->object.oid)) { +if (oideq (&merge_base->object.oid, &merge->object.oid)) {output (opt,0 ,_ ("Already up to date!" )); *result = head;return 1 ;
Signature · 1 line
gitgitgadget
Quoted 11 lines · Elijah Newren via GitGitGadget
From: Elijah Newren <[email protected]>
Back when merge-recursive was first introduced in commit
6d297f8137(Status update on merge-recursive in C, 2006-07-08), it created asha_eq()function. This function pre-dated the introduction ofhashcmp()tocache.hby about a month, but was switched over to usinghashcmp()as part of commit9047ebbc22(Split outmerge_recursive()tomerge-recursive.c, 2008-08-12). In commitb4da9d62f9(merge-recursive:
convert leaf functions to use structobject_id, 2016-06-24),sha_eq()was renamed tooid_eq()and itshashcmp()call was switched tooideq().
Quoted 7 lines
oid_eq()is basically just a wrapper aroundoideq()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 mainoideq()so all callers could benefit from them.)
Just for some historical yuck values ^W^W entertainment, 6d297f81373:merge-recursive.c shows how the function was called and needed to prepare for NULL inputs.
I agree that today's code won't need the "two NULLs are equal, and NULL is never equal to anything" hack. We've come a long way ;-)
Hi Elijah,
Quoted 19 lines · Elijah Newren via GitGitGadget
From: Elijah Newren <[email protected]>
Back when merge-recursive was first introduced in commit
6d297f8137(Status update on merge-recursive in C, 2006-07-08), it created asha_eq()function. This function pre-dated the introduction ofhashcmp()tocache.hby about a month, but was switched over to usinghashcmp()as part of commit9047ebbc22(Split outmerge_recursive()tomerge-recursive.c, 2008-08-12). In commitb4da9d62f9(merge-recursive:
convert leaf functions to use structobject_id, 2016-06-24),sha_eq()was renamed tooid_eq()and itshashcmp()call was switched tooideq().
oid_eq()is basically just a wrapper aroundoideq()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 mainoideq()so all callers could benefit from them.)
Quoted 5 lines
Reduce the cognitive overhead of having both
oid_eq()andoideq(), by getting rid of merge-recursive's specialoid_eq()wrapper.Signed-off-by Elijah Newren <[email protected]>---
The patch and the commit message look good to me!
Thanks,
Dscho
Quoted 113 lines
merge-recursive.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-)merge-recursive.c +11
-23@@ -224,17 +224,6 @@ static struct commit *make_virtual_commit(struct repository *repo,return commit; } -/* -* Since we use get_tree_entry(), which does not put the read object into -* the object pool, we cannot rely on a == b. -*/ -static int oid_eq (const struct object_id *a,const struct object_id *b) -{ -if (!a && !b) -return 2 ; -return a && b &&oideq (a, b); -} -enum rename_type {RENAME_NORMAL =0 ,RENAME_VIA_DIR ,@@ -805,7 +794,7 @@ static int was_tracked_and_matches(struct merge_options *opt, const char *path,/* See if the file we were tracking before matches */ ce = opt->priv->orig_index.cache[pos]; -return (oid_eq (&ce->oid, &blob->oid) && ce->ce_mode == blob->mode); +return (oideq (&ce->oid, &blob->oid) && ce->ce_mode == blob->mode); }/* @@ -1317,7 +1306,7 @@ static int merge_mode_and_contents(struct merge_options *opt,oidcpy (&result->blob.oid, &b->oid); } }else { -if (!oid_eq (&a->oid, &o->oid) && !oid_eq (&b->oid, &o->oid)) +if (!oideq (&a->oid, &o->oid) && !oideq (&b->oid, &o->oid)) result->merge =1 ;/* @@ -1333,9 +1322,9 @@ static int merge_mode_and_contents(struct merge_options *opt, } } -if (oid_eq (&a->oid, &b->oid) ||oid_eq (&a->oid, &o->oid)) +if (oideq (&a->oid, &b->oid) ||oideq (&a->oid, &o->oid))oidcpy (&result->blob.oid, &b->oid); -else if (oid_eq (&b->oid, &o->oid)) +else if (oideq (&b->oid, &o->oid))oidcpy (&result->blob.oid, &a->oid);else if (S_ISREG (a->mode)) {mmbuffer_t result_buf;@@ -1368,7 +1357,7 @@ static int merge_mode_and_contents(struct merge_options *opt,switch (opt->recursive_variant) {case MERGE_VARIANT_NORMAL :oidcpy (&result->blob.oid, &a->oid); -if (!oid_eq (&a->oid, &b->oid)) +if (!oideq (&a->oid, &b->oid)) result->clean =0 ;break ;case MERGE_VARIANT_OURS :@@ -2836,15 +2825,15 @@ static int process_renames(struct merge_options *opt, dst_other.mode = ren1->dst_entry->stages[other_stage].mode; try_merge =0 ; -if (oid_eq (&src_other.oid, &null_oid) && +if (oideq (&src_other.oid, &null_oid) && ren1->dir_rename_original_type =='A' ) {setup_rename_conflict_info (RENAME_VIA_DIR , opt, ren1,NULL ); - }else if (oid_eq (&src_other.oid, &null_oid)) { + }else if (oideq (&src_other.oid, &null_oid)) {setup_rename_conflict_info (RENAME_DELETE , opt, ren1,NULL ); }else if ((dst_other.mode == ren1->pair->two->mode) && -oid_eq (&dst_other.oid, &ren1->pair->two->oid)) { +oideq (&dst_other.oid, &ren1->pair->two->oid)) {/* * Added file on the other side identical to * the file being renamed: clean merge. @@ -2859,7 +2848,7 @@ static int process_renames(struct merge_options *opt, 1, /* update_cache */ 0 /* update_wd */)) clean_merge =-1 ; - }else if (!oid_eq (&dst_other.oid, &null_oid)) { + }else if (!oideq (&dst_other.oid, &null_oid)) {/* * Probably not a clean merge, but it's * premature to set clean_merge to 0 here, @@ -3037,7 +3026,7 @@ static int blob_unchanged(struct merge_options *opt,if (a->mode != o->mode)return 0 ; -if (oid_eq (&o->oid, &a->oid)) +if (oideq (&o->oid, &a->oid))return 1 ;if (!renormalize)return 0 ;@@ -3478,7 +3467,7 @@ static int merge_trees_internal(struct merge_options *opt, opt->subtree_shift); } -if (oid_eq (&merge_base->object.oid, &merge->object.oid)) { +if (oideq (&merge_base->object.oid, &merge->object.oid)) {output (opt,0 ,_ ("Already up to date!" )); *result = head;return 1 ; --gitgitgadget