From 65dcb6453457fee640fe62008f9a395de58fd39a Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Fri, 14 Jul 2017 13:29:29 +0200 Subject: patch_parse: use git_parse_contains_s Instead of manually checking the parsing context's remaining length and comparing the leading bytes with a specific string, we can simply re-use the function `git_parse_ctx_contains_s`. Do so to avoid code duplication and to further decouple patch parsing from the parsing context's struct members. --- src/patch_parse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/patch_parse.c b/src/patch_parse.c index 506a1bdcb..0b3ad8f08 100644 --- a/src/patch_parse.c +++ b/src/patch_parse.c @@ -36,7 +36,7 @@ typedef struct { static int header_path_len(git_patch_parse_ctx *ctx) { bool inquote = 0; - bool quoted = (ctx->parse_ctx.line_len > 0 && ctx->parse_ctx.line[0] == '"'); + bool quoted = git_parse_ctx_contains_s(&ctx->parse_ctx, "\""); size_t len; for (len = quoted; len < ctx->parse_ctx.line_len; len++) { @@ -531,7 +531,7 @@ static int parse_hunk_body( for (; ctx->parse_ctx.remain_len > 1 && (oldlines || newlines) && - (ctx->parse_ctx.remain_len <= 4 || memcmp(ctx->parse_ctx.line, "@@ -", 4) != 0); + !git_parse_ctx_contains_s(&ctx->parse_ctx, "@@ -"); git_parse_advance_line(&ctx->parse_ctx)) { int origin; -- cgit v1.2.1