File tree Expand file tree Collapse file tree 3 files changed +54
-0
lines changed
Expand file tree Collapse file tree 3 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 2121 */
2222GIT_BEGIN_DECL
2323
24+ /**
25+ * Parse a given refspec string
26+ *
27+ * @param refspec a pointer to hold the refspec handle
28+ * @param input the refspec string
29+ * @param is_fetch is this a refspec for a fetch
30+ * @return 0 if the refspec string could be parsed, -1 otherwise
31+ */
32+ GIT_EXTERN (int ) git_refspec_parse (git_refspec * * refspec , const char * input , int is_fetch );
33+
34+ /**
35+ * Free a refspec object which has been created by git_refspec_parse
36+ *
37+ * @param refspec the refspec object
38+ */
39+ GIT_EXTERN (void ) git_refspec_free (git_refspec * refspec );
40+
2441/**
2542 * Get the source specifier
2643 *
Original file line number Diff line number Diff line change @@ -160,6 +160,31 @@ void git_refspec__free(git_refspec *refspec)
160160 memset (refspec , 0x0 , sizeof (git_refspec ));
161161}
162162
163+ int git_refspec_parse (git_refspec * * out_refspec , const char * input , int is_fetch )
164+ {
165+ git_refspec * refspec ;
166+ assert (out_refspec && input );
167+
168+ * out_refspec = NULL ;
169+
170+ refspec = git__malloc (sizeof (git_refspec ));
171+ GITERR_CHECK_ALLOC (refspec );
172+
173+ if (git_refspec__parse (refspec , input , !!is_fetch ) != 0 ) {
174+ git__free (refspec );
175+ return -1 ;
176+ }
177+
178+ * out_refspec = refspec ;
179+ return 0 ;
180+ }
181+
182+ void git_refspec_free (git_refspec * refspec )
183+ {
184+ git_refspec__free (refspec );
185+ git__free (refspec );
186+ }
187+
163188const char * git_refspec_src (const git_refspec * refspec )
164189{
165190 return refspec == NULL ? NULL : refspec -> src ;
Original file line number Diff line number Diff line change @@ -158,3 +158,15 @@ void test_network_refspecs__matching(void)
158158
159159 git_refspec__free (& spec );
160160}
161+
162+ void test_network_refspecs__parse_free (void )
163+ {
164+ git_refspec * spec = NULL ;
165+
166+ cl_git_fail (git_refspec_parse (& spec , "" , 0 ));
167+ cl_git_fail (git_refspec_parse (& spec , ":::" , 0 ));
168+ cl_git_pass (git_refspec_parse (& spec , "HEAD:" , 1 ));
169+
170+ cl_assert (spec != NULL );
171+ git_refspec_free (spec );
172+ }
You can’t perform that action at this time.
0 commit comments