transport-helper: convert to use struct refspec

Convert the refspecs in transport-helper.c to be stored in a
'struct refspec'.

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:03 -07:00 коммит произвёл Junio C Hamano
Родитель 9530350096
Коммит 57f32ac2a5
1 изменённых файлов: 12 добавлений и 26 удалений

Просмотреть файл

@ -36,8 +36,7 @@ struct helper_data {
char *export_marks; char *export_marks;
char *import_marks; char *import_marks;
/* These go from remote name (as in "list") to private name */ /* These go from remote name (as in "list") to private name */
struct refspec_item *refspecs; struct refspec rs;
int refspec_nr;
/* Transport options for fetch-pack/send-pack (should one of /* Transport options for fetch-pack/send-pack (should one of
* those be invoked). * those be invoked).
*/ */
@ -107,9 +106,6 @@ static struct child_process *get_helper(struct transport *transport)
struct helper_data *data = transport->data; struct helper_data *data = transport->data;
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
struct child_process *helper; struct child_process *helper;
const char **refspecs = NULL;
int refspec_nr = 0;
int refspec_alloc = 0;
int duped; int duped;
int code; int code;
@ -139,6 +135,7 @@ static struct child_process *get_helper(struct transport *transport)
data->helper = helper; data->helper = helper;
data->no_disconnect_req = 0; data->no_disconnect_req = 0;
refspec_init(&data->rs, REFSPEC_FETCH);
/* /*
* Open the output as FILE* so strbuf_getline_*() family of * Open the output as FILE* so strbuf_getline_*() family of
@ -184,11 +181,8 @@ static struct child_process *get_helper(struct transport *transport)
data->export = 1; data->export = 1;
else if (!strcmp(capname, "check-connectivity")) else if (!strcmp(capname, "check-connectivity"))
data->check_connectivity = 1; data->check_connectivity = 1;
else if (!data->refspecs && skip_prefix(capname, "refspec ", &arg)) { else if (skip_prefix(capname, "refspec ", &arg)) {
ALLOC_GROW(refspecs, refspec_append(&data->rs, arg);
refspec_nr + 1,
refspec_alloc);
refspecs[refspec_nr++] = xstrdup(arg);
} else if (!strcmp(capname, "connect")) { } else if (!strcmp(capname, "connect")) {
data->connect = 1; data->connect = 1;
} else if (!strcmp(capname, "stateless-connect")) { } else if (!strcmp(capname, "stateless-connect")) {
@ -207,14 +201,7 @@ static struct child_process *get_helper(struct transport *transport)
capname); capname);
} }
} }
if (refspecs) { if (!data->rs.nr && (data->import || data->bidi_import || data->export)) {
int i;
data->refspec_nr = refspec_nr;
data->refspecs = parse_fetch_refspec(refspec_nr, refspecs);
for (i = 0; i < refspec_nr; i++)
free((char *)refspecs[i]);
free(refspecs);
} else if (data->import || data->bidi_import || data->export) {
warning("This remote helper should implement refspec capability."); warning("This remote helper should implement refspec capability.");
} }
strbuf_release(&buf); strbuf_release(&buf);
@ -378,8 +365,7 @@ static int release_helper(struct transport *transport)
{ {
int res = 0; int res = 0;
struct helper_data *data = transport->data; struct helper_data *data = transport->data;
free_refspec(data->refspec_nr, data->refspecs); refspec_clear(&data->rs);
data->refspecs = NULL;
res = disconnect_helper(transport); res = disconnect_helper(transport);
free(transport->data); free(transport->data);
return res; return res;
@ -536,8 +522,8 @@ static int fetch_with_import(struct transport *transport,
if (posn->status & REF_STATUS_UPTODATE) if (posn->status & REF_STATUS_UPTODATE)
continue; continue;
name = posn->symref ? posn->symref : posn->name; name = posn->symref ? posn->symref : posn->name;
if (data->refspecs) if (data->rs.nr)
private = apply_refspecs(data->refspecs, data->refspec_nr, name); private = apply_refspecs(data->rs.items, data->rs.nr, name);
else else
private = xstrdup(name); private = xstrdup(name);
if (private) { if (private) {
@ -815,11 +801,11 @@ static int push_update_refs_status(struct helper_data *data,
if (push_update_ref_status(&buf, &ref, remote_refs)) if (push_update_ref_status(&buf, &ref, remote_refs))
continue; continue;
if (flags & TRANSPORT_PUSH_DRY_RUN || !data->refspecs || data->no_private_update) if (flags & TRANSPORT_PUSH_DRY_RUN || !data->rs.nr || data->no_private_update)
continue; continue;
/* propagate back the update to the remote namespace */ /* propagate back the update to the remote namespace */
private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name); private = apply_refspecs(data->rs.items, data->rs.nr, ref->name);
if (!private) if (!private)
continue; continue;
update_ref("update by helper", private, &ref->new_oid, NULL, update_ref("update by helper", private, &ref->new_oid, NULL,
@ -939,7 +925,7 @@ static int push_refs_with_export(struct transport *transport,
struct string_list revlist_args = STRING_LIST_INIT_DUP; struct string_list revlist_args = STRING_LIST_INIT_DUP;
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
if (!data->refspecs) if (!data->rs.nr)
die("remote-helper doesn't support push; refspec needed"); die("remote-helper doesn't support push; refspec needed");
set_common_push_options(transport, data->name, flags); set_common_push_options(transport, data->name, flags);
@ -956,7 +942,7 @@ static int push_refs_with_export(struct transport *transport,
char *private; char *private;
struct object_id oid; struct object_id oid;
private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name); private = apply_refspecs(data->rs.items, data->rs.nr, ref->name);
if (private && !get_oid(private, &oid)) { if (private && !get_oid(private, &oid)) {
strbuf_addf(&buf, "^%s", private); strbuf_addf(&buf, "^%s", private);
string_list_append_nodup(&revlist_args, string_list_append_nodup(&revlist_args,