summaryrefslogtreecommitdiff
path: root/src/libgit2/diff_parse.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2023-04-22 23:12:00 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2023-04-22 23:17:32 +0100
commit190a4c55df72b32adf4d60f77cbc47276b74f84b (patch)
tree896d6d41c2ea6305992bd646bbbe79a3fdb5f6fe /src/libgit2/diff_parse.c
parente288f874a3a73ef31f88bb524f6d25d5ff3c5a3a (diff)
parent8a62616f43fe5ea37d41296f40293ff97aa88cfa (diff)
downloadlibgit2-190a4c55df72b32adf4d60f77cbc47276b74f84b.tar.gz
Merge remote-tracking branch 'origin/main' into shallow-clone-network
Diffstat (limited to 'src/libgit2/diff_parse.c')
-rw-r--r--src/libgit2/diff_parse.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/libgit2/diff_parse.c b/src/libgit2/diff_parse.c
index 75e41a544..04603969e 100644
--- a/src/libgit2/diff_parse.c
+++ b/src/libgit2/diff_parse.c
@@ -29,7 +29,7 @@ static void diff_parsed_free(git_diff *d)
git__free(diff);
}
-static git_diff_parsed *diff_parsed_alloc(void)
+static git_diff_parsed *diff_parsed_alloc(git_oid_t oid_type)
{
git_diff_parsed *diff;
@@ -51,6 +51,7 @@ static git_diff_parsed *diff_parsed_alloc(void)
}
diff->base.opts.flags &= ~GIT_DIFF_IGNORE_CASE;
+ diff->base.opts.oid_type = oid_type;
if (git_pool_init(&diff->base.pool, 1) < 0 ||
git_vector_init(&diff->patches, 0, NULL) < 0 ||
@@ -67,19 +68,34 @@ static git_diff_parsed *diff_parsed_alloc(void)
int git_diff_from_buffer(
git_diff **out,
const char *content,
- size_t content_len)
+ size_t content_len
+#ifdef GIT_EXPERIMENTAL_SHA256
+ , git_diff_parse_options *opts
+#endif
+ )
{
git_diff_parsed *diff;
git_patch *patch;
git_patch_parse_ctx *ctx = NULL;
+ git_patch_options patch_opts = GIT_PATCH_OPTIONS_INIT;
+ git_oid_t oid_type;
int error = 0;
*out = NULL;
- diff = diff_parsed_alloc();
+#ifdef GIT_EXPERIMENTAL_SHA256
+ oid_type = (opts && opts->oid_type) ? opts->oid_type :
+ GIT_OID_DEFAULT;
+#else
+ oid_type = GIT_OID_DEFAULT;
+#endif
+
+ patch_opts.oid_type = oid_type;
+
+ diff = diff_parsed_alloc(oid_type);
GIT_ERROR_CHECK_ALLOC(diff);
- ctx = git_patch_parse_ctx_init(content, content_len, NULL);
+ ctx = git_patch_parse_ctx_init(content, content_len, &patch_opts);
GIT_ERROR_CHECK_ALLOC(ctx);
while (ctx->parse_ctx.remain_len) {