line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
50
|
|
|
|
|
while (len) { |
15
|
14
|
|
|
|
|
|
unsigned char c = line[len - 1]; |
16
|
14
|
100
|
|
|
|
|
if (!git__isspace(c)) |
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
|
100
|
|
|
|
|
for (i = 0; i < strlen(message); i += line_length) { |
39
|
10
|
|
|
|
|
|
next_newline = memchr(message + i, '\n', message_len - i); |
40
|
|
|
|
|
|
|
|
41
|
10
|
50
|
|
|
|
|
if (next_newline != NULL) { |
42
|
10
|
|
|
|
|
|
line_length = next_newline - (message + i) + 1; |
43
|
|
|
|
|
|
|
} else { |
44
|
0
|
|
|
|
|
|
line_length = message_len - i; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
10
|
100
|
|
|
|
|
if (strip_comments && line_length && message[i] == comment_char) |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
48
|
3
|
|
|
|
|
|
continue; |
49
|
|
|
|
|
|
|
|
50
|
7
|
|
|
|
|
|
rtrimmed_line_length = line_length_without_trailing_spaces(message + i, line_length); |
51
|
|
|
|
|
|
|
|
52
|
7
|
50
|
|
|
|
|
if (!rtrimmed_line_length) { |
53
|
0
|
|
|
|
|
|
consecutive_empty_lines++; |
54
|
0
|
|
|
|
|
|
continue; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
7
|
50
|
|
|
|
|
if (consecutive_empty_lines > 0 && message_out->size > 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
|
50
|
|
|
|
|
return git_str_oom(message_out) ? -1 : 0; |
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
|
50
|
|
|
|
|
GIT_BUF_WRAP_PRIVATE(message_out, git_message__prettify, message, strip_comments, comment_char); |
|
|
50
|
|
|
|
|
|
75
|
|
|
|
|
|
|
} |