deps/libgit2/src/libgit2/message.c

filter: Statementstmt 86.2% 25 / 29 Branchbran 61.5% 16 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 74.5% 41 / 55 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« deps/libgit2/src/libgit2/buf.c ↑ Summary deps/libgit2/src/libgit2/xdiff/xprepare.c »
1 /*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
7  
8 #include "buf.h"
9  
10 #include "git2/message.h"
11  
12 7 static size_t line_length_without_trailing_spaces(const char *line, size_t len)
13 {
14 14 ▶ while (len) {
Branch: 1 branch
BranchTrueFalseTotal
while (len) { 14 0 14
15 14 unsigned char c = line[len - 1];
16 14 ▶ if (!git__isspace(c))
Branch: 1 branch
BranchTrueFalseTotal
if (!git__isspace(c)) 7 7 14
17 7 break;
18 7 len--;
19 }
20  
21 7 return len;
22 }
23  
24 /* Greatly inspired from git.git "stripspace" */
25 /* see https://github.com/git/git/blob/497215d8811ac7b8955693ceaad0899ecd894ed2/builtin/stripspace.c#L4-67 */
26 4 static int git_message__prettify(
27 git_str *message_out,
28 const char *message,
29 int strip_comments,
30 char comment_char)
31 {
32 4 const size_t message_len = strlen(message);
33  
34 4 int consecutive_empty_lines = 0;
35 size_t i, line_length, rtrimmed_line_length;
36 char *next_newline;
37  
38 14 ▶ for (i = 0; i < strlen(message); i += line_length) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < strlen(message); i += line_length) { 10 4 14
39 10 next_newline = memchr(message + i, '\n', message_len - i);
40  
41 10 ▶ if (next_newline != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (next_newline != NULL) { 10 0 10
42 10 line_length = next_newline - (message + i) + 1;
43 } else {
44 0 line_length = message_len - i;
45 }
46  
47 10 ▶ if (strip_comments && line_length && message[i] == comment_char)
Branch: 3 branches
BranchTrueFalseTotal
if (strip_comments && line_length && message[i] == comment_char) 8 2 10
if (strip_comments && line_length && message[i] == comment_char) 8 0 8
if (strip_comments && line_length && message[i] == comment_char) 3 5 8
48 3 continue;
49  
50 7 rtrimmed_line_length = line_length_without_trailing_spaces(message + i, line_length);
51  
52 7 ▶ if (!rtrimmed_line_length) {
Branch: 1 branch
BranchTrueFalseTotal
if (!rtrimmed_line_length) { 0 7 7
53 0 consecutive_empty_lines++;
54 0 continue;
55 }
56  
57 7 ▶ if (consecutive_empty_lines > 0 && message_out->size > 0)
Branch: 2 branches
BranchTrueFalseTotal
if (consecutive_empty_lines > 0 && message_out->size > 0) 0 7 7
if (consecutive_empty_lines > 0 && message_out->size > 0) 0 0 0
58 0 git_str_putc(message_out, '\n');
59  
60 7 consecutive_empty_lines = 0;
61 7 git_str_put(message_out, message + i, rtrimmed_line_length);
62 7 git_str_putc(message_out, '\n');
63 }
64  
65 4 ▶ return git_str_oom(message_out) ? -1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
return git_str_oom(message_out) ? -1 : 0; 0 4 4
66 }
67  
68 4 int git_message_prettify(
69 git_buf *message_out,
70 const char *message,
71 int strip_comments,
72 char comment_char)
73 {
74 4 ▶ GIT_BUF_WRAP_PRIVATE(message_out, git_message__prettify, message, strip_comments, comment_char);
Branch: 2 branches
BranchTrueFalseTotal
GIT_BUF_WRAP_PRIVATE(message_out, git_message__prettify, message, strip_comments, comment_char); 4 0 4
GIT_BUF_WRAP_PRIVATE(message_out, git_message__prettify, message, strip_comments, comment_char); 4 0 4
75 }
« deps/libgit2/src/libgit2/buf.c ↑ Summary deps/libgit2/src/libgit2/xdiff/xprepare.c »