Skip to content

Commit 0f4d498

Browse files
committed
push: further simplify the logic to assign rejection reason
First compute the reason why this push would fail if done without "--force", and then fail it by assigning that reason when the push was not forced (or if there is no reason to require force, allow it to succeed). Record the fact that the push was forced in the forced_update field only when the push would have failed without the option. The code becomes shorter, less repetitive and easier to read this way, especially given that the set of rejection reasons will be extended in a later patch. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5ece083 commit 0f4d498

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

remote.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,23 +1318,18 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
13181318
*/
13191319

13201320
if (!ref->deletion && !is_null_sha1(ref->old_sha1)) {
1321-
int nonfastforward =
1322-
!has_sha1_file(ref->old_sha1)
1323-
|| !ref_newer(ref->new_sha1, ref->old_sha1);
1324-
1325-
if (!prefixcmp(ref->name, "refs/tags/")) {
1326-
if (!force_ref_update) {
1327-
ref->status = REF_STATUS_REJECT_ALREADY_EXISTS;
1328-
continue;
1329-
}
1330-
ref->forced_update = 1;
1331-
} else if (nonfastforward) {
1332-
if (!force_ref_update) {
1333-
ref->status = REF_STATUS_REJECT_NONFASTFORWARD;
1334-
continue;
1335-
}
1321+
int why = 0; /* why would this push require --force? */
1322+
1323+
if (!prefixcmp(ref->name, "refs/tags/"))
1324+
why = REF_STATUS_REJECT_ALREADY_EXISTS;
1325+
else if (!has_sha1_file(ref->old_sha1)
1326+
|| !ref_newer(ref->new_sha1, ref->old_sha1))
1327+
why = REF_STATUS_REJECT_NONFASTFORWARD;
1328+
1329+
if (!force_ref_update)
1330+
ref->status = why;
1331+
else if (why)
13361332
ref->forced_update = 1;
1337-
}
13381333
}
13391334
}
13401335
}

0 commit comments

Comments
 (0)