http-push: store refspecs in a struct refspec

Convert http-push.c to store refspecs in a 'struct refspec' instead of
in an array of 'const char *'.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Brandon Williams 2018-05-16 15:58:20 -07:00 committed by Junio C Hamano
parent 7a78a82b6c
commit 38490dd416

View File

@ -1692,8 +1692,7 @@ int cmd_main(int argc, const char **argv)
{ {
struct transfer_request *request; struct transfer_request *request;
struct transfer_request *next_request; struct transfer_request *next_request;
int nr_refspec = 0; struct refspec rs = REFSPEC_INIT_PUSH;
const char **refspec = NULL;
struct remote_lock *ref_lock = NULL; struct remote_lock *ref_lock = NULL;
struct remote_lock *info_ref_lock = NULL; struct remote_lock *info_ref_lock = NULL;
struct rev_info revs; struct rev_info revs;
@ -1756,8 +1755,7 @@ int cmd_main(int argc, const char **argv)
} }
continue; continue;
} }
refspec = argv; refspec_appendn(&rs, argv, argc - i);
nr_refspec = argc - i;
break; break;
} }
@ -1768,7 +1766,7 @@ int cmd_main(int argc, const char **argv)
if (!repo->url) if (!repo->url)
usage(http_push_usage); usage(http_push_usage);
if (delete_branch && nr_refspec != 1) if (delete_branch && rs.nr != 1)
die("You must specify only one branch name when deleting a remote branch"); die("You must specify only one branch name when deleting a remote branch");
setup_git_directory(); setup_git_directory();
@ -1814,18 +1812,19 @@ int cmd_main(int argc, const char **argv)
/* Remove a remote branch if -d or -D was specified */ /* Remove a remote branch if -d or -D was specified */
if (delete_branch) { if (delete_branch) {
if (delete_remote_branch(refspec[0], force_delete) == -1) { const char *branch = rs.items[i].src;
if (delete_remote_branch(branch, force_delete) == -1) {
fprintf(stderr, "Unable to delete remote branch %s\n", fprintf(stderr, "Unable to delete remote branch %s\n",
refspec[0]); branch);
if (helper_status) if (helper_status)
printf("error %s cannot remove\n", refspec[0]); printf("error %s cannot remove\n", branch);
} }
goto cleanup; goto cleanup;
} }
/* match them up */ /* match them up */
if (match_push_refs(local_refs, &remote_refs, if (match_push_refs(local_refs, &remote_refs,
nr_refspec, (const char **) refspec, push_all)) { rs.raw_nr, rs.raw, push_all)) {
rc = -1; rc = -1;
goto cleanup; goto cleanup;
} }