@@ -36,8 +36,7 @@ struct helper_data {
36
36
char * export_marks ;
37
37
char * import_marks ;
38
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 ;
41
40
/* Transport options for fetch-pack/send-pack (should one of
42
41
* those be invoked).
43
42
*/
@@ -107,9 +106,6 @@ static struct child_process *get_helper(struct transport *transport)
107
106
struct helper_data * data = transport -> data ;
108
107
struct strbuf buf = STRBUF_INIT ;
109
108
struct child_process * helper ;
110
- const char * * refspecs = NULL ;
111
- int refspec_nr = 0 ;
112
- int refspec_alloc = 0 ;
113
109
int duped ;
114
110
int code ;
115
111
@@ -139,6 +135,7 @@ static struct child_process *get_helper(struct transport *transport)
139
135
140
136
data -> helper = helper ;
141
137
data -> no_disconnect_req = 0 ;
138
+ refspec_init (& data -> rs , REFSPEC_FETCH );
142
139
143
140
/*
144
141
* Open the output as FILE* so strbuf_getline_*() family of
@@ -184,11 +181,8 @@ static struct child_process *get_helper(struct transport *transport)
184
181
data -> export = 1 ;
185
182
else if (!strcmp (capname , "check-connectivity" ))
186
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 );
192
186
} else if (!strcmp (capname , "connect" )) {
193
187
data -> connect = 1 ;
194
188
} else if (!strcmp (capname , "stateless-connect" )) {
@@ -207,14 +201,7 @@ static struct child_process *get_helper(struct transport *transport)
207
201
capname );
208
202
}
209
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 )) {
218
205
warning ("This remote helper should implement refspec capability." );
219
206
}
220
207
strbuf_release (& buf );
@@ -378,8 +365,7 @@ static int release_helper(struct transport *transport)
378
365
{
379
366
int res = 0 ;
380
367
struct helper_data * data = transport -> data ;
381
- free_refspec (data -> refspec_nr , data -> refspecs );
382
- data -> refspecs = NULL ;
368
+ refspec_clear (& data -> rs );
383
369
res = disconnect_helper (transport );
384
370
free (transport -> data );
385
371
return res ;
@@ -536,8 +522,8 @@ static int fetch_with_import(struct transport *transport,
536
522
if (posn -> status & REF_STATUS_UPTODATE )
537
523
continue ;
538
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 );
541
527
else
542
528
private = xstrdup (name );
543
529
if (private ) {
@@ -815,11 +801,11 @@ static int push_update_refs_status(struct helper_data *data,
815
801
if (push_update_ref_status (& buf , & ref , remote_refs ))
816
802
continue ;
817
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 )
819
805
continue ;
820
806
821
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 );
823
809
if (!private )
824
810
continue ;
825
811
update_ref ("update by helper" , private , & ref -> new_oid , NULL ,
@@ -939,7 +925,7 @@ static int push_refs_with_export(struct transport *transport,
939
925
struct string_list revlist_args = STRING_LIST_INIT_DUP ;
940
926
struct strbuf buf = STRBUF_INIT ;
941
927
942
- if (!data -> refspecs )
928
+ if (!data -> rs . nr )
943
929
die ("remote-helper doesn't support push; refspec needed" );
944
930
945
931
set_common_push_options (transport , data -> name , flags );
@@ -956,7 +942,7 @@ static int push_refs_with_export(struct transport *transport,
956
942
char * private ;
957
943
struct object_id oid ;
958
944
959
- private = apply_refspecs (data -> refspecs , data -> refspec_nr , ref -> name );
945
+ private = apply_refspecs (data -> rs . items , data -> rs . nr , ref -> name );
960
946
if (private && !get_oid (private , & oid )) {
961
947
strbuf_addf (& buf , "^%s" , private );
962
948
string_list_append_nodup (& revlist_args ,
0 commit comments