@@ -19,7 +19,7 @@ static int push_spec_rref_cmp(const void *a, const void *b)
19
19
{
20
20
const push_spec * push_spec_a = a , * push_spec_b = b ;
21
21
22
- return strcmp (push_spec_a -> rref , push_spec_b -> rref );
22
+ return strcmp (push_spec_a -> refspec . dst , push_spec_b -> refspec . dst );
23
23
}
24
24
25
25
static int push_status_ref_cmp (const void * a , const void * b )
@@ -94,12 +94,7 @@ static void free_refspec(push_spec *spec)
94
94
if (spec == NULL )
95
95
return ;
96
96
97
- if (spec -> lref )
98
- git__free (spec -> lref );
99
-
100
- if (spec -> rref )
101
- git__free (spec -> rref );
102
-
97
+ git_refspec__free (& spec -> refspec );
103
98
git__free (spec );
104
99
}
105
100
@@ -134,47 +129,25 @@ static int check_lref(git_push *push, char *ref)
134
129
static int parse_refspec (git_push * push , push_spec * * spec , const char * str )
135
130
{
136
131
push_spec * s ;
137
- char * delim ;
138
132
139
133
* spec = NULL ;
140
134
141
135
s = git__calloc (1 , sizeof (* s ));
142
136
GITERR_CHECK_ALLOC (s );
143
137
144
- if (str [ 0 ] == '+' ) {
145
- s -> force = true ;
146
- str ++ ;
138
+ if (git_refspec__parse ( & s -> refspec , str , false) < 0 ) {
139
+ giterr_set ( GITERR_INVALID , "invalid refspec %s" , str ) ;
140
+ goto on_error ;
147
141
}
148
142
149
- delim = strchr (str , ':' );
150
- if (delim == NULL ) {
151
- s -> lref = git__strdup (str );
152
- if (!s -> lref || check_lref (push , s -> lref ) < 0 )
153
- goto on_error ;
154
- } else {
155
- if (delim - str ) {
156
- s -> lref = git__strndup (str , delim - str );
157
- if (!s -> lref || check_lref (push , s -> lref ) < 0 )
158
- goto on_error ;
159
- }
160
-
161
- if (strlen (delim + 1 )) {
162
- s -> rref = git__strdup (delim + 1 );
163
- if (!s -> rref || check_rref (s -> rref ) < 0 )
164
- goto on_error ;
165
- }
143
+ if (s -> refspec .src && s -> refspec .src [0 ] != '\0' &&
144
+ check_lref (push , s -> refspec .src ) < 0 ) {
145
+ goto on_error ;
166
146
}
167
147
168
- if (! s -> lref && ! s -> rref )
148
+ if (check_rref ( s -> refspec . dst ) < 0 )
169
149
goto on_error ;
170
150
171
- /* If rref is ommitted, use the same ref name as lref */
172
- if (!s -> rref ) {
173
- s -> rref = git__strdup (s -> lref );
174
- if (!s -> rref || check_rref (s -> rref ) < 0 )
175
- goto on_error ;
176
- }
177
-
178
151
* spec = s ;
179
152
return 0 ;
180
153
@@ -220,7 +193,7 @@ int git_push_update_tips(
220
193
221
194
/* Find matching push ref spec */
222
195
git_vector_foreach (& push -> specs , j , push_spec ) {
223
- if (!strcmp (push_spec -> rref , status -> ref ))
196
+ if (!strcmp (push_spec -> refspec . dst , status -> ref ))
224
197
break ;
225
198
}
226
199
@@ -353,7 +326,7 @@ static int revwalk(git_vector *commits, git_push *push)
353
326
} else if (git_revwalk_push (rw , & spec -> loid ) < 0 )
354
327
goto on_error ;
355
328
356
- if (!spec -> force ) {
329
+ if (!spec -> refspec . force ) {
357
330
git_oid base ;
358
331
359
332
if (git_oid_iszero (& spec -> roid ))
@@ -571,22 +544,20 @@ static int calculate_work(git_push *push)
571
544
/* Update local and remote oids*/
572
545
573
546
git_vector_foreach (& push -> specs , i , spec ) {
574
- if (spec -> lref ) {
547
+ if (spec -> refspec . src && spec -> refspec . src [ 0 ] != '\0' ) {
575
548
/* This is a create or update. Local ref must exist. */
576
549
if (git_reference_name_to_id (
577
- & spec -> loid , push -> repo , spec -> lref ) < 0 ) {
578
- giterr_set (GITERR_REFERENCE , "No such reference '%s'" , spec -> lref );
550
+ & spec -> loid , push -> repo , spec -> refspec . src ) < 0 ) {
551
+ giterr_set (GITERR_REFERENCE , "No such reference '%s'" , spec -> refspec . src );
579
552
return -1 ;
580
553
}
581
554
}
582
555
583
- if (spec -> rref ) {
584
- /* Remote ref may or may not (e.g. during create) already exist. */
585
- git_vector_foreach (& push -> remote -> refs , j , head ) {
586
- if (!strcmp (spec -> rref , head -> name )) {
587
- git_oid_cpy (& spec -> roid , & head -> oid );
588
- break ;
589
- }
556
+ /* Remote ref may or may not (e.g. during create) already exist. */
557
+ git_vector_foreach (& push -> remote -> refs , j , head ) {
558
+ if (!strcmp (spec -> refspec .dst , head -> name )) {
559
+ git_oid_cpy (& spec -> roid , & head -> oid );
560
+ break ;
590
561
}
591
562
}
592
563
}
0 commit comments