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 "annotated_commit.h" |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#include "refs.h" |
11
|
|
|
|
|
|
|
#include "cache.h" |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#include "git2/commit.h" |
14
|
|
|
|
|
|
|
#include "git2/refs.h" |
15
|
|
|
|
|
|
|
#include "git2/repository.h" |
16
|
|
|
|
|
|
|
#include "git2/annotated_commit.h" |
17
|
|
|
|
|
|
|
#include "git2/revparse.h" |
18
|
|
|
|
|
|
|
#include "git2/tree.h" |
19
|
|
|
|
|
|
|
#include "git2/index.h" |
20
|
|
|
|
|
|
|
|
21
|
48
|
|
|
|
|
|
static int annotated_commit_init( |
22
|
|
|
|
|
|
|
git_annotated_commit **out, |
23
|
|
|
|
|
|
|
git_commit *commit, |
24
|
|
|
|
|
|
|
const char *description) |
25
|
|
|
|
|
|
|
{ |
26
|
|
|
|
|
|
|
git_annotated_commit *annotated_commit; |
27
|
48
|
|
|
|
|
|
int error = 0; |
28
|
|
|
|
|
|
|
|
29
|
48
|
50
|
|
|
|
|
assert(out && commit); |
|
|
50
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
48
|
|
|
|
|
|
*out = NULL; |
32
|
|
|
|
|
|
|
|
33
|
48
|
|
|
|
|
|
annotated_commit = git__calloc(1, sizeof(git_annotated_commit)); |
34
|
48
|
50
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(annotated_commit); |
35
|
|
|
|
|
|
|
|
36
|
48
|
|
|
|
|
|
annotated_commit->type = GIT_ANNOTATED_COMMIT_REAL; |
37
|
|
|
|
|
|
|
|
38
|
48
|
50
|
|
|
|
|
if ((error = git_commit_dup(&annotated_commit->commit, commit)) < 0) |
39
|
0
|
|
|
|
|
|
goto done; |
40
|
|
|
|
|
|
|
|
41
|
48
|
|
|
|
|
|
git_oid_fmt(annotated_commit->id_str, git_commit_id(commit)); |
42
|
48
|
|
|
|
|
|
annotated_commit->id_str[GIT_OID_HEXSZ] = '\0'; |
43
|
|
|
|
|
|
|
|
44
|
48
|
100
|
|
|
|
|
if (!description) |
45
|
22
|
|
|
|
|
|
description = annotated_commit->id_str; |
46
|
|
|
|
|
|
|
|
47
|
48
|
|
|
|
|
|
annotated_commit->description = git__strdup(description); |
48
|
48
|
50
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(annotated_commit->description); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
done: |
51
|
48
|
50
|
|
|
|
|
if (!error) |
52
|
48
|
|
|
|
|
|
*out = annotated_commit; |
53
|
|
|
|
|
|
|
|
54
|
48
|
|
|
|
|
|
return error; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
47
|
|
|
|
|
|
static int annotated_commit_init_from_id( |
58
|
|
|
|
|
|
|
git_annotated_commit **out, |
59
|
|
|
|
|
|
|
git_repository *repo, |
60
|
|
|
|
|
|
|
const git_oid *id, |
61
|
|
|
|
|
|
|
const char *description) |
62
|
|
|
|
|
|
|
{ |
63
|
47
|
|
|
|
|
|
git_commit *commit = NULL; |
64
|
47
|
|
|
|
|
|
int error = 0; |
65
|
|
|
|
|
|
|
|
66
|
47
|
50
|
|
|
|
|
assert(out && repo && id); |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
47
|
|
|
|
|
|
*out = NULL; |
69
|
|
|
|
|
|
|
|
70
|
47
|
100
|
|
|
|
|
if ((error = git_commit_lookup(&commit, repo, id)) < 0) |
71
|
1
|
|
|
|
|
|
goto done; |
72
|
|
|
|
|
|
|
|
73
|
46
|
|
|
|
|
|
error = annotated_commit_init(out, commit, description); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
done: |
76
|
47
|
|
|
|
|
|
git_commit_free(commit); |
77
|
47
|
|
|
|
|
|
return error; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
21
|
|
|
|
|
|
int git_annotated_commit_lookup( |
81
|
|
|
|
|
|
|
git_annotated_commit **out, |
82
|
|
|
|
|
|
|
git_repository *repo, |
83
|
|
|
|
|
|
|
const git_oid *id) |
84
|
|
|
|
|
|
|
{ |
85
|
21
|
|
|
|
|
|
return annotated_commit_init_from_id(out, repo, id, NULL); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
2
|
|
|
|
|
|
int git_annotated_commit_from_commit( |
89
|
|
|
|
|
|
|
git_annotated_commit **out, |
90
|
|
|
|
|
|
|
git_commit *commit) |
91
|
|
|
|
|
|
|
{ |
92
|
2
|
|
|
|
|
|
return annotated_commit_init(out, commit, NULL); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
int git_annotated_commit_from_revspec( |
96
|
|
|
|
|
|
|
git_annotated_commit **out, |
97
|
|
|
|
|
|
|
git_repository *repo, |
98
|
|
|
|
|
|
|
const char *revspec) |
99
|
|
|
|
|
|
|
{ |
100
|
|
|
|
|
|
|
git_object *obj, *commit; |
101
|
|
|
|
|
|
|
int error; |
102
|
|
|
|
|
|
|
|
103
|
0
|
0
|
|
|
|
|
assert(out && repo && revspec); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
if ((error = git_revparse_single(&obj, repo, revspec)) < 0) |
106
|
0
|
|
|
|
|
|
return error; |
107
|
|
|
|
|
|
|
|
108
|
0
|
0
|
|
|
|
|
if ((error = git_object_peel(&commit, obj, GIT_OBJECT_COMMIT))) { |
109
|
0
|
|
|
|
|
|
git_object_free(obj); |
110
|
0
|
|
|
|
|
|
return error; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
error = annotated_commit_init(out, (git_commit *)commit, revspec); |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
git_object_free(obj); |
116
|
0
|
|
|
|
|
|
git_object_free(commit); |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
return error; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
26
|
|
|
|
|
|
int git_annotated_commit_from_ref( |
122
|
|
|
|
|
|
|
git_annotated_commit **out, |
123
|
|
|
|
|
|
|
git_repository *repo, |
124
|
|
|
|
|
|
|
const git_reference *ref) |
125
|
|
|
|
|
|
|
{ |
126
|
|
|
|
|
|
|
git_object *peeled; |
127
|
26
|
|
|
|
|
|
int error = 0; |
128
|
|
|
|
|
|
|
|
129
|
26
|
50
|
|
|
|
|
assert(out && repo && ref); |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
26
|
|
|
|
|
|
*out = NULL; |
132
|
|
|
|
|
|
|
|
133
|
26
|
50
|
|
|
|
|
if ((error = git_reference_peel(&peeled, ref, GIT_OBJECT_COMMIT)) < 0) |
134
|
0
|
|
|
|
|
|
return error; |
135
|
|
|
|
|
|
|
|
136
|
26
|
|
|
|
|
|
error = annotated_commit_init_from_id(out, |
137
|
|
|
|
|
|
|
repo, |
138
|
|
|
|
|
|
|
git_object_id(peeled), |
139
|
|
|
|
|
|
|
git_reference_name(ref)); |
140
|
|
|
|
|
|
|
|
141
|
26
|
50
|
|
|
|
|
if (!error) { |
142
|
26
|
|
|
|
|
|
(*out)->ref_name = git__strdup(git_reference_name(ref)); |
143
|
26
|
50
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC((*out)->ref_name); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
26
|
|
|
|
|
|
git_object_free(peeled); |
147
|
26
|
|
|
|
|
|
return error; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
5
|
|
|
|
|
|
int git_annotated_commit_from_head( |
151
|
|
|
|
|
|
|
git_annotated_commit **out, |
152
|
|
|
|
|
|
|
git_repository *repo) |
153
|
|
|
|
|
|
|
{ |
154
|
|
|
|
|
|
|
git_reference *head; |
155
|
|
|
|
|
|
|
int error; |
156
|
|
|
|
|
|
|
|
157
|
5
|
50
|
|
|
|
|
assert(out && repo); |
|
|
50
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
159
|
5
|
|
|
|
|
|
*out = NULL; |
160
|
|
|
|
|
|
|
|
161
|
5
|
50
|
|
|
|
|
if ((error = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0) |
162
|
0
|
|
|
|
|
|
return -1; |
163
|
|
|
|
|
|
|
|
164
|
5
|
|
|
|
|
|
error = git_annotated_commit_from_ref(out, repo, head); |
165
|
|
|
|
|
|
|
|
166
|
5
|
|
|
|
|
|
git_reference_free(head); |
167
|
5
|
|
|
|
|
|
return error; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
0
|
|
|
|
|
|
int git_annotated_commit_from_fetchhead( |
171
|
|
|
|
|
|
|
git_annotated_commit **out, |
172
|
|
|
|
|
|
|
git_repository *repo, |
173
|
|
|
|
|
|
|
const char *branch_name, |
174
|
|
|
|
|
|
|
const char *remote_url, |
175
|
|
|
|
|
|
|
const git_oid *id) |
176
|
|
|
|
|
|
|
{ |
177
|
0
|
0
|
|
|
|
|
assert(repo && id && branch_name && remote_url); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
178
|
|
|
|
|
|
|
|
179
|
0
|
0
|
|
|
|
|
if (annotated_commit_init_from_id(out, repo, id, branch_name) < 0) |
180
|
0
|
|
|
|
|
|
return -1; |
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
(*out)->ref_name = git__strdup(branch_name); |
183
|
0
|
0
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC((*out)->ref_name); |
184
|
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
(*out)->remote_url = git__strdup(remote_url); |
186
|
0
|
0
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC((*out)->remote_url); |
187
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
return 0; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
|
192
|
52
|
|
|
|
|
|
const git_oid *git_annotated_commit_id( |
193
|
|
|
|
|
|
|
const git_annotated_commit *annotated_commit) |
194
|
|
|
|
|
|
|
{ |
195
|
52
|
50
|
|
|
|
|
assert(annotated_commit); |
196
|
52
|
|
|
|
|
|
return git_commit_id(annotated_commit->commit); |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
|
const char *git_annotated_commit_ref( |
200
|
|
|
|
|
|
|
const git_annotated_commit *annotated_commit) |
201
|
|
|
|
|
|
|
{ |
202
|
0
|
0
|
|
|
|
|
assert(annotated_commit); |
203
|
0
|
|
|
|
|
|
return annotated_commit->ref_name; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
66
|
|
|
|
|
|
void git_annotated_commit_free(git_annotated_commit *annotated_commit) |
207
|
|
|
|
|
|
|
{ |
208
|
66
|
100
|
|
|
|
|
if (annotated_commit == NULL) |
209
|
21
|
|
|
|
|
|
return; |
210
|
|
|
|
|
|
|
|
211
|
45
|
|
|
|
|
|
switch (annotated_commit->type) { |
212
|
|
|
|
|
|
|
case GIT_ANNOTATED_COMMIT_REAL: |
213
|
45
|
|
|
|
|
|
git_commit_free(annotated_commit->commit); |
214
|
45
|
|
|
|
|
|
git_tree_free(annotated_commit->tree); |
215
|
45
|
|
|
|
|
|
git__free((char *)annotated_commit->description); |
216
|
45
|
|
|
|
|
|
git__free((char *)annotated_commit->ref_name); |
217
|
45
|
|
|
|
|
|
git__free((char *)annotated_commit->remote_url); |
218
|
45
|
|
|
|
|
|
break; |
219
|
|
|
|
|
|
|
case GIT_ANNOTATED_COMMIT_VIRTUAL: |
220
|
0
|
|
|
|
|
|
git_index_free(annotated_commit->index); |
221
|
0
|
|
|
|
|
|
git_array_clear(annotated_commit->parents); |
222
|
0
|
|
|
|
|
|
break; |
223
|
|
|
|
|
|
|
default: |
224
|
0
|
|
|
|
|
|
abort(); |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
45
|
|
|
|
|
|
git__free(annotated_commit); |
228
|
|
|
|
|
|
|
} |