зеркало из https://github.com/microsoft/git.git
Merge branch 'fh/transport-push-leakfix'
Leakfix. * fh/transport-push-leakfix: transport: free local and remote refs in transport_push() transport: unify return values and exit point from transport_push() transport: remove unnecessary indenting in transport_push()
This commit is contained in:
Коммит
07a454027b
234
transport.c
234
transport.c
|
@ -1276,146 +1276,152 @@ int transport_push(struct repository *r,
|
||||||
struct refspec *rs, int flags,
|
struct refspec *rs, int flags,
|
||||||
unsigned int *reject_reasons)
|
unsigned int *reject_reasons)
|
||||||
{
|
{
|
||||||
|
struct ref *remote_refs = NULL;
|
||||||
|
struct ref *local_refs = NULL;
|
||||||
|
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, err;
|
||||||
|
int ret = -1;
|
||||||
|
struct transport_ls_refs_options transport_options =
|
||||||
|
TRANSPORT_LS_REFS_OPTIONS_INIT;
|
||||||
|
|
||||||
*reject_reasons = 0;
|
*reject_reasons = 0;
|
||||||
|
|
||||||
if (transport_color_config() < 0)
|
if (transport_color_config() < 0)
|
||||||
return -1;
|
goto done;
|
||||||
|
|
||||||
if (transport->vtable->push_refs) {
|
if (!transport->vtable->push_refs)
|
||||||
struct ref *remote_refs;
|
goto done;
|
||||||
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)
|
local_refs = get_local_heads();
|
||||||
return -1;
|
|
||||||
|
|
||||||
refspec_ref_prefixes(rs, &transport_options.ref_prefixes);
|
if (check_push_refs(local_refs, rs) < 0)
|
||||||
|
goto done;
|
||||||
|
|
||||||
trace2_region_enter("transport_push", "get_refs_list", r);
|
refspec_ref_prefixes(rs, &transport_options.ref_prefixes);
|
||||||
remote_refs = transport->vtable->get_refs_list(transport, 1,
|
|
||||||
&transport_options);
|
|
||||||
trace2_region_leave("transport_push", "get_refs_list", r);
|
|
||||||
|
|
||||||
transport_ls_refs_options_release(&transport_options);
|
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 (flags & TRANSPORT_PUSH_ALL)
|
transport_ls_refs_options_release(&transport_options);
|
||||||
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;
|
|
||||||
|
|
||||||
if (match_push_refs(local_refs, &remote_refs, rs, match_flags))
|
if (flags & TRANSPORT_PUSH_ALL)
|
||||||
return -1;
|
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;
|
||||||
|
|
||||||
if (transport->smart_options &&
|
if (match_push_refs(local_refs, &remote_refs, rs, match_flags))
|
||||||
transport->smart_options->cas &&
|
goto done;
|
||||||
!is_empty_cas(transport->smart_options->cas))
|
|
||||||
apply_push_cas(transport->smart_options->cas,
|
|
||||||
transport->remote, remote_refs);
|
|
||||||
|
|
||||||
set_ref_status_for_push(remote_refs,
|
if (transport->smart_options &&
|
||||||
flags & TRANSPORT_PUSH_MIRROR,
|
transport->smart_options->cas &&
|
||||||
flags & TRANSPORT_PUSH_FORCE);
|
!is_empty_cas(transport->smart_options->cas))
|
||||||
|
apply_push_cas(transport->smart_options->cas,
|
||||||
|
transport->remote, remote_refs);
|
||||||
|
|
||||||
if (!(flags & TRANSPORT_PUSH_NO_HOOK))
|
set_ref_status_for_push(remote_refs,
|
||||||
if (run_pre_push_hook(transport, remote_refs))
|
flags & TRANSPORT_PUSH_MIRROR,
|
||||||
return -1;
|
flags & TRANSPORT_PUSH_FORCE);
|
||||||
|
|
||||||
if ((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND |
|
if (!(flags & TRANSPORT_PUSH_NO_HOOK))
|
||||||
TRANSPORT_RECURSE_SUBMODULES_ONLY)) &&
|
if (run_pre_push_hook(transport, remote_refs))
|
||||||
!is_bare_repository()) {
|
goto done;
|
||||||
struct ref *ref = remote_refs;
|
|
||||||
struct oid_array commits = OID_ARRAY_INIT;
|
|
||||||
|
|
||||||
trace2_region_enter("transport_push", "push_submodules", r);
|
if ((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND |
|
||||||
for (; ref; ref = ref->next)
|
TRANSPORT_RECURSE_SUBMODULES_ONLY)) &&
|
||||||
if (!is_null_oid(&ref->new_oid))
|
!is_bare_repository()) {
|
||||||
oid_array_append(&commits,
|
struct ref *ref = remote_refs;
|
||||||
&ref->new_oid);
|
struct oid_array commits = OID_ARRAY_INIT;
|
||||||
|
|
||||||
if (!push_unpushed_submodules(r,
|
trace2_region_enter("transport_push", "push_submodules", r);
|
||||||
&commits,
|
for (; ref; ref = ref->next)
|
||||||
transport->remote,
|
if (!is_null_oid(&ref->new_oid))
|
||||||
rs,
|
oid_array_append(&commits,
|
||||||
transport->push_options,
|
&ref->new_oid);
|
||||||
pretend)) {
|
|
||||||
oid_array_clear(&commits);
|
if (!push_unpushed_submodules(r,
|
||||||
trace2_region_leave("transport_push", "push_submodules", r);
|
&commits,
|
||||||
die(_("failed to push all needed submodules"));
|
transport->remote,
|
||||||
}
|
rs,
|
||||||
|
transport->push_options,
|
||||||
|
pretend)) {
|
||||||
oid_array_clear(&commits);
|
oid_array_clear(&commits);
|
||||||
trace2_region_leave("transport_push", "push_submodules", r);
|
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) ||
|
if (((flags & TRANSPORT_RECURSE_SUBMODULES_CHECK) ||
|
||||||
((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND |
|
((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND |
|
||||||
TRANSPORT_RECURSE_SUBMODULES_ONLY)) &&
|
TRANSPORT_RECURSE_SUBMODULES_ONLY)) &&
|
||||||
!pretend)) && !is_bare_repository()) {
|
!pretend)) && !is_bare_repository()) {
|
||||||
struct ref *ref = remote_refs;
|
struct ref *ref = remote_refs;
|
||||||
struct string_list needs_pushing = STRING_LIST_INIT_DUP;
|
struct string_list needs_pushing = STRING_LIST_INIT_DUP;
|
||||||
struct oid_array commits = OID_ARRAY_INIT;
|
struct oid_array commits = OID_ARRAY_INIT;
|
||||||
|
|
||||||
trace2_region_enter("transport_push", "check_submodules", r);
|
trace2_region_enter("transport_push", "check_submodules", r);
|
||||||
for (; ref; ref = ref->next)
|
for (; ref; ref = ref->next)
|
||||||
if (!is_null_oid(&ref->new_oid))
|
if (!is_null_oid(&ref->new_oid))
|
||||||
oid_array_append(&commits,
|
oid_array_append(&commits,
|
||||||
&ref->new_oid);
|
&ref->new_oid);
|
||||||
|
|
||||||
if (find_unpushed_submodules(r,
|
if (find_unpushed_submodules(r,
|
||||||
&commits,
|
&commits,
|
||||||
transport->remote->name,
|
transport->remote->name,
|
||||||
&needs_pushing)) {
|
&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);
|
oid_array_clear(&commits);
|
||||||
trace2_region_leave("transport_push", "check_submodules", r);
|
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_ONLY)) {
|
oid_array_clear(&commits);
|
||||||
trace2_region_enter("transport_push", "push_refs", r);
|
trace2_region_leave("transport_push", "check_submodules", 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");
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
return 1;
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
done:
|
||||||
|
free_refs(local_refs);
|
||||||
|
free_refs(remote_refs);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct ref *transport_get_remote_refs(struct transport *transport,
|
const struct ref *transport_get_remote_refs(struct transport *transport,
|
||||||
|
|
Загрузка…
Ссылка в новой задаче