diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2023-04-22 23:09:32 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-22 23:09:32 +0100 |
| commit | 8a62616f43fe5ea37d41296f40293ff97aa88cfa (patch) | |
| tree | edb5683195bb8989814ca610e6745745b361efb9 /src/libgit2/patch_parse.c | |
| parent | abb0b313172d1b4477fe0c6e88102ce4bb8db90c (diff) | |
| parent | b899fda3d88dc92f50e73544fb7524a1c3c70354 (diff) | |
| download | libgit2-8a62616f43fe5ea37d41296f40293ff97aa88cfa.tar.gz | |
Merge pull request #6549 from libgit2/ethomson/sha256_experimental
sha256: less hardcoded SHA1 types and lengths
Diffstat (limited to 'src/libgit2/patch_parse.c')
| -rw-r--r-- | src/libgit2/patch_parse.c | 24 |
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; |
