[PATCH v2 3/3] push: further simplify the logic to assign rejection status
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 22, 2013, 06:30 UTC
- Message-ID
- <1358836230-9197-4-git-send-email-gitster@pobox.com>
- In-Reply-To
- <1358836230-9197-1-git-send-email-gitster@pobox.com>
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 <gitster@pobox.com> ---
* 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