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>
Brandon Williams committed
May 16, 2018 at 15:58 UTC
57f32ac2a583b3d9acde9c3d758610e6c881749f
1 file changed
+12
-26
transport-helper.c
+12
-26
@@ -36,8 +36,7 @@ struct helper_data {
36
char *export_marks;
37
char *import_marks;
38
/* These go from remote name (as in "list") to private name */
39
- struct refspec_item *refspecs;
40
- int refspec_nr;
39
+ struct refspec rs;
40
/* Transport options for fetch-pack/send-pack (should one of
41
* those be invoked).
42
*/
@@ -107,9 +106,6 @@ static struct child_process *get_helper(struct transport *transport)
106
struct helper_data *data = transport->data;
107
struct strbuf buf = STRBUF_INIT;
108
struct child_process *helper;
110
- const char **refspecs = NULL;
111
- int refspec_nr = 0;
112
- int refspec_alloc = 0;
109
int duped;
110
int code;
111
@@ -139,6 +135,7 @@ static struct child_process *get_helper(struct transport *transport)
135
136
data->helper = helper;
137
data->no_disconnect_req = 0;
138
+ refspec_init(&data->rs, REFSPEC_FETCH);
139
140
/*
141
* Open the output as FILE* so strbuf_getline_*() family of
@@ -184,11 +181,8 @@ static struct child_process *get_helper(struct transport *transport)
181
data->export = 1;
182
else if (!strcmp(capname, "check-connectivity"))
183
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);
186
} else if (!strcmp(capname, "connect")) {
187
data->connect = 1;
188
} else if (!strcmp(capname, "stateless-connect")) {
@@ -207,14 +201,7 @@ static struct child_process *get_helper(struct transport *transport)
201
capname);
202
}
203
}
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)) {
205
warning("This remote helper should implement refspec capability.");
206
}
207
strbuf_release(&buf);
@@ -378,8 +365,7 @@ static int release_helper(struct transport *transport)
365
{
366
int res = 0;
367
struct helper_data *data = transport->data;
381
- free_refspec(data->refspec_nr, data->refspecs);
382
- data->refspecs = NULL;
368
+ refspec_clear(&data->rs);
369
res = disconnect_helper(transport);
370
free(transport->data);
371
return res;
@@ -536,8 +522,8 @@ static int fetch_with_import(struct transport *transport,
522
if (posn->status & REF_STATUS_UPTODATE)
523
continue;
524
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);
527
else
528
private = xstrdup(name);
529
if (private) {
@@ -815,11 +801,11 @@ static int push_update_refs_status(struct helper_data *data,
801
if (push_update_ref_status(&buf, &ref, remote_refs))
802
continue;
803
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)
805
continue;
806
807
/* 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);
809
if (!private)
810
continue;
811
update_ref("update by helper", private, &ref->new_oid, NULL,
@@ -939,7 +925,7 @@ static int push_refs_with_export(struct transport *transport,
925
struct string_list revlist_args = STRING_LIST_INIT_DUP;
926
struct strbuf buf = STRBUF_INIT;
927
942
- if (!data->refspecs)
928
+ if (!data->rs.nr)
929
die("remote-helper doesn't support push; refspec needed");
930
931
set_common_push_options(transport, data->name, flags);
@@ -956,7 +942,7 @@ static int push_refs_with_export(struct transport *transport,
942
char *private;
943
struct object_id oid;
944
959
- private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
945
+ private = apply_refspecs(data->rs.items, data->rs.nr, ref->name);
946
if (private && !get_oid(private, &oid)) {
947
strbuf_addf(&buf, "^%s", private);
948
string_list_append_nodup(&revlist_args,