Skip to content

Commit 57f32ac

Browse files
bmwillgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9530350 commit 57f32ac

File tree

1 file changed

+12
-26
lines changed

1 file changed

+12
-26
lines changed

transport-helper.c

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ struct helper_data {
3636
char *export_marks;
3737
char *import_marks;
3838
/* These go from remote name (as in "list") to private name */
39-
struct refspec_item *refspecs;
40-
int refspec_nr;
39+
struct refspec rs;
4140
/* Transport options for fetch-pack/send-pack (should one of
4241
* those be invoked).
4342
*/
@@ -107,9 +106,6 @@ static struct child_process *get_helper(struct transport *transport)
107106
struct helper_data *data = transport->data;
108107
struct strbuf buf = STRBUF_INIT;
109108
struct child_process *helper;
110-
const char **refspecs = NULL;
111-
int refspec_nr = 0;
112-
int refspec_alloc = 0;
113109
int duped;
114110
int code;
115111

@@ -139,6 +135,7 @@ static struct child_process *get_helper(struct transport *transport)
139135

140136
data->helper = helper;
141137
data->no_disconnect_req = 0;
138+
refspec_init(&data->rs, REFSPEC_FETCH);
142139

143140
/*
144141
* Open the output as FILE* so strbuf_getline_*() family of
@@ -184,11 +181,8 @@ static struct child_process *get_helper(struct transport *transport)
184181
data->export = 1;
185182
else if (!strcmp(capname, "check-connectivity"))
186183
data->check_connectivity = 1;
187-
else if (!data->refspecs && skip_prefix(capname, "refspec ", &arg)) {
188-
ALLOC_GROW(refspecs,
189-
refspec_nr + 1,
190-
refspec_alloc);
191-
refspecs[refspec_nr++] = xstrdup(arg);
184+
else if (skip_prefix(capname, "refspec ", &arg)) {
185+
refspec_append(&data->rs, arg);
192186
} else if (!strcmp(capname, "connect")) {
193187
data->connect = 1;
194188
} else if (!strcmp(capname, "stateless-connect")) {
@@ -207,14 +201,7 @@ static struct child_process *get_helper(struct transport *transport)
207201
capname);
208202
}
209203
}
210-
if (refspecs) {
211-
int i;
212-
data->refspec_nr = refspec_nr;
213-
data->refspecs = parse_fetch_refspec(refspec_nr, refspecs);
214-
for (i = 0; i < refspec_nr; i++)
215-
free((char *)refspecs[i]);
216-
free(refspecs);
217-
} else if (data->import || data->bidi_import || data->export) {
204+
if (!data->rs.nr && (data->import || data->bidi_import || data->export)) {
218205
warning("This remote helper should implement refspec capability.");
219206
}
220207
strbuf_release(&buf);
@@ -378,8 +365,7 @@ static int release_helper(struct transport *transport)
378365
{
379366
int res = 0;
380367
struct helper_data *data = transport->data;
381-
free_refspec(data->refspec_nr, data->refspecs);
382-
data->refspecs = NULL;
368+
refspec_clear(&data->rs);
383369
res = disconnect_helper(transport);
384370
free(transport->data);
385371
return res;
@@ -536,8 +522,8 @@ static int fetch_with_import(struct transport *transport,
536522
if (posn->status & REF_STATUS_UPTODATE)
537523
continue;
538524
name = posn->symref ? posn->symref : posn->name;
539-
if (data->refspecs)
540-
private = apply_refspecs(data->refspecs, data->refspec_nr, name);
525+
if (data->rs.nr)
526+
private = apply_refspecs(data->rs.items, data->rs.nr, name);
541527
else
542528
private = xstrdup(name);
543529
if (private) {
@@ -815,11 +801,11 @@ static int push_update_refs_status(struct helper_data *data,
815801
if (push_update_ref_status(&buf, &ref, remote_refs))
816802
continue;
817803

818-
if (flags & TRANSPORT_PUSH_DRY_RUN || !data->refspecs || data->no_private_update)
804+
if (flags & TRANSPORT_PUSH_DRY_RUN || !data->rs.nr || data->no_private_update)
819805
continue;
820806

821807
/* propagate back the update to the remote namespace */
822-
private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
808+
private = apply_refspecs(data->rs.items, data->rs.nr, ref->name);
823809
if (!private)
824810
continue;
825811
update_ref("update by helper", private, &ref->new_oid, NULL,
@@ -939,7 +925,7 @@ static int push_refs_with_export(struct transport *transport,
939925
struct string_list revlist_args = STRING_LIST_INIT_DUP;
940926
struct strbuf buf = STRBUF_INIT;
941927

942-
if (!data->refspecs)
928+
if (!data->rs.nr)
943929
die("remote-helper doesn't support push; refspec needed");
944930

945931
set_common_push_options(transport, data->name, flags);
@@ -956,7 +942,7 @@ static int push_refs_with_export(struct transport *transport,
956942
char *private;
957943
struct object_id oid;
958944

959-
private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
945+
private = apply_refspecs(data->rs.items, data->rs.nr, ref->name);
960946
if (private && !get_oid(private, &oid)) {
961947
strbuf_addf(&buf, "^%s", private);
962948
string_list_append_nodup(&revlist_args,

0 commit comments

Comments
 (0)