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 <gitster@pobox.com>
Junio C Hamano committed
Jan 23, 2013 at 13:14 UTC
0f4d498dbecbc1b6da66f926df3bc12446bd44dd
1 file changed
+11
-16
remote.c
+11
-16
@@ -1318,23 +1318,18 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
1318
*/
1319
1320
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)
1332
ref->forced_update = 1;
1337
- }
1333
}
1334
}
1335
}