@@ -119,37 +119,34 @@ int git_grafts_refresh(git_grafts *grafts)
119119 return error ;
120120}
121121
122- int git_grafts_parse (git_grafts * grafts , const char * content , size_t contentlen )
122+ int git_grafts_parse (git_grafts * grafts , const char * buf , size_t len )
123123{
124124 git_array_oid_t parents = GIT_ARRAY_INIT ;
125125 git_parse_ctx parser ;
126126 int error ;
127127
128128 git_grafts_clear (grafts );
129129
130- if ((error = git_parse_ctx_init (& parser , content , contentlen )) < 0 )
130+ if ((error = git_parse_ctx_init (& parser , buf , len )) < 0 )
131131 goto error ;
132132
133133 for (; parser .remain_len ; git_parse_advance_line (& parser )) {
134- const char * line_start = parser .line , * line_end = parser .line + parser .line_len ;
135134 git_oid graft_oid ;
136135
137- if ((error = git_oid__fromstrn (& graft_oid , line_start , GIT_OID_SHA1_HEXSIZE , GIT_OID_SHA1 )) < 0 ) {
136+ if ((error = git_parse_advance_oid (& graft_oid , & parser , GIT_OID_SHA1 )) < 0 ) {
138137 git_error_set (GIT_ERROR_GRAFTS , "invalid graft OID at line %" PRIuZ , parser .line_num );
139138 goto error ;
140139 }
141- line_start += GIT_OID_SHA1_HEXSIZE ;
142140
143- while (line_start < line_end && * line_start == ' ' ) {
141+ while (parser . line_len && git_parse_advance_expected ( & parser , "\n" , 1 ) != 0 ) {
144142 git_oid * id = git_array_alloc (parents );
145143 GIT_ERROR_CHECK_ALLOC (id );
146144
147- if ((error = git_oid__fromstrn (id , ++ line_start , GIT_OID_SHA1_HEXSIZE , GIT_OID_SHA1 )) < 0 ) {
145+ if ((error = git_parse_advance_expected (& parser , " " , 1 )) < 0 ||
146+ (error = git_parse_advance_oid (id , & parser , GIT_OID_SHA1 )) < 0 ) {
148147 git_error_set (GIT_ERROR_GRAFTS , "invalid parent OID at line %" PRIuZ , parser .line_num );
149148 goto error ;
150149 }
151-
152- line_start += GIT_OID_SHA1_HEXSIZE ;
153150 }
154151
155152 if ((error = git_grafts_add (grafts , & graft_oid , parents )) < 0 )
@@ -186,6 +183,7 @@ int git_grafts_add(git_grafts *grafts, const git_oid *oid, git_array_oid_t paren
186183
187184 if ((error = git_grafts_remove (grafts , & graft -> oid )) < 0 && error != GIT_ENOTFOUND )
188185 goto cleanup ;
186+
189187 if ((error = git_oidmap_set (grafts -> commits , & graft -> oid , graft )) < 0 )
190188 goto cleanup ;
191189
0 commit comments