Commit 65dcb645 by Patrick Steinhardt

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.
parent ef1395f3
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment