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; }