@@ -77,14 +77,6 @@ static const char *alias_url(const char *url, struct rewrites *r)
77
77
return xstrfmt ("%s%s" , r -> rewrite [longest_i ]-> base , url + longest -> len );
78
78
}
79
79
80
- static void add_push_refspec (struct remote * remote , const char * ref )
81
- {
82
- ALLOC_GROW (remote -> push_refspec ,
83
- remote -> push_refspec_nr + 1 ,
84
- remote -> push_refspec_alloc );
85
- remote -> push_refspec [remote -> push_refspec_nr ++ ] = ref ;
86
- }
87
-
88
80
static void add_fetch_refspec (struct remote * remote , const char * ref )
89
81
{
90
82
ALLOC_GROW (remote -> fetch_refspec ,
@@ -175,9 +167,11 @@ static struct remote *make_remote(const char *name, int len)
175
167
ret = xcalloc (1 , sizeof (struct remote ));
176
168
ret -> prune = -1 ; /* unspecified */
177
169
ret -> prune_tags = -1 ; /* unspecified */
170
+ ret -> name = xstrndup (name , len );
171
+ refspec_init (& ret -> push , REFSPEC_PUSH );
172
+
178
173
ALLOC_GROW (remotes , remotes_nr + 1 , remotes_alloc );
179
174
remotes [remotes_nr ++ ] = ret ;
180
- ret -> name = xstrndup (name , len );
181
175
182
176
hashmap_entry_init (ret , lookup_entry .hash );
183
177
replaced = hashmap_put (& remotes_hash , ret );
@@ -275,7 +269,7 @@ static void read_remotes_file(struct remote *remote)
275
269
if (skip_prefix (buf .buf , "URL:" , & v ))
276
270
add_url_alias (remote , xstrdup (skip_spaces (v )));
277
271
else if (skip_prefix (buf .buf , "Push:" , & v ))
278
- add_push_refspec ( remote , xstrdup ( skip_spaces (v ) ));
272
+ refspec_append ( & remote -> push , skip_spaces (v ));
279
273
else if (skip_prefix (buf .buf , "Pull:" , & v ))
280
274
add_fetch_refspec (remote , xstrdup (skip_spaces (v )));
281
275
}
@@ -323,8 +317,10 @@ static void read_branches_file(struct remote *remote)
323
317
* Cogito compatible push: push current HEAD to remote #branch
324
318
* (master if missing)
325
319
*/
326
- add_push_refspec (remote , xstrfmt ("HEAD:refs/heads/%s" , frag ));
320
+ strbuf_addf (& buf , "HEAD:refs/heads/%s" , frag );
321
+ refspec_append (& remote -> push , buf .buf );
327
322
remote -> fetch_tags = 1 ; /* always auto-follow */
323
+ strbuf_release (& buf );
328
324
}
329
325
330
326
static int handle_config (const char * key , const char * value , void * cb )
@@ -409,7 +405,8 @@ static int handle_config(const char *key, const char *value, void *cb)
409
405
const char * v ;
410
406
if (git_config_string (& v , key , value ))
411
407
return -1 ;
412
- add_push_refspec (remote , v );
408
+ refspec_append (& remote -> push , v );
409
+ free ((char * )v );
413
410
} else if (!strcmp (subkey , "fetch" )) {
414
411
const char * v ;
415
412
if (git_config_string (& v , key , value ))
@@ -542,9 +539,9 @@ const char *remote_ref_for_branch(struct branch *branch, int for_push,
542
539
pushremote_for_branch (branch , NULL );
543
540
struct remote * remote = remote_get (remote_name );
544
541
545
- if (remote && remote -> push_refspec_nr &&
546
- (dst = apply_refspecs (remote -> push ,
547
- remote -> push_refspec_nr ,
542
+ if (remote && remote -> push . nr &&
543
+ (dst = apply_refspecs (remote -> push . items ,
544
+ remote -> push . nr ,
548
545
branch -> refname ))) {
549
546
if (explicit )
550
547
* explicit = 1 ;
@@ -582,7 +579,6 @@ static struct remote *remote_get_1(const char *name,
582
579
if (!valid_remote (ret ))
583
580
return NULL ;
584
581
ret -> fetch = parse_fetch_refspec (ret -> fetch_refspec_nr , ret -> fetch_refspec );
585
- ret -> push = parse_push_refspec (ret -> push_refspec_nr , ret -> push_refspec );
586
582
return ret ;
587
583
}
588
584
@@ -616,9 +612,6 @@ int for_each_remote(each_remote_fn fn, void *priv)
616
612
if (!r -> fetch )
617
613
r -> fetch = parse_fetch_refspec (r -> fetch_refspec_nr ,
618
614
r -> fetch_refspec );
619
- if (!r -> push )
620
- r -> push = parse_push_refspec (r -> push_refspec_nr ,
621
- r -> push_refspec );
622
615
result = fn (r , priv );
623
616
}
624
617
return result ;
@@ -1613,11 +1606,11 @@ static const char *branch_get_push_1(struct branch *branch, struct strbuf *err)
1613
1606
_ ("branch '%s' has no remote for pushing" ),
1614
1607
branch -> name );
1615
1608
1616
- if (remote -> push_refspec_nr ) {
1609
+ if (remote -> push . nr ) {
1617
1610
char * dst ;
1618
1611
const char * ret ;
1619
1612
1620
- dst = apply_refspecs (remote -> push , remote -> push_refspec_nr ,
1613
+ dst = apply_refspecs (remote -> push . items , remote -> push . nr ,
1621
1614
branch -> refname );
1622
1615
if (!dst )
1623
1616
return error_buf (err ,
0 commit comments