[PATCH v2 3/3] push: further simplify the logic to assign rejection status
From: Junio C Hamano <hidden>
Date: 2016-06-15 22:55:51
Subsystem:
the rest · Maintainer:
Linus Torvalds
Instead of using deeply nested if/else statements, first decide what rejection status we would get if this push weren't forced, and then assign the rejection reason to the ref->status field and flip the ref->forced_update field when we forced a push for a ref that indeed required forcing. Signed-off-by: Junio C Hamano <redacted> --- * The first one mistakenly changed the semantics and reported a forced push even when the push was done with useless and unnecessary --force option (e.g. the update was properly fast-forwarding but --force was given from the command line). This fixes it. remote.c | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-)
diff --git a/remote.c b/remote.c
index c991915..af2136d 100644
--- a/remote.c
+++ b/remote.c@@ -1318,32 +1318,22 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror, */ if (!ref->deletion && !is_null_sha1(ref->old_sha1)) { - if (!prefixcmp(ref->name, "refs/tags/")) { - if (!force_ref_update) { - ref->status = REF_STATUS_REJECT_ALREADY_EXISTS; - continue; - } + int status = 0; + + if (!prefixcmp(ref->name, "refs/tags/")) + status = REF_STATUS_REJECT_ALREADY_EXISTS; + else if (!has_sha1_file(ref->old_sha1)) + status = REF_STATUS_REJECT_FETCH_FIRST; + else if (!lookup_commit_reference_gently(ref->old_sha1, 1) || + !lookup_commit_reference_gently(ref->new_sha1, 1)) + status = REF_STATUS_REJECT_NEEDS_FORCE; + else if (!ref_newer(ref->new_sha1, ref->old_sha1)) + status = REF_STATUS_REJECT_NONFASTFORWARD; + + if (!force_ref_update) + ref->status = status; + else if (status) ref->forced_update = 1; - } else if (!has_sha1_file(ref->old_sha1)) { - if (!force_ref_update) { - ref->status = REF_STATUS_REJECT_FETCH_FIRST; - continue; - } - ref->forced_update = 1; - } else if (!lookup_commit_reference_gently(ref->old_sha1, 1) || - !lookup_commit_reference_gently(ref->new_sha1, 1)) { - if (!force_ref_update) { - ref->status = REF_STATUS_REJECT_NEEDS_FORCE; - continue; - } - ref->forced_update = 1; - } else if (!ref_newer(ref->new_sha1, ref->old_sha1)) { - if (!force_ref_update) { - ref->status = REF_STATUS_REJECT_NONFASTFORWARD; - continue; - } - ref->forced_update = 1; - } } } }
--
1.8.1.1.498.gfdee8be