summaryrefslogtreecommitdiff
path: root/src/libgit2/patch_parse.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2023-04-07 15:28:58 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2023-04-10 14:21:16 +0100
commitdb2a794dda2b6f92291b3758507f863f39314c72 (patch)
tree53c5b2d77c6c38cf26fecc90e91809df0397fa46 /src/libgit2/patch_parse.c
parent7f70484799df14dbc666b3c395ded690d1a5a402 (diff)
downloadlibgit2-db2a794dda2b6f92291b3758507f863f39314c72.tar.gz
diff: parse patches with sha256
Diffstat (limited to 'src/libgit2/patch_parse.c')
-rw-r--r--src/libgit2/patch_parse.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/libgit2/patch_parse.c b/src/libgit2/patch_parse.c
index ffdb99231..c06915537 100644
--- a/src/libgit2/patch_parse.c
+++ b/src/libgit2/patch_parse.c
@@ -166,15 +166,19 @@ static int parse_header_oid(
uint16_t *oid_len,
git_patch_parse_ctx *ctx)
{
- size_t len;
+ size_t hexsize, len;
+
+ hexsize = git_oid_hexsize(ctx->opts.oid_type);
- for (len = 0; len < ctx->parse_ctx.line_len && len < GIT_OID_SHA1_HEXSIZE; len++) {
+ for (len = 0;
+ len < ctx->parse_ctx.line_len && len < hexsize;
+ len++) {
if (!git__isxdigit(ctx->parse_ctx.line[len]))
break;
}
- if (len < GIT_OID_MINPREFIXLEN || len > GIT_OID_SHA1_HEXSIZE ||
- git_oid__fromstrn(oid, ctx->parse_ctx.line, len, GIT_OID_SHA1) < 0)
+ if (len < GIT_OID_MINPREFIXLEN || len > hexsize ||
+ git_oid__fromstrn(oid, ctx->parse_ctx.line, len, ctx->opts.oid_type) < 0)
return git_parse_err("invalid hex formatted object id at line %"PRIuZ,
ctx->parse_ctx.line_num);
@@ -1065,12 +1069,14 @@ static int check_patch(git_patch_parsed *patch)
return git_parse_err("patch with no hunks");
if (delta->status == GIT_DELTA_ADDED) {
- git_oid_clear(&delta->old_file.id, GIT_OID_SHA1);
+ git_oid_clear(&delta->old_file.id,
+ patch->base.diff_opts.oid_type);
delta->old_file.id_abbrev = 0;
}
if (delta->status == GIT_DELTA_DELETED) {
- git_oid_clear(&delta->new_file.id, GIT_OID_SHA1);
+ git_oid_clear(&delta->new_file.id,
+ patch->base.diff_opts.oid_type);
delta->new_file.id_abbrev = 0;
}
@@ -1187,11 +1193,13 @@ int git_patch_parse(
patch->base.delta->status = GIT_DELTA_MODIFIED;
patch->base.delta->nfiles = 2;
+ patch->base.diff_opts.oid_type = ctx->opts.oid_type;
+
start = ctx->parse_ctx.remain_len;
if ((error = parse_patch_header(patch, ctx)) < 0 ||
- (error = parse_patch_body(patch, ctx)) < 0 ||
- (error = check_patch(patch)) < 0)
+ (error = parse_patch_body(patch, ctx)) < 0 ||
+ (error = check_patch(patch)) < 0)
goto done;
used = start - ctx->parse_ctx.remain_len;