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 "diff_parse.h" |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#include "diff.h" |
11
|
|
|
|
|
|
|
#include "patch.h" |
12
|
|
|
|
|
|
|
#include "patch_parse.h" |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
|
|
|
static void diff_parsed_free(git_diff *d) |
15
|
|
|
|
|
|
|
{ |
16
|
1
|
|
|
|
|
|
git_diff_parsed *diff = (git_diff_parsed *)d; |
17
|
|
|
|
|
|
|
git_patch *patch; |
18
|
|
|
|
|
|
|
size_t i; |
19
|
|
|
|
|
|
|
|
20
|
3
|
100
|
|
|
|
|
git_vector_foreach(&diff->patches, i, patch) |
21
|
2
|
|
|
|
|
|
git_patch_free(patch); |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
|
git_vector_free(&diff->patches); |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
|
git_vector_free(&diff->base.deltas); |
26
|
1
|
|
|
|
|
|
git_pool_clear(&diff->base.pool); |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
|
git__memzero(diff, sizeof(*diff)); |
29
|
1
|
|
|
|
|
|
git__free(diff); |
30
|
1
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
|
static git_diff_parsed *diff_parsed_alloc(void) |
33
|
|
|
|
|
|
|
{ |
34
|
|
|
|
|
|
|
git_diff_parsed *diff; |
35
|
|
|
|
|
|
|
|
36
|
1
|
50
|
|
|
|
|
if ((diff = git__calloc(1, sizeof(git_diff_parsed))) == NULL) |
37
|
0
|
|
|
|
|
|
return NULL; |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
|
GIT_REFCOUNT_INC(&diff->base); |
40
|
1
|
|
|
|
|
|
diff->base.type = GIT_DIFF_TYPE_PARSED; |
41
|
1
|
|
|
|
|
|
diff->base.strcomp = git__strcmp; |
42
|
1
|
|
|
|
|
|
diff->base.strncomp = git__strncmp; |
43
|
1
|
|
|
|
|
|
diff->base.pfxcomp = git__prefixcmp; |
44
|
1
|
|
|
|
|
|
diff->base.entrycomp = git_diff__entry_cmp; |
45
|
1
|
|
|
|
|
|
diff->base.patch_fn = git_patch_parsed_from_diff; |
46
|
1
|
|
|
|
|
|
diff->base.free_fn = diff_parsed_free; |
47
|
|
|
|
|
|
|
|
48
|
1
|
50
|
|
|
|
|
if (git_diff_options_init(&diff->base.opts, GIT_DIFF_OPTIONS_VERSION) < 0) { |
49
|
0
|
|
|
|
|
|
git__free(diff); |
50
|
0
|
|
|
|
|
|
return NULL; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
|
diff->base.opts.flags &= ~GIT_DIFF_IGNORE_CASE; |
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
|
|
|
if (git_pool_init(&diff->base.pool, 1) < 0 || |
56
|
2
|
50
|
|
|
|
|
git_vector_init(&diff->patches, 0, NULL) < 0 || |
57
|
1
|
|
|
|
|
|
git_vector_init(&diff->base.deltas, 0, git_diff_delta__cmp) < 0) { |
58
|
0
|
|
|
|
|
|
git_diff_free(&diff->base); |
59
|
0
|
|
|
|
|
|
return NULL; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
|
git_vector_set_cmp(&diff->base.deltas, git_diff_delta__cmp); |
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
|
return diff; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
1
|
|
|
|
|
|
int git_diff_from_buffer( |
68
|
|
|
|
|
|
|
git_diff **out, |
69
|
|
|
|
|
|
|
const char *content, |
70
|
|
|
|
|
|
|
size_t content_len) |
71
|
|
|
|
|
|
|
{ |
72
|
|
|
|
|
|
|
git_diff_parsed *diff; |
73
|
|
|
|
|
|
|
git_patch *patch; |
74
|
1
|
|
|
|
|
|
git_patch_parse_ctx *ctx = NULL; |
75
|
1
|
|
|
|
|
|
int error = 0; |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
|
*out = NULL; |
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
|
diff = diff_parsed_alloc(); |
80
|
1
|
50
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(diff); |
81
|
|
|
|
|
|
|
|
82
|
1
|
|
|
|
|
|
ctx = git_patch_parse_ctx_init(content, content_len, NULL); |
83
|
1
|
50
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(ctx); |
84
|
|
|
|
|
|
|
|
85
|
3
|
50
|
|
|
|
|
while (ctx->parse_ctx.remain_len) { |
86
|
3
|
100
|
|
|
|
|
if ((error = git_patch_parse(&patch, ctx)) < 0) |
87
|
1
|
|
|
|
|
|
break; |
88
|
|
|
|
|
|
|
|
89
|
2
|
|
|
|
|
|
git_vector_insert(&diff->patches, patch); |
90
|
2
|
|
|
|
|
|
git_vector_insert(&diff->base.deltas, patch->delta); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
1
|
50
|
|
|
|
|
if (error == GIT_ENOTFOUND && git_vector_length(&diff->patches) > 0) { |
|
|
50
|
|
|
|
|
|
94
|
1
|
|
|
|
|
|
git_error_clear(); |
95
|
1
|
|
|
|
|
|
error = 0; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
1
|
|
|
|
|
|
git_patch_parse_ctx_free(ctx); |
99
|
|
|
|
|
|
|
|
100
|
1
|
50
|
|
|
|
|
if (error < 0) |
101
|
0
|
|
|
|
|
|
git_diff_free(&diff->base); |
102
|
|
|
|
|
|
|
else |
103
|
1
|
|
|
|
|
|
*out = &diff->base; |
104
|
|
|
|
|
|
|
|
105
|
1
|
|
|
|
|
|
return error; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|