static void patch_parsed__free(git_patch *p) { git_patch_parsed *patch = (git_patch_parsed *)p; if (!patch) return; git_patch_parse_ctx_free(patch->ctx); git__free((char *)patch->base.binary.old_file.data); git__free((char *)patch->base.binary.new_file.data); git_array_clear(patch->base.hunks); git_array_clear(patch->base.lines); git__free(patch->base.delta); git__free(patch->old_prefix); git__free(patch->new_prefix); git__free(patch->header_old_path); git__free(patch->header_new_path); git__free(patch->rename_old_path); git__free(patch->rename_new_path); git__free(patch->old_path); git__free(patch->new_path); git__free(patch); }
int git_patch_from_buffer( git_patch **out, const char *content, size_t content_len, const git_patch_options *opts) { git_patch_parse_ctx *ctx; int error; ctx = git_patch_parse_ctx_init(content, content_len, opts); GITERR_CHECK_ALLOC(ctx); error = git_patch_parse(out, ctx); git_patch_parse_ctx_free(ctx); return error; }
int git_diff_from_buffer( git_diff **out, const char *content, size_t content_len) { git_diff_parsed *diff; git_patch *patch; git_patch_parse_ctx *ctx = NULL; int error = 0; *out = NULL; diff = diff_parsed_alloc(); GITERR_CHECK_ALLOC(diff); ctx = git_patch_parse_ctx_init(content, content_len, NULL); GITERR_CHECK_ALLOC(ctx); while (ctx->remain_len) { if ((error = git_patch_parse(&patch, ctx)) < 0) break; git_vector_insert(&diff->patches, patch); git_vector_insert(&diff->base.deltas, patch->delta); } if (error == GIT_ENOTFOUND && git_vector_length(&diff->patches) > 0) { giterr_clear(); error = 0; } git_patch_parse_ctx_free(ctx); if (error < 0) git_diff_free(&diff->base); else *out = &diff->base; return error; }