Remove the big indented block for push_refs() check in transport vtable and let's just return error immediately. Hopefully this makes the code more readable. Signed-off-by: Frantisek Hrbata <frantisek@xxxxxxxxxx> --- Is there a reason to return 1 instead of -1 when push_refs() is not set in transport vtable? Looking at the code I think it might return -1 also and make it more consistent. transport.c | 234 ++++++++++++++++++++++++++-------------------------- 1 file changed, 118 insertions(+), 116 deletions(-) diff --git a/transport.c b/transport.c index 3d64a43ab3..0b9c5a427d 100644 --- a/transport.c +++ b/transport.c @@ -1276,146 +1276,148 @@ int transport_push(struct repository *r, struct refspec *rs, int flags, unsigned int *reject_reasons) { + struct ref *remote_refs; + struct ref *local_refs; + int match_flags = MATCH_REFS_NONE; + int verbose = (transport->verbose > 0); + int quiet = (transport->verbose < 0); + int porcelain = flags & TRANSPORT_PUSH_PORCELAIN; + int pretend = flags & TRANSPORT_PUSH_DRY_RUN; + int push_ret, ret, err; + struct transport_ls_refs_options transport_options = + TRANSPORT_LS_REFS_OPTIONS_INIT; + *reject_reasons = 0; if (transport_color_config() < 0) return -1; - if (transport->vtable->push_refs) { - struct ref *remote_refs; - struct ref *local_refs = get_local_heads(); - int match_flags = MATCH_REFS_NONE; - int verbose = (transport->verbose > 0); - int quiet = (transport->verbose < 0); - int porcelain = flags & TRANSPORT_PUSH_PORCELAIN; - int pretend = flags & TRANSPORT_PUSH_DRY_RUN; - int push_ret, ret, err; - struct transport_ls_refs_options transport_options = - TRANSPORT_LS_REFS_OPTIONS_INIT; - - if (check_push_refs(local_refs, rs) < 0) - return -1; + if (!transport->vtable->push_refs) + return 1; - refspec_ref_prefixes(rs, &transport_options.ref_prefixes); + local_refs = get_local_heads(); - trace2_region_enter("transport_push", "get_refs_list", r); - remote_refs = transport->vtable->get_refs_list(transport, 1, - &transport_options); - trace2_region_leave("transport_push", "get_refs_list", r); + if (check_push_refs(local_refs, rs) < 0) + return -1; - transport_ls_refs_options_release(&transport_options); + refspec_ref_prefixes(rs, &transport_options.ref_prefixes); - if (flags & TRANSPORT_PUSH_ALL) - match_flags |= MATCH_REFS_ALL; - if (flags & TRANSPORT_PUSH_MIRROR) - match_flags |= MATCH_REFS_MIRROR; - if (flags & TRANSPORT_PUSH_PRUNE) - match_flags |= MATCH_REFS_PRUNE; - if (flags & TRANSPORT_PUSH_FOLLOW_TAGS) - match_flags |= MATCH_REFS_FOLLOW_TAGS; + trace2_region_enter("transport_push", "get_refs_list", r); + remote_refs = transport->vtable->get_refs_list(transport, 1, + &transport_options); + trace2_region_leave("transport_push", "get_refs_list", r); - if (match_push_refs(local_refs, &remote_refs, rs, match_flags)) - return -1; + transport_ls_refs_options_release(&transport_options); - if (transport->smart_options && - transport->smart_options->cas && - !is_empty_cas(transport->smart_options->cas)) - apply_push_cas(transport->smart_options->cas, - transport->remote, remote_refs); + if (flags & TRANSPORT_PUSH_ALL) + match_flags |= MATCH_REFS_ALL; + if (flags & TRANSPORT_PUSH_MIRROR) + match_flags |= MATCH_REFS_MIRROR; + if (flags & TRANSPORT_PUSH_PRUNE) + match_flags |= MATCH_REFS_PRUNE; + if (flags & TRANSPORT_PUSH_FOLLOW_TAGS) + match_flags |= MATCH_REFS_FOLLOW_TAGS; - set_ref_status_for_push(remote_refs, - flags & TRANSPORT_PUSH_MIRROR, - flags & TRANSPORT_PUSH_FORCE); + if (match_push_refs(local_refs, &remote_refs, rs, match_flags)) + return -1; - if (!(flags & TRANSPORT_PUSH_NO_HOOK)) - if (run_pre_push_hook(transport, remote_refs)) - return -1; + if (transport->smart_options && + transport->smart_options->cas && + !is_empty_cas(transport->smart_options->cas)) + apply_push_cas(transport->smart_options->cas, + transport->remote, remote_refs); - if ((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND | - TRANSPORT_RECURSE_SUBMODULES_ONLY)) && - !is_bare_repository()) { - struct ref *ref = remote_refs; - struct oid_array commits = OID_ARRAY_INIT; - - trace2_region_enter("transport_push", "push_submodules", r); - for (; ref; ref = ref->next) - if (!is_null_oid(&ref->new_oid)) - oid_array_append(&commits, - &ref->new_oid); - - if (!push_unpushed_submodules(r, - &commits, - transport->remote, - rs, - transport->push_options, - pretend)) { - oid_array_clear(&commits); - trace2_region_leave("transport_push", "push_submodules", r); - die(_("failed to push all needed submodules")); - } + set_ref_status_for_push(remote_refs, + flags & TRANSPORT_PUSH_MIRROR, + flags & TRANSPORT_PUSH_FORCE); + + if (!(flags & TRANSPORT_PUSH_NO_HOOK)) + if (run_pre_push_hook(transport, remote_refs)) + return -1; + + if ((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND | + TRANSPORT_RECURSE_SUBMODULES_ONLY)) && + !is_bare_repository()) { + struct ref *ref = remote_refs; + struct oid_array commits = OID_ARRAY_INIT; + + trace2_region_enter("transport_push", "push_submodules", r); + for (; ref; ref = ref->next) + if (!is_null_oid(&ref->new_oid)) + oid_array_append(&commits, + &ref->new_oid); + + if (!push_unpushed_submodules(r, + &commits, + transport->remote, + rs, + transport->push_options, + pretend)) { oid_array_clear(&commits); trace2_region_leave("transport_push", "push_submodules", r); + die(_("failed to push all needed submodules")); } + oid_array_clear(&commits); + trace2_region_leave("transport_push", "push_submodules", r); + } - if (((flags & TRANSPORT_RECURSE_SUBMODULES_CHECK) || - ((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND | - TRANSPORT_RECURSE_SUBMODULES_ONLY)) && - !pretend)) && !is_bare_repository()) { - struct ref *ref = remote_refs; - struct string_list needs_pushing = STRING_LIST_INIT_DUP; - struct oid_array commits = OID_ARRAY_INIT; - - trace2_region_enter("transport_push", "check_submodules", r); - for (; ref; ref = ref->next) - if (!is_null_oid(&ref->new_oid)) - oid_array_append(&commits, - &ref->new_oid); - - if (find_unpushed_submodules(r, - &commits, - transport->remote->name, - &needs_pushing)) { - oid_array_clear(&commits); - trace2_region_leave("transport_push", "check_submodules", r); - die_with_unpushed_submodules(&needs_pushing); - } - string_list_clear(&needs_pushing, 0); + if (((flags & TRANSPORT_RECURSE_SUBMODULES_CHECK) || + ((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND | + TRANSPORT_RECURSE_SUBMODULES_ONLY)) && + !pretend)) && !is_bare_repository()) { + struct ref *ref = remote_refs; + struct string_list needs_pushing = STRING_LIST_INIT_DUP; + struct oid_array commits = OID_ARRAY_INIT; + + trace2_region_enter("transport_push", "check_submodules", r); + for (; ref; ref = ref->next) + if (!is_null_oid(&ref->new_oid)) + oid_array_append(&commits, + &ref->new_oid); + + if (find_unpushed_submodules(r, + &commits, + transport->remote->name, + &needs_pushing)) { oid_array_clear(&commits); trace2_region_leave("transport_push", "check_submodules", r); + die_with_unpushed_submodules(&needs_pushing); } + string_list_clear(&needs_pushing, 0); + oid_array_clear(&commits); + trace2_region_leave("transport_push", "check_submodules", r); + } - if (!(flags & TRANSPORT_RECURSE_SUBMODULES_ONLY)) { - trace2_region_enter("transport_push", "push_refs", r); - push_ret = transport->vtable->push_refs(transport, remote_refs, flags); - trace2_region_leave("transport_push", "push_refs", r); - } else - push_ret = 0; - err = push_had_errors(remote_refs); - ret = push_ret | err; - - if (!quiet || err) - transport_print_push_status(transport->url, remote_refs, - verbose | porcelain, porcelain, - reject_reasons); - - if (flags & TRANSPORT_PUSH_SET_UPSTREAM) - set_upstreams(transport, remote_refs, pretend); - - if (!(flags & (TRANSPORT_PUSH_DRY_RUN | - TRANSPORT_RECURSE_SUBMODULES_ONLY))) { - struct ref *ref; - for (ref = remote_refs; ref; ref = ref->next) - transport_update_tracking_ref(transport->remote, ref, verbose); - } + if (!(flags & TRANSPORT_RECURSE_SUBMODULES_ONLY)) { + trace2_region_enter("transport_push", "push_refs", r); + push_ret = transport->vtable->push_refs(transport, remote_refs, flags); + trace2_region_leave("transport_push", "push_refs", r); + } else + push_ret = 0; + err = push_had_errors(remote_refs); + ret = push_ret | err; + + if (!quiet || err) + transport_print_push_status(transport->url, remote_refs, + verbose | porcelain, porcelain, + reject_reasons); + + if (flags & TRANSPORT_PUSH_SET_UPSTREAM) + set_upstreams(transport, remote_refs, pretend); + + if (!(flags & (TRANSPORT_PUSH_DRY_RUN | + TRANSPORT_RECURSE_SUBMODULES_ONLY))) { + struct ref *ref; + for (ref = remote_refs; ref; ref = ref->next) + transport_update_tracking_ref(transport->remote, ref, verbose); + } - if (porcelain && !push_ret) - puts("Done"); - else if (!quiet && !ret && !transport_refs_pushed(remote_refs)) - fprintf(stderr, "Everything up-to-date\n"); + if (porcelain && !push_ret) + puts("Done"); + else if (!quiet && !ret && !transport_refs_pushed(remote_refs)) + fprintf(stderr, "Everything up-to-date\n"); - return ret; - } - return 1; + return ret; } const struct ref *transport_get_remote_refs(struct transport *transport, -- 2.35.1