transport: remove unnecessary indenting in transport_push()
Remove the big indented block for transport_push() check in transport vtable and let's just return error immediately. Hopefully this makes the code more readable. Signed-off-by: Frantisek Hrbata <frantisek@hrbata.com> Reviewed-by: Josh Steadmon <steadmon@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Frantisek Hrbata committed
May 20, 2022 at 14:49 UTC
6448182a831a5704601b7ad29afa1a26c40a4d53
1 file changed
+118
-116
transport.c
+118
-116
@@ -1276,146 +1276,148 @@ int transport_push(struct repository *r,
1276
struct refspec *rs, int flags,
1277
unsigned int *reject_reasons)
1278
{
1279
+ struct ref *remote_refs;
1280
+ struct ref *local_refs;
1281
+ int match_flags = MATCH_REFS_NONE;
1282
+ int verbose = (transport->verbose > 0);
1283
+ int quiet = (transport->verbose < 0);
1284
+ int porcelain = flags & TRANSPORT_PUSH_PORCELAIN;
1285
+ int pretend = flags & TRANSPORT_PUSH_DRY_RUN;
1286
+ int push_ret, ret, err;
1287
+ struct transport_ls_refs_options transport_options =
1288
+ TRANSPORT_LS_REFS_OPTIONS_INIT;
1289
+
1290
*reject_reasons = 0;
1291
1292
if (transport_color_config() < 0)
1293
return -1;
1294
1284
- if (transport->vtable->push_refs) {
1285
- struct ref *remote_refs;
1286
- struct ref *local_refs = get_local_heads();
1287
- int match_flags = MATCH_REFS_NONE;
1288
- int verbose = (transport->verbose > 0);
1289
- int quiet = (transport->verbose < 0);
1290
- int porcelain = flags & TRANSPORT_PUSH_PORCELAIN;
1291
- int pretend = flags & TRANSPORT_PUSH_DRY_RUN;
1292
- int push_ret, ret, err;
1293
- struct transport_ls_refs_options transport_options =
1294
- TRANSPORT_LS_REFS_OPTIONS_INIT;
1295
-
1296
- if (check_push_refs(local_refs, rs) < 0)
1297
- return -1;
1295
+ if (!transport->vtable->push_refs)
1296
+ return 1;
1297
1299
- refspec_ref_prefixes(rs, &transport_options.ref_prefixes);
1298
+ local_refs = get_local_heads();
1299
1301
- trace2_region_enter("transport_push", "get_refs_list", r);
1302
- remote_refs = transport->vtable->get_refs_list(transport, 1,
1303
- &transport_options);
1304
- trace2_region_leave("transport_push", "get_refs_list", r);
1300
+ if (check_push_refs(local_refs, rs) < 0)
1301
+ return -1;
1302
1306
- transport_ls_refs_options_release(&transport_options);
1303
+ refspec_ref_prefixes(rs, &transport_options.ref_prefixes);
1304
1308
- if (flags & TRANSPORT_PUSH_ALL)
1309
- match_flags |= MATCH_REFS_ALL;
1310
- if (flags & TRANSPORT_PUSH_MIRROR)
1311
- match_flags |= MATCH_REFS_MIRROR;
1312
- if (flags & TRANSPORT_PUSH_PRUNE)
1313
- match_flags |= MATCH_REFS_PRUNE;
1314
- if (flags & TRANSPORT_PUSH_FOLLOW_TAGS)
1315
- match_flags |= MATCH_REFS_FOLLOW_TAGS;
1305
+ trace2_region_enter("transport_push", "get_refs_list", r);
1306
+ remote_refs = transport->vtable->get_refs_list(transport, 1,
1307
+ &transport_options);
1308
+ trace2_region_leave("transport_push", "get_refs_list", r);
1309
1317
- if (match_push_refs(local_refs, &remote_refs, rs, match_flags))
1318
- return -1;
1310
+ transport_ls_refs_options_release(&transport_options);
1311
1320
- if (transport->smart_options &&
1321
- transport->smart_options->cas &&
1322
- !is_empty_cas(transport->smart_options->cas))
1323
- apply_push_cas(transport->smart_options->cas,
1324
- transport->remote, remote_refs);
1312
+ if (flags & TRANSPORT_PUSH_ALL)
1313
+ match_flags |= MATCH_REFS_ALL;
1314
+ if (flags & TRANSPORT_PUSH_MIRROR)
1315
+ match_flags |= MATCH_REFS_MIRROR;
1316
+ if (flags & TRANSPORT_PUSH_PRUNE)
1317
+ match_flags |= MATCH_REFS_PRUNE;
1318
+ if (flags & TRANSPORT_PUSH_FOLLOW_TAGS)
1319
+ match_flags |= MATCH_REFS_FOLLOW_TAGS;
1320
1326
- set_ref_status_for_push(remote_refs,
1327
- flags & TRANSPORT_PUSH_MIRROR,
1328
- flags & TRANSPORT_PUSH_FORCE);
1321
+ if (match_push_refs(local_refs, &remote_refs, rs, match_flags))
1322
+ return -1;
1323
1330
- if (!(flags & TRANSPORT_PUSH_NO_HOOK))
1331
- if (run_pre_push_hook(transport, remote_refs))
1332
- return -1;
1324
+ if (transport->smart_options &&
1325
+ transport->smart_options->cas &&
1326
+ !is_empty_cas(transport->smart_options->cas))
1327
+ apply_push_cas(transport->smart_options->cas,
1328
+ transport->remote, remote_refs);
1329
1334
- if ((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND |
1335
- TRANSPORT_RECURSE_SUBMODULES_ONLY)) &&
1336
- !is_bare_repository()) {
1337
- struct ref *ref = remote_refs;
1338
- struct oid_array commits = OID_ARRAY_INIT;
1339
-
1340
- trace2_region_enter("transport_push", "push_submodules", r);
1341
- for (; ref; ref = ref->next)
1342
- if (!is_null_oid(&ref->new_oid))
1343
- oid_array_append(&commits,
1344
- &ref->new_oid);
1345
-
1346
- if (!push_unpushed_submodules(r,
1347
- &commits,
1348
- transport->remote,
1349
- rs,
1350
- transport->push_options,
1351
- pretend)) {
1352
- oid_array_clear(&commits);
1353
- trace2_region_leave("transport_push", "push_submodules", r);
1354
- die(_("failed to push all needed submodules"));
1355
- }
1330
+ set_ref_status_for_push(remote_refs,
1331
+ flags & TRANSPORT_PUSH_MIRROR,
1332
+ flags & TRANSPORT_PUSH_FORCE);
1333
+
1334
+ if (!(flags & TRANSPORT_PUSH_NO_HOOK))
1335
+ if (run_pre_push_hook(transport, remote_refs))
1336
+ return -1;
1337
+
1338
+ if ((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND |
1339
+ TRANSPORT_RECURSE_SUBMODULES_ONLY)) &&
1340
+ !is_bare_repository()) {
1341
+ struct ref *ref = remote_refs;
1342
+ struct oid_array commits = OID_ARRAY_INIT;
1343
+
1344
+ trace2_region_enter("transport_push", "push_submodules", r);
1345
+ for (; ref; ref = ref->next)
1346
+ if (!is_null_oid(&ref->new_oid))
1347
+ oid_array_append(&commits,
1348
+ &ref->new_oid);
1349
+
1350
+ if (!push_unpushed_submodules(r,
1351
+ &commits,
1352
+ transport->remote,
1353
+ rs,
1354
+ transport->push_options,
1355
+ pretend)) {
1356
oid_array_clear(&commits);
1357
trace2_region_leave("transport_push", "push_submodules", r);
1358
+ die(_("failed to push all needed submodules"));
1359
}
1360
+ oid_array_clear(&commits);
1361
+ trace2_region_leave("transport_push", "push_submodules", r);
1362
+ }
1363
1360
- if (((flags & TRANSPORT_RECURSE_SUBMODULES_CHECK) ||
1361
- ((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND |
1362
- TRANSPORT_RECURSE_SUBMODULES_ONLY)) &&
1363
- !pretend)) && !is_bare_repository()) {
1364
- struct ref *ref = remote_refs;
1365
- struct string_list needs_pushing = STRING_LIST_INIT_DUP;
1366
- struct oid_array commits = OID_ARRAY_INIT;
1367
-
1368
- trace2_region_enter("transport_push", "check_submodules", r);
1369
- for (; ref; ref = ref->next)
1370
- if (!is_null_oid(&ref->new_oid))
1371
- oid_array_append(&commits,
1372
- &ref->new_oid);
1373
-
1374
- if (find_unpushed_submodules(r,
1375
- &commits,
1376
- transport->remote->name,
1377
- &needs_pushing)) {
1378
- oid_array_clear(&commits);
1379
- trace2_region_leave("transport_push", "check_submodules", r);
1380
- die_with_unpushed_submodules(&needs_pushing);
1381
- }
1382
- string_list_clear(&needs_pushing, 0);
1364
+ if (((flags & TRANSPORT_RECURSE_SUBMODULES_CHECK) ||
1365
+ ((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND |
1366
+ TRANSPORT_RECURSE_SUBMODULES_ONLY)) &&
1367
+ !pretend)) && !is_bare_repository()) {
1368
+ struct ref *ref = remote_refs;
1369
+ struct string_list needs_pushing = STRING_LIST_INIT_DUP;
1370
+ struct oid_array commits = OID_ARRAY_INIT;
1371
+
1372
+ trace2_region_enter("transport_push", "check_submodules", r);
1373
+ for (; ref; ref = ref->next)
1374
+ if (!is_null_oid(&ref->new_oid))
1375
+ oid_array_append(&commits,
1376
+ &ref->new_oid);
1377
+
1378
+ if (find_unpushed_submodules(r,
1379
+ &commits,
1380
+ transport->remote->name,
1381
+ &needs_pushing)) {
1382
oid_array_clear(&commits);
1383
trace2_region_leave("transport_push", "check_submodules", r);
1384
+ die_with_unpushed_submodules(&needs_pushing);
1385
}
1386
+ string_list_clear(&needs_pushing, 0);
1387
+ oid_array_clear(&commits);
1388
+ trace2_region_leave("transport_push", "check_submodules", r);
1389
+ }
1390
1387
- if (!(flags & TRANSPORT_RECURSE_SUBMODULES_ONLY)) {
1388
- trace2_region_enter("transport_push", "push_refs", r);
1389
- push_ret = transport->vtable->push_refs(transport, remote_refs, flags);
1390
- trace2_region_leave("transport_push", "push_refs", r);
1391
- } else
1392
- push_ret = 0;
1393
- err = push_had_errors(remote_refs);
1394
- ret = push_ret | err;
1395
-
1396
- if (!quiet || err)
1397
- transport_print_push_status(transport->url, remote_refs,
1398
- verbose | porcelain, porcelain,
1399
- reject_reasons);
1400
-
1401
- if (flags & TRANSPORT_PUSH_SET_UPSTREAM)
1402
- set_upstreams(transport, remote_refs, pretend);
1403
-
1404
- if (!(flags & (TRANSPORT_PUSH_DRY_RUN |
1405
- TRANSPORT_RECURSE_SUBMODULES_ONLY))) {
1406
- struct ref *ref;
1407
- for (ref = remote_refs; ref; ref = ref->next)
1408
- transport_update_tracking_ref(transport->remote, ref, verbose);
1409
- }
1391
+ if (!(flags & TRANSPORT_RECURSE_SUBMODULES_ONLY)) {
1392
+ trace2_region_enter("transport_push", "push_refs", r);
1393
+ push_ret = transport->vtable->push_refs(transport, remote_refs, flags);
1394
+ trace2_region_leave("transport_push", "push_refs", r);
1395
+ } else
1396
+ push_ret = 0;
1397
+ err = push_had_errors(remote_refs);
1398
+ ret = push_ret | err;
1399
+
1400
+ if (!quiet || err)
1401
+ transport_print_push_status(transport->url, remote_refs,
1402
+ verbose | porcelain, porcelain,
1403
+ reject_reasons);
1404
+
1405
+ if (flags & TRANSPORT_PUSH_SET_UPSTREAM)
1406
+ set_upstreams(transport, remote_refs, pretend);
1407
+
1408
+ if (!(flags & (TRANSPORT_PUSH_DRY_RUN |
1409
+ TRANSPORT_RECURSE_SUBMODULES_ONLY))) {
1410
+ struct ref *ref;
1411
+ for (ref = remote_refs; ref; ref = ref->next)
1412
+ transport_update_tracking_ref(transport->remote, ref, verbose);
1413
+ }
1414
1411
- if (porcelain && !push_ret)
1412
- puts("Done");
1413
- else if (!quiet && !ret && !transport_refs_pushed(remote_refs))
1414
- fprintf(stderr, "Everything up-to-date\n");
1415
+ if (porcelain && !push_ret)
1416
+ puts("Done");
1417
+ else if (!quiet && !ret && !transport_refs_pushed(remote_refs))
1418
+ fprintf(stderr, "Everything up-to-date\n");
1419
1416
- return ret;
1417
- }
1418
- return 1;
1420
+ return ret;
1421
}
1422
1423
const struct ref *transport_get_remote_refs(struct transport *transport,