| 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
|
|
|
|
|
|
|
#include "parse.h" |
|
8
|
|
|
|
|
|
|
|
|
9
|
206
|
|
|
|
|
|
int git_parse_ctx_init(git_parse_ctx *ctx, const char *content, size_t content_len) |
|
10
|
|
|
|
|
|
|
{ |
|
11
|
206
|
50
|
|
|
|
|
if (content && content_len) { |
|
|
|
100
|
|
|
|
|
|
|
12
|
193
|
|
|
|
|
|
ctx->content = content; |
|
13
|
193
|
|
|
|
|
|
ctx->content_len = content_len; |
|
14
|
|
|
|
|
|
|
} else { |
|
15
|
13
|
|
|
|
|
|
ctx->content = ""; |
|
16
|
13
|
|
|
|
|
|
ctx->content_len = 0; |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
|
|
19
|
206
|
|
|
|
|
|
ctx->remain = ctx->content; |
|
20
|
206
|
|
|
|
|
|
ctx->remain_len = ctx->content_len; |
|
21
|
206
|
|
|
|
|
|
ctx->line = ctx->remain; |
|
22
|
206
|
|
|
|
|
|
ctx->line_len = git__linenlen(ctx->line, ctx->remain_len); |
|
23
|
206
|
|
|
|
|
|
ctx->line_num = 1; |
|
24
|
|
|
|
|
|
|
|
|
25
|
206
|
|
|
|
|
|
return 0; |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
50
|
|
|
|
|
|
void git_parse_ctx_clear(git_parse_ctx *ctx) |
|
29
|
|
|
|
|
|
|
{ |
|
30
|
50
|
|
|
|
|
|
memset(ctx, 0, sizeof(*ctx)); |
|
31
|
50
|
|
|
|
|
|
ctx->content = ""; |
|
32
|
50
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
2829
|
|
|
|
|
|
void git_parse_advance_line(git_parse_ctx *ctx) |
|
35
|
|
|
|
|
|
|
{ |
|
36
|
2829
|
|
|
|
|
|
ctx->line += ctx->line_len; |
|
37
|
2829
|
|
|
|
|
|
ctx->remain_len -= ctx->line_len; |
|
38
|
2829
|
|
|
|
|
|
ctx->line_len = git__linenlen(ctx->line, ctx->remain_len); |
|
39
|
2829
|
|
|
|
|
|
ctx->line_num++; |
|
40
|
2829
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
3183
|
|
|
|
|
|
void git_parse_advance_chars(git_parse_ctx *ctx, size_t char_cnt) |
|
43
|
|
|
|
|
|
|
{ |
|
44
|
3183
|
|
|
|
|
|
ctx->line += char_cnt; |
|
45
|
3183
|
|
|
|
|
|
ctx->remain_len -= char_cnt; |
|
46
|
3183
|
|
|
|
|
|
ctx->line_len -= char_cnt; |
|
47
|
3183
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
58
|
|
|
|
|
|
int git_parse_advance_expected( |
|
50
|
|
|
|
|
|
|
git_parse_ctx *ctx, |
|
51
|
|
|
|
|
|
|
const char *expected, |
|
52
|
|
|
|
|
|
|
size_t expected_len) |
|
53
|
|
|
|
|
|
|
{ |
|
54
|
58
|
50
|
|
|
|
|
if (ctx->line_len < expected_len) |
|
55
|
0
|
|
|
|
|
|
return -1; |
|
56
|
|
|
|
|
|
|
|
|
57
|
58
|
50
|
|
|
|
|
if (memcmp(ctx->line, expected, expected_len) != 0) |
|
58
|
0
|
|
|
|
|
|
return -1; |
|
59
|
|
|
|
|
|
|
|
|
60
|
58
|
|
|
|
|
|
git_parse_advance_chars(ctx, expected_len); |
|
61
|
58
|
|
|
|
|
|
return 0; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
2775
|
|
|
|
|
|
int git_parse_advance_ws(git_parse_ctx *ctx) |
|
65
|
|
|
|
|
|
|
{ |
|
66
|
2775
|
|
|
|
|
|
int ret = -1; |
|
67
|
|
|
|
|
|
|
|
|
68
|
4669
|
50
|
|
|
|
|
while (ctx->line_len > 0 && |
|
|
|
100
|
|
|
|
|
|
|
69
|
4660
|
100
|
|
|
|
|
ctx->line[0] != '\n' && |
|
70
|
4660
|
|
|
|
|
|
git__isspace(ctx->line[0])) { |
|
71
|
1894
|
|
|
|
|
|
ctx->line++; |
|
72
|
1894
|
|
|
|
|
|
ctx->line_len--; |
|
73
|
1894
|
|
|
|
|
|
ctx->remain_len--; |
|
74
|
1894
|
|
|
|
|
|
ret = 0; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
2775
|
|
|
|
|
|
return ret; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
int git_parse_advance_nl(git_parse_ctx *ctx) |
|
81
|
|
|
|
|
|
|
{ |
|
82
|
0
|
0
|
|
|
|
|
if (ctx->line_len != 1 || ctx->line[0] != '\n') |
|
|
|
0
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return -1; |
|
84
|
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
git_parse_advance_line(ctx); |
|
86
|
0
|
|
|
|
|
|
return 0; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
8
|
|
|
|
|
|
int git_parse_advance_digit(int64_t *out, git_parse_ctx *ctx, int base) |
|
90
|
|
|
|
|
|
|
{ |
|
91
|
|
|
|
|
|
|
const char *end; |
|
92
|
|
|
|
|
|
|
int ret; |
|
93
|
|
|
|
|
|
|
|
|
94
|
8
|
50
|
|
|
|
|
if (ctx->line_len < 1 || !git__isdigit(ctx->line[0])) |
|
|
|
50
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
return -1; |
|
96
|
|
|
|
|
|
|
|
|
97
|
8
|
50
|
|
|
|
|
if ((ret = git__strntol64(out, ctx->line, ctx->line_len, &end, base)) < 0) |
|
98
|
0
|
|
|
|
|
|
return -1; |
|
99
|
|
|
|
|
|
|
|
|
100
|
8
|
|
|
|
|
|
git_parse_advance_chars(ctx, (end - ctx->line)); |
|
101
|
8
|
|
|
|
|
|
return 0; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
78
|
|
|
|
|
|
int git_parse_advance_oid(git_oid *out, git_parse_ctx *ctx) |
|
105
|
|
|
|
|
|
|
{ |
|
106
|
78
|
50
|
|
|
|
|
if (ctx->line_len < GIT_OID_HEXSZ) |
|
107
|
0
|
|
|
|
|
|
return -1; |
|
108
|
78
|
50
|
|
|
|
|
if ((git_oid_fromstrn(out, ctx->line, GIT_OID_HEXSZ)) < 0) |
|
109
|
0
|
|
|
|
|
|
return -1; |
|
110
|
78
|
|
|
|
|
|
git_parse_advance_chars(ctx, GIT_OID_HEXSZ); |
|
111
|
78
|
|
|
|
|
|
return 0; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
5790
|
|
|
|
|
|
int git_parse_peek(char *out, git_parse_ctx *ctx, int flags) |
|
115
|
|
|
|
|
|
|
{ |
|
116
|
5790
|
|
|
|
|
|
size_t remain = ctx->line_len; |
|
117
|
5790
|
|
|
|
|
|
const char *ptr = ctx->line; |
|
118
|
|
|
|
|
|
|
|
|
119
|
8554
|
100
|
|
|
|
|
while (remain) { |
|
120
|
7682
|
|
|
|
|
|
char c = *ptr; |
|
121
|
|
|
|
|
|
|
|
|
122
|
13210
|
|
|
|
|
|
if ((flags & GIT_PARSE_PEEK_SKIP_WHITESPACE) && |
|
123
|
5528
|
|
|
|
|
|
git__isspace(c)) { |
|
124
|
2764
|
|
|
|
|
|
remain--; |
|
125
|
2764
|
|
|
|
|
|
ptr++; |
|
126
|
2764
|
|
|
|
|
|
continue; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
4918
|
|
|
|
|
|
*out = c; |
|
130
|
4918
|
|
|
|
|
|
return 0; |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
|
|
133
|
872
|
|
|
|
|
|
return -1; |
|
134
|
|
|
|
|
|
|
} |