Branch Coverage

deps/libgit2/src/libgit2/patch_parse.c
Criterion Covered Total %
branch 157 376 41.7


line true false branch
54 32 0 for (len = quoted; len < ctx->parse_ctx.line_len; len++) {
55 32 0 if (!quoted && git__isspace(ctx->parse_ctx.line[len]))
28 4 if (!quoted && git__isspace(ctx->parse_ctx.line[len]))
57 0 28 else if (quoted && !inquote && ctx->parse_ctx.line[len] == '"') {
0 0 else if (quoted && !inquote && ctx->parse_ctx.line[len] == '"') {
0 0 else if (quoted && !inquote && ctx->parse_ctx.line[len] == '"') {
62 28 0 inquote = (!inquote && ctx->parse_ctx.line[len] == '\\');
0 28 inquote = (!inquote && ctx->parse_ctx.line[len] == '\\');
72 0 8 if ((error = git_str_put(path, ctx->parse_ctx.line, path_len)) < 0)
79 8 0 if (path->size > 0 && path->ptr[0] == '"' &&
0 8 if (path->size > 0 && path->ptr[0] == '"' &&
0 0 if (path->size > 0 && path->ptr[0] == '"' &&
85 0 8 if (!path->size)
97 0 4 if ((error = parse_header_path_buf(&path, ctx, header_path_len(ctx))) < 0)
112 0 2 if (patch->old_path) {
118 0 2 if ((error = parse_header_path_buf(&old_path, ctx, ctx->parse_ctx.line_len - 1)) < 0)
134 0 2 if (patch->new_path) {
140 0 2 if ((error = parse_header_path_buf(&new_path, ctx, ctx->parse_ctx.line_len - 1)) < 0)
153 0 2 if ((git_parse_advance_digit(&m, &ctx->parse_ctx, 8)) < 0)
156 0 2 if (m > UINT16_MAX)
171 32 0 for (len = 0; len < ctx->parse_ctx.line_len && len < GIT_OID_HEXSZ; len++) {
32 0 for (len = 0; len < ctx->parse_ctx.line_len && len < GIT_OID_HEXSZ; len++) {
172 4 28 if (!git__isxdigit(ctx->parse_ctx.line[len]))
176 4 0 if (len < GIT_OID_MINPREFIXLEN || len > GIT_OID_HEXSZ ||
193 2 0 if (parse_header_oid(&patch->base.delta->old_file.id,
194 2 0 &patch->base.delta->old_file.id_abbrev, ctx) < 0 ||
195 0 2 git_parse_advance_expected_str(&ctx->parse_ctx, "..") < 0 ||
200 2 0 if (git_parse_peek(&c, &ctx->parse_ctx, 0) == 0 && c == ' ') {
1 1 if (git_parse_peek(&c, &ctx->parse_ctx, 0) == 0 && c == ' ') {
205 0 1 if (parse_header_mode(&mode, ctx) < 0)
208 1 0 if (!patch->base.delta->new_file.mode)
211 1 0 if (!patch->base.delta->old_file.mode)
262 0 0 if (parse_header_path_buf(&path, ctx, header_path_len(ctx)) < 0)
304 0 0 if (git_parse_advance_digit(&val, &ctx->parse_ctx, 10) < 0)
307 0 0 if (git_parse_advance_expected_str(&ctx->parse_ctx, "%") < 0)
310 0 0 if (val < 0 || val > 100)
0 0 if (val < 0 || val > 100)
320 0 0 if (parse_header_percent(&patch->base.delta->similarity, ctx) < 0)
332 0 0 if (parse_header_percent(&dissimilarity, ctx) < 0)
343 0 2 if (parse_header_path(&patch->header_old_path, ctx) < 0)
441 11 0 for (; ctx->parse_ctx.remain_len > 0; git_parse_advance_line(&ctx->parse_ctx)) {
444 11 0 if (ctx->parse_ctx.line_len == 0 || ctx->parse_ctx.line[ctx->parse_ctx.line_len - 1] != '\n')
11 0 if (ctx->parse_ctx.line_len == 0 || ctx->parse_ctx.line[ctx->parse_ctx.line_len - 1] != '\n')
447 112 0 for (i = 0; i < ARRAY_SIZE(transitions); i++) {
458 2 9 if (transition->fn == NULL)
463 0 9 if ((error = transition->fn(patch, ctx)) < 0)
468 9 0 if (git_parse_advance_expected_str(&ctx->parse_ctx, "\n") < 0 ||
0 9 if (git_parse_advance_expected_str(&ctx->parse_ctx, "\n") < 0 ||
478 0 9 if (!found) {
485 0 0 if (state != STATE_END) {
498 6 0 if (git_parse_advance_digit(&num, &ctx->parse_ctx, 10) < 0 || !git__is_int(num))
0 6 if (git_parse_advance_digit(&num, &ctx->parse_ctx, 10) < 0 || !git__is_int(num))
519 2 0 if (git_parse_peek(&c, &ctx->parse_ctx, 0) == 0 && c == ',') {
1 1 if (git_parse_peek(&c, &ctx->parse_ctx, 0) == 0 && c == ',') {
529 2 0 if (git_parse_peek(&c, &ctx->parse_ctx, 0) == 0 && c == ',') {
1 1 if (git_parse_peek(&c, &ctx->parse_ctx, 0) == 0 && c == ',') {
535 0 2 if (git_parse_advance_expected_str(&ctx->parse_ctx, " @@") < 0)
540 1 1 if (!hunk->hunk.old_lines && !hunk->hunk.new_lines)
0 1 if (!hunk->hunk.old_lines && !hunk->hunk.new_lines)
544 0 2 if (hunk->hunk.header_len > (GIT_DIFF_HUNK_HEADER_SIZE - 1))
560 0 0 if (origin == GIT_DIFF_LINE_ADDITION)
562 0 0 if (origin == GIT_DIFF_LINE_DELETION)
579 5 0 for (;
580 4 1 ctx->parse_ctx.remain_len > 1 &&
589 3 0 git__sub_int_overflow(&old_lineno, old_lineno, oldlines) ||
590 0 3 git__add_int_overflow(&new_lineno, hunk->hunk.new_start, hunk->hunk.new_lines) ||
597 3 0 if (ctx->parse_ctx.line_len == 0 || ctx->parse_ctx.line[ctx->parse_ctx.line_len - 1] != '\n') {
0 3 if (ctx->parse_ctx.line_len == 0 || ctx->parse_ctx.line[ctx->parse_ctx.line_len - 1] != '\n') {
634 0 0 if (!oldlines) {
648 2 1 line = git_array_alloc(patch->base.lines);
2 0 line = git_array_alloc(patch->base.lines);
649 0 3 GIT_ERROR_CHECK_ALLOC(line);
655 0 3 GIT_ERROR_CHECK_ALLOC(line->content);
667 2 0 if (oldlines || newlines) {
0 2 if (oldlines || newlines) {
680 0 2 if (git_parse_ctx_contains_s(&ctx->parse_ctx, "\\ ") &&
0 0 if (git_parse_ctx_contains_s(&ctx->parse_ctx, "\\ ") &&
683 0 0 line = git_array_get(patch->base.lines, git_array_size(patch->base.lines) - 1);
685 0 0 if (line->content_len < 1) {
690 0 0 line = git_array_alloc(patch->base.lines);
0 0 line = git_array_alloc(patch->base.lines);
691 0 0 GIT_ERROR_CHECK_ALLOC(line);
697 0 0 GIT_ERROR_CHECK_ALLOC(line->content);
719 15 0 for (; ctx->parse_ctx.remain_len > 0; git_parse_advance_line(&ctx->parse_ctx)) {
721 4 11 if (ctx->parse_ctx.line_len < 6)
726 0 11 if (git_parse_ctx_contains_s(&ctx->parse_ctx, "@@ -")) {
733 0 0 if (parse_hunk_header(&hunk, ctx) < 0) {
744 1 10 if (ctx->parse_ctx.remain_len < ctx->parse_ctx.line_len + 6)
748 2 8 if (git_parse_ctx_contains_s(&ctx->parse_ctx, "diff --git ")) {
773 0 0 if (git_parse_ctx_contains_s(&ctx->parse_ctx, "literal ")) {
776 0 0 } else if (git_parse_ctx_contains_s(&ctx->parse_ctx, "delta ")) {
786 0 0 git_parse_advance_nl(&ctx->parse_ctx) < 0 || len < 0) {
791 0 0 while (ctx->parse_ctx.line_len) {
797 0 0 if (c == '\n')
799 0 0 else if (c >= 'A' && c <= 'Z')
0 0 else if (c >= 'A' && c <= 'Z')
801 0 0 else if (c >= 'a' && c <= 'z')
0 0 else if (c >= 'a' && c <= 'z')
804 0 0 if (!decoded_len) {
813 0 0 if (!encoded_len || !ctx->parse_ctx.line_len || encoded_len > ctx->parse_ctx.line_len - 1) {
0 0 if (!encoded_len || !ctx->parse_ctx.line_len || encoded_len > ctx->parse_ctx.line_len - 1) {
0 0 if (!encoded_len || !ctx->parse_ctx.line_len || encoded_len > ctx->parse_ctx.line_len - 1) {
818 0 0 if ((error = git_str_decode_base85(
822 0 0 if (decoded.size - decoded_orig != decoded_len) {
829 0 0 if (git_parse_advance_nl(&ctx->parse_ctx) < 0) {
857 0 0 if ((error = parse_patch_binary_side(
861 0 0 if (git_parse_advance_nl(&ctx->parse_ctx) < 0)
866 0 0 if ((error = parse_patch_binary_side(
870 0 0 if (git_parse_advance_nl(&ctx->parse_ctx) < 0)
883 0 0 const char *old = patch->old_path ? patch->old_path : patch->header_old_path;
884 0 0 const char *new = patch->new_path ? patch->new_path : patch->header_new_path;
886 0 0 if (!old || !new)
0 0 if (!old || !new)
889 0 0 if (patch->base.delta->status == GIT_DELTA_ADDED)
891 0 0 else if (patch->base.delta->status == GIT_DELTA_DELETED)
895 0 0 git_parse_advance_expected_str(&ctx->parse_ctx, old) < 0 ||
896 0 0 git_parse_advance_expected_str(&ctx->parse_ctx, " and ") < 0 ||
897 0 0 git_parse_advance_expected_str(&ctx->parse_ctx, new) < 0 ||
898 0 0 git_parse_advance_expected_str(&ctx->parse_ctx, " differ") < 0 ||
914 2 2 while (git_parse_ctx_contains_s(&ctx->parse_ctx, "@@ -")) {
915 2 0 hunk = git_array_alloc(patch->base.hunks);
2 0 hunk = git_array_alloc(patch->base.hunks);
916 0 2 GIT_ERROR_CHECK_ALLOC(hunk);
923 2 0 if ((error = parse_hunk_header(hunk, ctx)) < 0 ||
2 0 if ((error = parse_hunk_header(hunk, ctx)) < 0 ||
937 0 2 if (git_parse_ctx_contains_s(&ctx->parse_ctx, "GIT binary patch"))
939 0 2 else if (git_parse_ctx_contains_s(&ctx->parse_ctx, "Binary files "))
951 4 0 if (!one || !two)
0 4 if (!one || !two)
954 1 3 if (two_null && strcmp(two, "/dev/null") != 0)
0 1 if (two_null && strcmp(two, "/dev/null") != 0)
957 3 1 else if (!two_null && strcmp(one, two) != 0)
0 3 else if (!two_null && strcmp(one, two) != 0)
976 0 4 if (prefix_len == 0)
980 0 4 while (*path == '/')
983 12 0 while (*path && remain_len) {
8 4 while (*path && remain_len) {
984 4 4 if (*path == '/')
990 4 0 if (remain_len || !*path)
0 4 if (remain_len || !*path)
999 0 4 return (*out == NULL) ? -1 : 0;
1009 2 0 if (patch->old_path && !patch->new_path)
0 2 if (patch->old_path && !patch->new_path)
1012 0 2 if (!patch->old_path && patch->new_path)
0 0 if (!patch->old_path && patch->new_path)
1020 1 1 prefixed_old = (!added && patch->old_path) ? patch->old_path : patch->header_old_path;
1 0 prefixed_old = (!added && patch->old_path) ? patch->old_path : patch->header_old_path;
1021 2 0 prefixed_new = (!deleted && patch->new_path) ? patch->new_path : patch->header_new_path;
2 0 prefixed_new = (!deleted && patch->new_path) ? patch->new_path : patch->header_new_path;
1023 2 0 if ((prefixed_old && check_prefix(&patch->old_prefix, &old_prefixlen, patch, prefixed_old) < 0) ||
2 0 if ((prefixed_old && check_prefix(&patch->old_prefix, &old_prefixlen, patch, prefixed_old) < 0) ||
2 0 if ((prefixed_old && check_prefix(&patch->old_prefix, &old_prefixlen, patch, prefixed_old) < 0) ||
1024 0 2 (prefixed_new && check_prefix(&patch->new_prefix, &new_prefixlen, patch, prefixed_new) < 0))
1028 0 2 if (patch->rename_old_path)
1030 2 0 else if (prefixed_old)
1035 0 2 if (patch->rename_new_path)
1037 2 0 else if (prefixed_new)
1042 0 2 if (!patch->base.delta->old_file.path &&
0 0 if (!patch->base.delta->old_file.path &&
1053 0 2 if (check_filenames(patch) < 0)
1056 2 0 if (delta->old_file.path &&
2 0 if (delta->old_file.path &&
1057 0 2 delta->status != GIT_DELTA_DELETED &&
1061 1 1 if (delta->status == GIT_DELTA_MODIFIED &&
1 0 if (delta->status == GIT_DELTA_MODIFIED &&
1062 1 0 !(delta->flags & GIT_DIFF_FLAG_BINARY) &&
1063 0 1 delta->new_file.mode == delta->old_file.mode &&
1067 1 1 if (delta->status == GIT_DELTA_ADDED) {
1072 0 2 if (delta->status == GIT_DELTA_DELETED) {
1088 0 1 if ((ctx = git__calloc(1, sizeof(git_patch_parse_ctx))) == NULL)
1091 0 1 if ((git_parse_ctx_init(&ctx->parse_ctx, content, content_len)) < 0) {
1096 0 1 if (opts)
1107 0 1 if (!ctx)
1116 1 3 GIT_REFCOUNT_DEC(ctx, patch_parse_ctx_free);
1 0 GIT_REFCOUNT_DEC(ctx, patch_parse_ctx_free);
1124 0 2 if ((p = git_vector_get(&diff->patches, idx)) == NULL)
1139 0 3 if (!patch)
1147 3 3 git_array_foreach(patch->base.lines, i, line)
3 0 git_array_foreach(patch->base.lines, i, line)
1171 0 3 GIT_ASSERT_ARG(out);
1172 0 3 GIT_ASSERT_ARG(ctx);
1177 0 3 GIT_ERROR_CHECK_ALLOC(patch);
1185 0 3 GIT_ERROR_CHECK_ALLOC(patch->base.delta);
1192 2 1 if ((error = parse_patch_header(patch, ctx)) < 0 ||
2 0 if ((error = parse_patch_header(patch, ctx)) < 0 ||
1193 2 0 (error = parse_patch_body(patch, ctx)) < 0 ||
1208 1 2 if (error < 0)
1224 0 0 GIT_ERROR_CHECK_ALLOC(ctx);