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 "notes.h" |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#include "buf.h" |
11
|
|
|
|
|
|
|
#include "refs.h" |
12
|
|
|
|
|
|
|
#include "config.h" |
13
|
|
|
|
|
|
|
#include "iterator.h" |
14
|
|
|
|
|
|
|
#include "signature.h" |
15
|
|
|
|
|
|
|
#include "blob.h" |
16
|
|
|
|
|
|
|
|
17
|
6
|
|
|
|
|
|
static int note_error_notfound(void) |
18
|
|
|
|
|
|
|
{ |
19
|
6
|
|
|
|
|
|
git_error_set(GIT_ERROR_INVALID, "note could not be found"); |
20
|
6
|
|
|
|
|
|
return GIT_ENOTFOUND; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
16
|
|
|
|
|
|
static int find_subtree_in_current_level( |
24
|
|
|
|
|
|
|
git_tree **out, |
25
|
|
|
|
|
|
|
git_repository *repo, |
26
|
|
|
|
|
|
|
git_tree *parent, |
27
|
|
|
|
|
|
|
const char *annotated_object_sha, |
28
|
|
|
|
|
|
|
int fanout) |
29
|
|
|
|
|
|
|
{ |
30
|
|
|
|
|
|
|
size_t i; |
31
|
|
|
|
|
|
|
const git_tree_entry *entry; |
32
|
|
|
|
|
|
|
|
33
|
16
|
|
|
|
|
|
*out = NULL; |
34
|
|
|
|
|
|
|
|
35
|
16
|
100
|
|
|
|
|
if (parent == NULL) |
36
|
2
|
|
|
|
|
|
return note_error_notfound(); |
37
|
|
|
|
|
|
|
|
38
|
14
|
100
|
|
|
|
|
for (i = 0; i < git_tree_entrycount(parent); i++) { |
39
|
10
|
|
|
|
|
|
entry = git_tree_entry_byindex(parent, i); |
40
|
|
|
|
|
|
|
|
41
|
10
|
50
|
|
|
|
|
if (!git__ishex(git_tree_entry_name(entry))) |
42
|
0
|
|
|
|
|
|
continue; |
43
|
|
|
|
|
|
|
|
44
|
10
|
50
|
|
|
|
|
if (S_ISDIR(git_tree_entry_filemode(entry)) |
45
|
0
|
0
|
|
|
|
|
&& strlen(git_tree_entry_name(entry)) == 2 |
46
|
0
|
0
|
|
|
|
|
&& !strncmp(git_tree_entry_name(entry), annotated_object_sha + fanout, 2)) |
47
|
0
|
|
|
|
|
|
return git_tree_lookup(out, repo, git_tree_entry_id(entry)); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
/* Not a DIR, so do we have an already existing blob? */ |
50
|
10
|
50
|
|
|
|
|
if (!strcmp(git_tree_entry_name(entry), annotated_object_sha + fanout)) |
51
|
10
|
|
|
|
|
|
return GIT_EEXISTS; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
4
|
|
|
|
|
|
return note_error_notfound(); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
8
|
|
|
|
|
|
static int find_subtree_r(git_tree **out, git_tree *root, |
58
|
|
|
|
|
|
|
git_repository *repo, const char *target, int *fanout) |
59
|
|
|
|
|
|
|
{ |
60
|
|
|
|
|
|
|
int error; |
61
|
8
|
|
|
|
|
|
git_tree *subtree = NULL; |
62
|
|
|
|
|
|
|
|
63
|
8
|
|
|
|
|
|
*out = NULL; |
64
|
|
|
|
|
|
|
|
65
|
8
|
|
|
|
|
|
error = find_subtree_in_current_level(&subtree, repo, root, target, *fanout); |
66
|
8
|
100
|
|
|
|
|
if (error == GIT_EEXISTS) |
67
|
6
|
|
|
|
|
|
return git_tree_lookup(out, repo, git_tree_id(root)); |
68
|
|
|
|
|
|
|
|
69
|
2
|
50
|
|
|
|
|
if (error < 0) |
70
|
2
|
|
|
|
|
|
return error; |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
*fanout += 2; |
73
|
0
|
|
|
|
|
|
error = find_subtree_r(out, subtree, repo, target, fanout); |
74
|
0
|
|
|
|
|
|
git_tree_free(subtree); |
75
|
|
|
|
|
|
|
|
76
|
8
|
|
|
|
|
|
return error; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
6
|
|
|
|
|
|
static int find_blob(git_oid *blob, git_tree *tree, const char *target) |
80
|
|
|
|
|
|
|
{ |
81
|
|
|
|
|
|
|
size_t i; |
82
|
|
|
|
|
|
|
const git_tree_entry *entry; |
83
|
|
|
|
|
|
|
|
84
|
6
|
50
|
|
|
|
|
for (i=0; i
|
85
|
6
|
|
|
|
|
|
entry = git_tree_entry_byindex(tree, i); |
86
|
|
|
|
|
|
|
|
87
|
6
|
50
|
|
|
|
|
if (!strcmp(git_tree_entry_name(entry), target)) { |
88
|
|
|
|
|
|
|
/* found matching note object - return */ |
89
|
|
|
|
|
|
|
|
90
|
6
|
|
|
|
|
|
git_oid_cpy(blob, git_tree_entry_id(entry)); |
91
|
6
|
|
|
|
|
|
return 0; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
return note_error_notfound(); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
5
|
|
|
|
|
|
static int tree_write( |
99
|
|
|
|
|
|
|
git_tree **out, |
100
|
|
|
|
|
|
|
git_repository *repo, |
101
|
|
|
|
|
|
|
git_tree *source_tree, |
102
|
|
|
|
|
|
|
const git_oid *object_oid, |
103
|
|
|
|
|
|
|
const char *treeentry_name, |
104
|
|
|
|
|
|
|
unsigned int attributes) |
105
|
|
|
|
|
|
|
{ |
106
|
|
|
|
|
|
|
int error; |
107
|
5
|
|
|
|
|
|
git_treebuilder *tb = NULL; |
108
|
|
|
|
|
|
|
const git_tree_entry *entry; |
109
|
|
|
|
|
|
|
git_oid tree_oid; |
110
|
|
|
|
|
|
|
|
111
|
5
|
50
|
|
|
|
|
if ((error = git_treebuilder_new(&tb, repo, source_tree)) < 0) |
112
|
0
|
|
|
|
|
|
goto cleanup; |
113
|
|
|
|
|
|
|
|
114
|
5
|
100
|
|
|
|
|
if (object_oid) { |
115
|
3
|
50
|
|
|
|
|
if ((error = git_treebuilder_insert( |
116
|
|
|
|
|
|
|
&entry, tb, treeentry_name, object_oid, attributes)) < 0) |
117
|
0
|
|
|
|
|
|
goto cleanup; |
118
|
|
|
|
|
|
|
} else { |
119
|
2
|
50
|
|
|
|
|
if ((error = git_treebuilder_remove(tb, treeentry_name)) < 0) |
120
|
0
|
|
|
|
|
|
goto cleanup; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
5
|
50
|
|
|
|
|
if ((error = git_treebuilder_write(&tree_oid, tb)) < 0) |
124
|
0
|
|
|
|
|
|
goto cleanup; |
125
|
|
|
|
|
|
|
|
126
|
5
|
|
|
|
|
|
error = git_tree_lookup(out, repo, &tree_oid); |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
cleanup: |
129
|
5
|
|
|
|
|
|
git_treebuilder_free(tb); |
130
|
5
|
|
|
|
|
|
return error; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
8
|
|
|
|
|
|
static int manipulate_note_in_tree_r( |
134
|
|
|
|
|
|
|
git_tree **out, |
135
|
|
|
|
|
|
|
git_repository *repo, |
136
|
|
|
|
|
|
|
git_tree *parent, |
137
|
|
|
|
|
|
|
git_oid *note_oid, |
138
|
|
|
|
|
|
|
const char *annotated_object_sha, |
139
|
|
|
|
|
|
|
int fanout, |
140
|
|
|
|
|
|
|
int (*note_exists_cb)( |
141
|
|
|
|
|
|
|
git_tree **out, |
142
|
|
|
|
|
|
|
git_repository *repo, |
143
|
|
|
|
|
|
|
git_tree *parent, |
144
|
|
|
|
|
|
|
git_oid *note_oid, |
145
|
|
|
|
|
|
|
const char *annotated_object_sha, |
146
|
|
|
|
|
|
|
int fanout, |
147
|
|
|
|
|
|
|
int current_error), |
148
|
|
|
|
|
|
|
int (*note_notfound_cb)( |
149
|
|
|
|
|
|
|
git_tree **out, |
150
|
|
|
|
|
|
|
git_repository *repo, |
151
|
|
|
|
|
|
|
git_tree *parent, |
152
|
|
|
|
|
|
|
git_oid *note_oid, |
153
|
|
|
|
|
|
|
const char *annotated_object_sha, |
154
|
|
|
|
|
|
|
int fanout, |
155
|
|
|
|
|
|
|
int current_error)) |
156
|
|
|
|
|
|
|
{ |
157
|
|
|
|
|
|
|
int error; |
158
|
8
|
|
|
|
|
|
git_tree *subtree = NULL, *new = NULL; |
159
|
|
|
|
|
|
|
char subtree_name[3]; |
160
|
|
|
|
|
|
|
|
161
|
8
|
|
|
|
|
|
error = find_subtree_in_current_level( |
162
|
|
|
|
|
|
|
&subtree, repo, parent, annotated_object_sha, fanout); |
163
|
|
|
|
|
|
|
|
164
|
8
|
100
|
|
|
|
|
if (error == GIT_EEXISTS) { |
165
|
4
|
|
|
|
|
|
error = note_exists_cb( |
166
|
|
|
|
|
|
|
out, repo, parent, note_oid, annotated_object_sha, fanout, error); |
167
|
4
|
|
|
|
|
|
goto cleanup; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
4
|
50
|
|
|
|
|
if (error == GIT_ENOTFOUND) { |
171
|
4
|
|
|
|
|
|
error = note_notfound_cb( |
172
|
|
|
|
|
|
|
out, repo, parent, note_oid, annotated_object_sha, fanout, error); |
173
|
4
|
|
|
|
|
|
goto cleanup; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
0
|
0
|
|
|
|
|
if (error < 0) |
177
|
0
|
|
|
|
|
|
goto cleanup; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
/* An existing fanout has been found, let's dig deeper */ |
180
|
0
|
|
|
|
|
|
error = manipulate_note_in_tree_r( |
181
|
|
|
|
|
|
|
&new, repo, subtree, note_oid, annotated_object_sha, |
182
|
|
|
|
|
|
|
fanout + 2, note_exists_cb, note_notfound_cb); |
183
|
|
|
|
|
|
|
|
184
|
0
|
0
|
|
|
|
|
if (error < 0) |
185
|
0
|
|
|
|
|
|
goto cleanup; |
186
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
strncpy(subtree_name, annotated_object_sha + fanout, 2); |
188
|
0
|
|
|
|
|
|
subtree_name[2] = '\0'; |
189
|
|
|
|
|
|
|
|
190
|
0
|
|
|
|
|
|
error = tree_write(out, repo, parent, git_tree_id(new), |
191
|
|
|
|
|
|
|
subtree_name, GIT_FILEMODE_TREE); |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
cleanup: |
195
|
8
|
|
|
|
|
|
git_tree_free(new); |
196
|
8
|
|
|
|
|
|
git_tree_free(subtree); |
197
|
8
|
|
|
|
|
|
return error; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
2
|
|
|
|
|
|
static int remove_note_in_tree_eexists_cb( |
201
|
|
|
|
|
|
|
git_tree **out, |
202
|
|
|
|
|
|
|
git_repository *repo, |
203
|
|
|
|
|
|
|
git_tree *parent, |
204
|
|
|
|
|
|
|
git_oid *note_oid, |
205
|
|
|
|
|
|
|
const char *annotated_object_sha, |
206
|
|
|
|
|
|
|
int fanout, |
207
|
|
|
|
|
|
|
int current_error) |
208
|
|
|
|
|
|
|
{ |
209
|
2
|
|
|
|
|
|
GIT_UNUSED(note_oid); |
210
|
2
|
|
|
|
|
|
GIT_UNUSED(current_error); |
211
|
|
|
|
|
|
|
|
212
|
2
|
|
|
|
|
|
return tree_write(out, repo, parent, NULL, annotated_object_sha + fanout, 0); |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
2
|
|
|
|
|
|
static int remove_note_in_tree_enotfound_cb( |
216
|
|
|
|
|
|
|
git_tree **out, |
217
|
|
|
|
|
|
|
git_repository *repo, |
218
|
|
|
|
|
|
|
git_tree *parent, |
219
|
|
|
|
|
|
|
git_oid *note_oid, |
220
|
|
|
|
|
|
|
const char *annotated_object_sha, |
221
|
|
|
|
|
|
|
int fanout, |
222
|
|
|
|
|
|
|
int current_error) |
223
|
|
|
|
|
|
|
{ |
224
|
2
|
|
|
|
|
|
GIT_UNUSED(out); |
225
|
2
|
|
|
|
|
|
GIT_UNUSED(repo); |
226
|
2
|
|
|
|
|
|
GIT_UNUSED(parent); |
227
|
2
|
|
|
|
|
|
GIT_UNUSED(note_oid); |
228
|
2
|
|
|
|
|
|
GIT_UNUSED(fanout); |
229
|
|
|
|
|
|
|
|
230
|
2
|
|
|
|
|
|
git_error_set(GIT_ERROR_REPOSITORY, "object '%s' has no note", annotated_object_sha); |
231
|
2
|
|
|
|
|
|
return current_error; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
1
|
|
|
|
|
|
static int insert_note_in_tree_eexists_cb(git_tree **out, |
235
|
|
|
|
|
|
|
git_repository *repo, |
236
|
|
|
|
|
|
|
git_tree *parent, |
237
|
|
|
|
|
|
|
git_oid *note_oid, |
238
|
|
|
|
|
|
|
const char *annotated_object_sha, |
239
|
|
|
|
|
|
|
int fanout, |
240
|
|
|
|
|
|
|
int current_error) |
241
|
|
|
|
|
|
|
{ |
242
|
1
|
|
|
|
|
|
GIT_UNUSED(out); |
243
|
1
|
|
|
|
|
|
GIT_UNUSED(repo); |
244
|
1
|
|
|
|
|
|
GIT_UNUSED(parent); |
245
|
1
|
|
|
|
|
|
GIT_UNUSED(note_oid); |
246
|
1
|
|
|
|
|
|
GIT_UNUSED(fanout); |
247
|
|
|
|
|
|
|
|
248
|
1
|
|
|
|
|
|
git_error_set(GIT_ERROR_REPOSITORY, "note for '%s' exists already", annotated_object_sha); |
249
|
1
|
|
|
|
|
|
return current_error; |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
|
252
|
3
|
|
|
|
|
|
static int insert_note_in_tree_enotfound_cb(git_tree **out, |
253
|
|
|
|
|
|
|
git_repository *repo, |
254
|
|
|
|
|
|
|
git_tree *parent, |
255
|
|
|
|
|
|
|
git_oid *note_oid, |
256
|
|
|
|
|
|
|
const char *annotated_object_sha, |
257
|
|
|
|
|
|
|
int fanout, |
258
|
|
|
|
|
|
|
int current_error) |
259
|
|
|
|
|
|
|
{ |
260
|
3
|
|
|
|
|
|
GIT_UNUSED(current_error); |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
/* No existing fanout at this level, insert in place */ |
263
|
3
|
|
|
|
|
|
return tree_write( |
264
|
|
|
|
|
|
|
out, |
265
|
|
|
|
|
|
|
repo, |
266
|
|
|
|
|
|
|
parent, |
267
|
|
|
|
|
|
|
note_oid, |
268
|
|
|
|
|
|
|
annotated_object_sha + fanout, |
269
|
|
|
|
|
|
|
GIT_FILEMODE_BLOB); |
270
|
|
|
|
|
|
|
} |
271
|
|
|
|
|
|
|
|
272
|
4
|
|
|
|
|
|
static int note_write( |
273
|
|
|
|
|
|
|
git_oid *notes_commit_out, |
274
|
|
|
|
|
|
|
git_oid *notes_blob_out, |
275
|
|
|
|
|
|
|
git_repository *repo, |
276
|
|
|
|
|
|
|
const git_signature *author, |
277
|
|
|
|
|
|
|
const git_signature *committer, |
278
|
|
|
|
|
|
|
const char *notes_ref, |
279
|
|
|
|
|
|
|
const char *note, |
280
|
|
|
|
|
|
|
git_tree *commit_tree, |
281
|
|
|
|
|
|
|
const char *target, |
282
|
|
|
|
|
|
|
git_commit **parents, |
283
|
|
|
|
|
|
|
int allow_note_overwrite) |
284
|
|
|
|
|
|
|
{ |
285
|
|
|
|
|
|
|
int error; |
286
|
|
|
|
|
|
|
git_oid oid; |
287
|
4
|
|
|
|
|
|
git_tree *tree = NULL; |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
/* TODO: should we apply filters? */ |
290
|
|
|
|
|
|
|
/* create note object */ |
291
|
4
|
50
|
|
|
|
|
if ((error = git_blob_create_from_buffer(&oid, repo, note, strlen(note))) < 0) |
292
|
0
|
|
|
|
|
|
goto cleanup; |
293
|
|
|
|
|
|
|
|
294
|
4
|
100
|
|
|
|
|
if ((error = manipulate_note_in_tree_r( |
|
|
100
|
|
|
|
|
|
295
|
|
|
|
|
|
|
&tree, repo, commit_tree, &oid, target, 0, |
296
|
|
|
|
|
|
|
allow_note_overwrite ? insert_note_in_tree_enotfound_cb : insert_note_in_tree_eexists_cb, |
297
|
|
|
|
|
|
|
insert_note_in_tree_enotfound_cb)) < 0) |
298
|
1
|
|
|
|
|
|
goto cleanup; |
299
|
|
|
|
|
|
|
|
300
|
3
|
50
|
|
|
|
|
if (notes_blob_out) |
301
|
3
|
|
|
|
|
|
git_oid_cpy(notes_blob_out, &oid); |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
|
304
|
3
|
|
|
|
|
|
error = git_commit_create(&oid, repo, notes_ref, author, committer, |
305
|
|
|
|
|
|
|
NULL, GIT_NOTES_DEFAULT_MSG_ADD, |
306
|
3
|
|
|
|
|
|
tree, *parents == NULL ? 0 : 1, (const git_commit **) parents); |
307
|
|
|
|
|
|
|
|
308
|
3
|
50
|
|
|
|
|
if (notes_commit_out) |
309
|
3
|
|
|
|
|
|
git_oid_cpy(notes_commit_out, &oid); |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
cleanup: |
312
|
4
|
|
|
|
|
|
git_tree_free(tree); |
313
|
4
|
|
|
|
|
|
return error; |
314
|
|
|
|
|
|
|
} |
315
|
|
|
|
|
|
|
|
316
|
6
|
|
|
|
|
|
static int note_new( |
317
|
|
|
|
|
|
|
git_note **out, |
318
|
|
|
|
|
|
|
git_oid *note_oid, |
319
|
|
|
|
|
|
|
git_commit *commit, |
320
|
|
|
|
|
|
|
git_blob *blob) |
321
|
|
|
|
|
|
|
{ |
322
|
6
|
|
|
|
|
|
git_note *note = NULL; |
323
|
|
|
|
|
|
|
git_object_size_t blobsize; |
324
|
|
|
|
|
|
|
|
325
|
6
|
|
|
|
|
|
note = git__malloc(sizeof(git_note)); |
326
|
6
|
50
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(note); |
327
|
|
|
|
|
|
|
|
328
|
6
|
|
|
|
|
|
git_oid_cpy(¬e->id, note_oid); |
329
|
|
|
|
|
|
|
|
330
|
12
|
|
|
|
|
|
if (git_signature_dup(¬e->author, git_commit_author(commit)) < 0 || |
331
|
6
|
|
|
|
|
|
git_signature_dup(¬e->committer, git_commit_committer(commit)) < 0) |
332
|
0
|
|
|
|
|
|
return -1; |
333
|
|
|
|
|
|
|
|
334
|
6
|
|
|
|
|
|
blobsize = git_blob_rawsize(blob); |
335
|
6
|
50
|
|
|
|
|
GIT_ERROR_CHECK_BLOBSIZE(blobsize); |
336
|
|
|
|
|
|
|
|
337
|
6
|
|
|
|
|
|
note->message = git__strndup(git_blob_rawcontent(blob), (size_t)blobsize); |
338
|
6
|
50
|
|
|
|
|
GIT_ERROR_CHECK_ALLOC(note->message); |
339
|
|
|
|
|
|
|
|
340
|
6
|
|
|
|
|
|
*out = note; |
341
|
6
|
|
|
|
|
|
return 0; |
342
|
|
|
|
|
|
|
} |
343
|
|
|
|
|
|
|
|
344
|
8
|
|
|
|
|
|
static int note_lookup( |
345
|
|
|
|
|
|
|
git_note **out, |
346
|
|
|
|
|
|
|
git_repository *repo, |
347
|
|
|
|
|
|
|
git_commit *commit, |
348
|
|
|
|
|
|
|
git_tree *tree, |
349
|
|
|
|
|
|
|
const char *target) |
350
|
|
|
|
|
|
|
{ |
351
|
8
|
|
|
|
|
|
int error, fanout = 0; |
352
|
|
|
|
|
|
|
git_oid oid; |
353
|
8
|
|
|
|
|
|
git_blob *blob = NULL; |
354
|
8
|
|
|
|
|
|
git_note *note = NULL; |
355
|
8
|
|
|
|
|
|
git_tree *subtree = NULL; |
356
|
|
|
|
|
|
|
|
357
|
8
|
100
|
|
|
|
|
if ((error = find_subtree_r(&subtree, tree, repo, target, &fanout)) < 0) |
358
|
2
|
|
|
|
|
|
goto cleanup; |
359
|
|
|
|
|
|
|
|
360
|
6
|
50
|
|
|
|
|
if ((error = find_blob(&oid, subtree, target + fanout)) < 0) |
361
|
0
|
|
|
|
|
|
goto cleanup; |
362
|
|
|
|
|
|
|
|
363
|
6
|
50
|
|
|
|
|
if ((error = git_blob_lookup(&blob, repo, &oid)) < 0) |
364
|
0
|
|
|
|
|
|
goto cleanup; |
365
|
|
|
|
|
|
|
|
366
|
6
|
50
|
|
|
|
|
if ((error = note_new(¬e, &oid, commit, blob)) < 0) |
367
|
0
|
|
|
|
|
|
goto cleanup; |
368
|
|
|
|
|
|
|
|
369
|
6
|
|
|
|
|
|
*out = note; |
370
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
cleanup: |
372
|
8
|
|
|
|
|
|
git_tree_free(subtree); |
373
|
8
|
|
|
|
|
|
git_blob_free(blob); |
374
|
8
|
|
|
|
|
|
return error; |
375
|
|
|
|
|
|
|
} |
376
|
|
|
|
|
|
|
|
377
|
4
|
|
|
|
|
|
static int note_remove( |
378
|
|
|
|
|
|
|
git_oid *notes_commit_out, |
379
|
|
|
|
|
|
|
git_repository *repo, |
380
|
|
|
|
|
|
|
const git_signature *author, const git_signature *committer, |
381
|
|
|
|
|
|
|
const char *notes_ref, git_tree *tree, |
382
|
|
|
|
|
|
|
const char *target, git_commit **parents) |
383
|
|
|
|
|
|
|
{ |
384
|
|
|
|
|
|
|
int error; |
385
|
4
|
|
|
|
|
|
git_tree *tree_after_removal = NULL; |
386
|
|
|
|
|
|
|
git_oid oid; |
387
|
|
|
|
|
|
|
|
388
|
4
|
100
|
|
|
|
|
if ((error = manipulate_note_in_tree_r( |
389
|
|
|
|
|
|
|
&tree_after_removal, repo, tree, NULL, target, 0, |
390
|
|
|
|
|
|
|
remove_note_in_tree_eexists_cb, remove_note_in_tree_enotfound_cb)) < 0) |
391
|
2
|
|
|
|
|
|
goto cleanup; |
392
|
|
|
|
|
|
|
|
393
|
2
|
|
|
|
|
|
error = git_commit_create(&oid, repo, notes_ref, author, committer, |
394
|
|
|
|
|
|
|
NULL, GIT_NOTES_DEFAULT_MSG_RM, |
395
|
|
|
|
|
|
|
tree_after_removal, |
396
|
2
|
|
|
|
|
|
*parents == NULL ? 0 : 1, |
397
|
|
|
|
|
|
|
(const git_commit **) parents); |
398
|
|
|
|
|
|
|
|
399
|
2
|
50
|
|
|
|
|
if (error < 0) |
400
|
0
|
|
|
|
|
|
goto cleanup; |
401
|
|
|
|
|
|
|
|
402
|
2
|
50
|
|
|
|
|
if (notes_commit_out) |
403
|
2
|
|
|
|
|
|
git_oid_cpy(notes_commit_out, &oid); |
404
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
cleanup: |
406
|
4
|
|
|
|
|
|
git_tree_free(tree_after_removal); |
407
|
4
|
|
|
|
|
|
return error; |
408
|
|
|
|
|
|
|
} |
409
|
|
|
|
|
|
|
|
410
|
12
|
|
|
|
|
|
static int note_get_default_ref(git_str *out, git_repository *repo) |
411
|
|
|
|
|
|
|
{ |
412
|
|
|
|
|
|
|
git_config *cfg; |
413
|
|
|
|
|
|
|
int error; |
414
|
|
|
|
|
|
|
|
415
|
12
|
50
|
|
|
|
|
if ((error = git_repository_config__weakptr(&cfg, repo)) < 0) |
416
|
0
|
|
|
|
|
|
return error; |
417
|
|
|
|
|
|
|
|
418
|
12
|
|
|
|
|
|
error = git_config__get_string_buf(out, cfg, "core.notesref"); |
419
|
|
|
|
|
|
|
|
420
|
12
|
50
|
|
|
|
|
if (error == GIT_ENOTFOUND) |
421
|
12
|
|
|
|
|
|
error = git_str_puts(out, GIT_NOTES_DEFAULT_REF); |
422
|
|
|
|
|
|
|
|
423
|
12
|
|
|
|
|
|
return error; |
424
|
|
|
|
|
|
|
} |
425
|
|
|
|
|
|
|
|
426
|
17
|
|
|
|
|
|
static int normalize_namespace(git_str *out, git_repository *repo, const char *notes_ref) |
427
|
|
|
|
|
|
|
{ |
428
|
17
|
100
|
|
|
|
|
if (notes_ref) |
429
|
7
|
|
|
|
|
|
return git_str_puts(out, notes_ref); |
430
|
|
|
|
|
|
|
|
431
|
10
|
|
|
|
|
|
return note_get_default_ref(out, repo); |
432
|
|
|
|
|
|
|
} |
433
|
|
|
|
|
|
|
|
434
|
17
|
|
|
|
|
|
static int retrieve_note_commit( |
435
|
|
|
|
|
|
|
git_commit **commit_out, |
436
|
|
|
|
|
|
|
git_str *notes_ref_out, |
437
|
|
|
|
|
|
|
git_repository *repo, |
438
|
|
|
|
|
|
|
const char *notes_ref) |
439
|
|
|
|
|
|
|
{ |
440
|
|
|
|
|
|
|
int error; |
441
|
|
|
|
|
|
|
git_oid oid; |
442
|
|
|
|
|
|
|
|
443
|
17
|
50
|
|
|
|
|
if ((error = normalize_namespace(notes_ref_out, repo, notes_ref)) < 0) |
444
|
0
|
|
|
|
|
|
return error; |
445
|
|
|
|
|
|
|
|
446
|
17
|
100
|
|
|
|
|
if ((error = git_reference_name_to_id(&oid, repo, notes_ref_out->ptr)) < 0) |
447
|
3
|
|
|
|
|
|
return error; |
448
|
|
|
|
|
|
|
|
449
|
14
|
50
|
|
|
|
|
if (git_commit_lookup(commit_out, repo, &oid) < 0) |
450
|
0
|
|
|
|
|
|
return error; |
451
|
|
|
|
|
|
|
|
452
|
17
|
|
|
|
|
|
return 0; |
453
|
|
|
|
|
|
|
} |
454
|
|
|
|
|
|
|
|
455
|
8
|
|
|
|
|
|
int git_note_commit_read( |
456
|
|
|
|
|
|
|
git_note **out, |
457
|
|
|
|
|
|
|
git_repository *repo, |
458
|
|
|
|
|
|
|
git_commit *notes_commit, |
459
|
|
|
|
|
|
|
const git_oid *oid) |
460
|
|
|
|
|
|
|
{ |
461
|
|
|
|
|
|
|
int error; |
462
|
8
|
|
|
|
|
|
git_tree *tree = NULL; |
463
|
|
|
|
|
|
|
char target[GIT_OID_HEXSZ + 1]; |
464
|
|
|
|
|
|
|
|
465
|
8
|
|
|
|
|
|
git_oid_tostr(target, sizeof(target), oid); |
466
|
|
|
|
|
|
|
|
467
|
8
|
50
|
|
|
|
|
if ((error = git_commit_tree(&tree, notes_commit)) < 0) |
468
|
0
|
|
|
|
|
|
goto cleanup; |
469
|
|
|
|
|
|
|
|
470
|
8
|
|
|
|
|
|
error = note_lookup(out, repo, notes_commit, tree, target); |
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
cleanup: |
473
|
8
|
|
|
|
|
|
git_tree_free(tree); |
474
|
8
|
|
|
|
|
|
return error; |
475
|
|
|
|
|
|
|
} |
476
|
|
|
|
|
|
|
|
477
|
8
|
|
|
|
|
|
int git_note_read(git_note **out, git_repository *repo, |
478
|
|
|
|
|
|
|
const char *notes_ref_in, const git_oid *oid) |
479
|
|
|
|
|
|
|
{ |
480
|
|
|
|
|
|
|
int error; |
481
|
8
|
|
|
|
|
|
git_str notes_ref = GIT_STR_INIT; |
482
|
8
|
|
|
|
|
|
git_commit *commit = NULL; |
483
|
|
|
|
|
|
|
|
484
|
8
|
|
|
|
|
|
error = retrieve_note_commit(&commit, ¬es_ref, repo, notes_ref_in); |
485
|
|
|
|
|
|
|
|
486
|
8
|
50
|
|
|
|
|
if (error < 0) |
487
|
0
|
|
|
|
|
|
goto cleanup; |
488
|
|
|
|
|
|
|
|
489
|
8
|
|
|
|
|
|
error = git_note_commit_read(out, repo, commit, oid); |
490
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
cleanup: |
492
|
8
|
|
|
|
|
|
git_str_dispose(¬es_ref); |
493
|
8
|
|
|
|
|
|
git_commit_free(commit); |
494
|
8
|
|
|
|
|
|
return error; |
495
|
|
|
|
|
|
|
} |
496
|
|
|
|
|
|
|
|
497
|
4
|
|
|
|
|
|
int git_note_commit_create( |
498
|
|
|
|
|
|
|
git_oid *notes_commit_out, |
499
|
|
|
|
|
|
|
git_oid *notes_blob_out, |
500
|
|
|
|
|
|
|
git_repository *repo, |
501
|
|
|
|
|
|
|
git_commit *parent, |
502
|
|
|
|
|
|
|
const git_signature *author, |
503
|
|
|
|
|
|
|
const git_signature *committer, |
504
|
|
|
|
|
|
|
const git_oid *oid, |
505
|
|
|
|
|
|
|
const char *note, |
506
|
|
|
|
|
|
|
int allow_note_overwrite) |
507
|
|
|
|
|
|
|
{ |
508
|
|
|
|
|
|
|
int error; |
509
|
4
|
|
|
|
|
|
git_tree *tree = NULL; |
510
|
|
|
|
|
|
|
char target[GIT_OID_HEXSZ + 1]; |
511
|
|
|
|
|
|
|
|
512
|
4
|
|
|
|
|
|
git_oid_tostr(target, sizeof(target), oid); |
513
|
|
|
|
|
|
|
|
514
|
4
|
100
|
|
|
|
|
if (parent != NULL && (error = git_commit_tree(&tree, parent)) < 0) |
|
|
50
|
|
|
|
|
|
515
|
0
|
|
|
|
|
|
goto cleanup; |
516
|
|
|
|
|
|
|
|
517
|
4
|
|
|
|
|
|
error = note_write(notes_commit_out, notes_blob_out, repo, author, |
518
|
|
|
|
|
|
|
committer, NULL, note, tree, target, &parent, allow_note_overwrite); |
519
|
|
|
|
|
|
|
|
520
|
4
|
100
|
|
|
|
|
if (error < 0) |
521
|
1
|
|
|
|
|
|
goto cleanup; |
522
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
cleanup: |
524
|
4
|
|
|
|
|
|
git_tree_free(tree); |
525
|
4
|
|
|
|
|
|
return error; |
526
|
|
|
|
|
|
|
} |
527
|
|
|
|
|
|
|
|
528
|
5
|
|
|
|
|
|
int git_note_create( |
529
|
|
|
|
|
|
|
git_oid *out, |
530
|
|
|
|
|
|
|
git_repository *repo, |
531
|
|
|
|
|
|
|
const char *notes_ref_in, |
532
|
|
|
|
|
|
|
const git_signature *author, |
533
|
|
|
|
|
|
|
const git_signature *committer, |
534
|
|
|
|
|
|
|
const git_oid *oid, |
535
|
|
|
|
|
|
|
const char *note, |
536
|
|
|
|
|
|
|
int allow_note_overwrite) |
537
|
|
|
|
|
|
|
{ |
538
|
|
|
|
|
|
|
int error; |
539
|
5
|
|
|
|
|
|
git_str notes_ref = GIT_STR_INIT; |
540
|
5
|
|
|
|
|
|
git_commit *existing_notes_commit = NULL; |
541
|
5
|
|
|
|
|
|
git_reference *ref = NULL; |
542
|
|
|
|
|
|
|
git_oid notes_blob_oid, notes_commit_oid; |
543
|
|
|
|
|
|
|
|
544
|
5
|
|
|
|
|
|
error = retrieve_note_commit(&existing_notes_commit, ¬es_ref, |
545
|
|
|
|
|
|
|
repo, notes_ref_in); |
546
|
|
|
|
|
|
|
|
547
|
5
|
100
|
|
|
|
|
if (error < 0 && error != GIT_ENOTFOUND) |
|
|
100
|
|
|
|
|
|
548
|
1
|
|
|
|
|
|
goto cleanup; |
549
|
|
|
|
|
|
|
|
550
|
4
|
|
|
|
|
|
error = git_note_commit_create(¬es_commit_oid, |
551
|
|
|
|
|
|
|
¬es_blob_oid, |
552
|
|
|
|
|
|
|
repo, existing_notes_commit, author, |
553
|
|
|
|
|
|
|
committer, oid, note, |
554
|
|
|
|
|
|
|
allow_note_overwrite); |
555
|
4
|
100
|
|
|
|
|
if (error < 0) |
556
|
1
|
|
|
|
|
|
goto cleanup; |
557
|
|
|
|
|
|
|
|
558
|
3
|
|
|
|
|
|
error = git_reference_create(&ref, repo, notes_ref.ptr, |
559
|
|
|
|
|
|
|
¬es_commit_oid, 1, NULL); |
560
|
|
|
|
|
|
|
|
561
|
3
|
50
|
|
|
|
|
if (out != NULL) |
562
|
0
|
|
|
|
|
|
git_oid_cpy(out, ¬es_blob_oid); |
563
|
|
|
|
|
|
|
|
564
|
|
|
|
|
|
|
cleanup: |
565
|
5
|
|
|
|
|
|
git_str_dispose(¬es_ref); |
566
|
5
|
|
|
|
|
|
git_commit_free(existing_notes_commit); |
567
|
5
|
|
|
|
|
|
git_reference_free(ref); |
568
|
5
|
|
|
|
|
|
return error; |
569
|
|
|
|
|
|
|
} |
570
|
|
|
|
|
|
|
|
571
|
4
|
|
|
|
|
|
int git_note_commit_remove( |
572
|
|
|
|
|
|
|
git_oid *notes_commit_out, |
573
|
|
|
|
|
|
|
git_repository *repo, |
574
|
|
|
|
|
|
|
git_commit *notes_commit, |
575
|
|
|
|
|
|
|
const git_signature *author, |
576
|
|
|
|
|
|
|
const git_signature *committer, |
577
|
|
|
|
|
|
|
const git_oid *oid) |
578
|
|
|
|
|
|
|
{ |
579
|
|
|
|
|
|
|
int error; |
580
|
4
|
|
|
|
|
|
git_tree *tree = NULL; |
581
|
|
|
|
|
|
|
char target[GIT_OID_HEXSZ + 1]; |
582
|
|
|
|
|
|
|
|
583
|
4
|
|
|
|
|
|
git_oid_tostr(target, sizeof(target), oid); |
584
|
|
|
|
|
|
|
|
585
|
4
|
50
|
|
|
|
|
if ((error = git_commit_tree(&tree, notes_commit)) < 0) |
586
|
0
|
|
|
|
|
|
goto cleanup; |
587
|
|
|
|
|
|
|
|
588
|
4
|
|
|
|
|
|
error = note_remove(notes_commit_out, |
589
|
|
|
|
|
|
|
repo, author, committer, NULL, tree, target, ¬es_commit); |
590
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
cleanup: |
592
|
4
|
|
|
|
|
|
git_tree_free(tree); |
593
|
4
|
|
|
|
|
|
return error; |
594
|
|
|
|
|
|
|
} |
595
|
|
|
|
|
|
|
|
596
|
4
|
|
|
|
|
|
int git_note_remove(git_repository *repo, const char *notes_ref_in, |
597
|
|
|
|
|
|
|
const git_signature *author, const git_signature *committer, |
598
|
|
|
|
|
|
|
const git_oid *oid) |
599
|
|
|
|
|
|
|
{ |
600
|
|
|
|
|
|
|
int error; |
601
|
4
|
|
|
|
|
|
git_str notes_ref_target = GIT_STR_INIT; |
602
|
4
|
|
|
|
|
|
git_commit *existing_notes_commit = NULL; |
603
|
|
|
|
|
|
|
git_oid new_notes_commit; |
604
|
4
|
|
|
|
|
|
git_reference *notes_ref = NULL; |
605
|
|
|
|
|
|
|
|
606
|
4
|
|
|
|
|
|
error = retrieve_note_commit(&existing_notes_commit, ¬es_ref_target, |
607
|
|
|
|
|
|
|
repo, notes_ref_in); |
608
|
|
|
|
|
|
|
|
609
|
4
|
50
|
|
|
|
|
if (error < 0) |
610
|
0
|
|
|
|
|
|
goto cleanup; |
611
|
|
|
|
|
|
|
|
612
|
4
|
|
|
|
|
|
error = git_note_commit_remove(&new_notes_commit, repo, |
613
|
|
|
|
|
|
|
existing_notes_commit, author, committer, oid); |
614
|
4
|
100
|
|
|
|
|
if (error < 0) |
615
|
2
|
|
|
|
|
|
goto cleanup; |
616
|
|
|
|
|
|
|
|
617
|
2
|
|
|
|
|
|
error = git_reference_create(¬es_ref, repo, notes_ref_target.ptr, |
618
|
|
|
|
|
|
|
&new_notes_commit, 1, NULL); |
619
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
cleanup: |
621
|
4
|
|
|
|
|
|
git_str_dispose(¬es_ref_target); |
622
|
4
|
|
|
|
|
|
git_reference_free(notes_ref); |
623
|
4
|
|
|
|
|
|
git_commit_free(existing_notes_commit); |
624
|
4
|
|
|
|
|
|
return error; |
625
|
|
|
|
|
|
|
} |
626
|
|
|
|
|
|
|
|
627
|
2
|
|
|
|
|
|
int git_note_default_ref(git_buf *out, git_repository *repo) |
628
|
|
|
|
|
|
|
{ |
629
|
2
|
50
|
|
|
|
|
GIT_BUF_WRAP_PRIVATE(out, note_get_default_ref, repo); |
|
|
50
|
|
|
|
|
|
630
|
|
|
|
|
|
|
} |
631
|
|
|
|
|
|
|
|
632
|
1
|
|
|
|
|
|
const git_signature *git_note_committer(const git_note *note) |
633
|
|
|
|
|
|
|
{ |
634
|
1
|
50
|
|
|
|
|
GIT_ASSERT_ARG_WITH_RETVAL(note, NULL); |
635
|
1
|
|
|
|
|
|
return note->committer; |
636
|
|
|
|
|
|
|
} |
637
|
|
|
|
|
|
|
|
638
|
1
|
|
|
|
|
|
const git_signature *git_note_author(const git_note *note) |
639
|
|
|
|
|
|
|
{ |
640
|
1
|
50
|
|
|
|
|
GIT_ASSERT_ARG_WITH_RETVAL(note, NULL); |
641
|
1
|
|
|
|
|
|
return note->author; |
642
|
|
|
|
|
|
|
} |
643
|
|
|
|
|
|
|
|
644
|
3
|
|
|
|
|
|
const char *git_note_message(const git_note *note) |
645
|
|
|
|
|
|
|
{ |
646
|
3
|
50
|
|
|
|
|
GIT_ASSERT_ARG_WITH_RETVAL(note, NULL); |
647
|
3
|
|
|
|
|
|
return note->message; |
648
|
|
|
|
|
|
|
} |
649
|
|
|
|
|
|
|
|
650
|
3
|
|
|
|
|
|
const git_oid *git_note_id(const git_note *note) |
651
|
|
|
|
|
|
|
{ |
652
|
3
|
50
|
|
|
|
|
GIT_ASSERT_ARG_WITH_RETVAL(note, NULL); |
653
|
3
|
|
|
|
|
|
return ¬e->id; |
654
|
|
|
|
|
|
|
} |
655
|
|
|
|
|
|
|
|
656
|
6
|
|
|
|
|
|
void git_note_free(git_note *note) |
657
|
|
|
|
|
|
|
{ |
658
|
6
|
50
|
|
|
|
|
if (note == NULL) |
659
|
0
|
|
|
|
|
|
return; |
660
|
|
|
|
|
|
|
|
661
|
6
|
|
|
|
|
|
git_signature_free(note->committer); |
662
|
6
|
|
|
|
|
|
git_signature_free(note->author); |
663
|
6
|
|
|
|
|
|
git__free(note->message); |
664
|
6
|
|
|
|
|
|
git__free(note); |
665
|
|
|
|
|
|
|
} |
666
|
|
|
|
|
|
|
|
667
|
0
|
|
|
|
|
|
static int process_entry_path( |
668
|
|
|
|
|
|
|
const char *entry_path, |
669
|
|
|
|
|
|
|
git_oid *annotated_object_id) |
670
|
|
|
|
|
|
|
{ |
671
|
0
|
|
|
|
|
|
int error = 0; |
672
|
0
|
|
|
|
|
|
size_t i = 0, j = 0, len; |
673
|
0
|
|
|
|
|
|
git_str buf = GIT_STR_INIT; |
674
|
|
|
|
|
|
|
|
675
|
0
|
0
|
|
|
|
|
if ((error = git_str_puts(&buf, entry_path)) < 0) |
676
|
0
|
|
|
|
|
|
goto cleanup; |
677
|
|
|
|
|
|
|
|
678
|
0
|
|
|
|
|
|
len = git_str_len(&buf); |
679
|
|
|
|
|
|
|
|
680
|
0
|
0
|
|
|
|
|
while (i < len) { |
681
|
0
|
0
|
|
|
|
|
if (buf.ptr[i] == '/') { |
682
|
0
|
|
|
|
|
|
i++; |
683
|
0
|
|
|
|
|
|
continue; |
684
|
|
|
|
|
|
|
} |
685
|
|
|
|
|
|
|
|
686
|
0
|
0
|
|
|
|
|
if (git__fromhex(buf.ptr[i]) < 0) { |
687
|
|
|
|
|
|
|
/* This is not a note entry */ |
688
|
0
|
|
|
|
|
|
goto cleanup; |
689
|
|
|
|
|
|
|
} |
690
|
|
|
|
|
|
|
|
691
|
0
|
0
|
|
|
|
|
if (i != j) |
692
|
0
|
|
|
|
|
|
buf.ptr[j] = buf.ptr[i]; |
693
|
|
|
|
|
|
|
|
694
|
0
|
|
|
|
|
|
i++; |
695
|
0
|
|
|
|
|
|
j++; |
696
|
|
|
|
|
|
|
} |
697
|
|
|
|
|
|
|
|
698
|
0
|
|
|
|
|
|
buf.ptr[j] = '\0'; |
699
|
0
|
|
|
|
|
|
buf.size = j; |
700
|
|
|
|
|
|
|
|
701
|
0
|
0
|
|
|
|
|
if (j != GIT_OID_HEXSZ) { |
702
|
|
|
|
|
|
|
/* This is not a note entry */ |
703
|
0
|
|
|
|
|
|
goto cleanup; |
704
|
|
|
|
|
|
|
} |
705
|
|
|
|
|
|
|
|
706
|
0
|
|
|
|
|
|
error = git_oid_fromstr(annotated_object_id, buf.ptr); |
707
|
|
|
|
|
|
|
|
708
|
|
|
|
|
|
|
cleanup: |
709
|
0
|
|
|
|
|
|
git_str_dispose(&buf); |
710
|
0
|
|
|
|
|
|
return error; |
711
|
|
|
|
|
|
|
} |
712
|
|
|
|
|
|
|
|
713
|
0
|
|
|
|
|
|
int git_note_foreach( |
714
|
|
|
|
|
|
|
git_repository *repo, |
715
|
|
|
|
|
|
|
const char *notes_ref, |
716
|
|
|
|
|
|
|
git_note_foreach_cb note_cb, |
717
|
|
|
|
|
|
|
void *payload) |
718
|
|
|
|
|
|
|
{ |
719
|
|
|
|
|
|
|
int error; |
720
|
0
|
|
|
|
|
|
git_note_iterator *iter = NULL; |
721
|
|
|
|
|
|
|
git_oid note_id, annotated_id; |
722
|
|
|
|
|
|
|
|
723
|
0
|
0
|
|
|
|
|
if ((error = git_note_iterator_new(&iter, repo, notes_ref)) < 0) |
724
|
0
|
|
|
|
|
|
return error; |
725
|
|
|
|
|
|
|
|
726
|
0
|
0
|
|
|
|
|
while (!(error = git_note_next(¬e_id, &annotated_id, iter))) { |
727
|
0
|
0
|
|
|
|
|
if ((error = note_cb(¬e_id, &annotated_id, payload)) != 0) { |
728
|
0
|
|
|
|
|
|
git_error_set_after_callback(error); |
729
|
0
|
|
|
|
|
|
break; |
730
|
|
|
|
|
|
|
} |
731
|
|
|
|
|
|
|
} |
732
|
|
|
|
|
|
|
|
733
|
0
|
0
|
|
|
|
|
if (error == GIT_ITEROVER) |
734
|
0
|
|
|
|
|
|
error = 0; |
735
|
|
|
|
|
|
|
|
736
|
0
|
|
|
|
|
|
git_note_iterator_free(iter); |
737
|
0
|
|
|
|
|
|
return error; |
738
|
|
|
|
|
|
|
} |
739
|
|
|
|
|
|
|
|
740
|
0
|
|
|
|
|
|
void git_note_iterator_free(git_note_iterator *it) |
741
|
|
|
|
|
|
|
{ |
742
|
0
|
0
|
|
|
|
|
if (it == NULL) |
743
|
0
|
|
|
|
|
|
return; |
744
|
|
|
|
|
|
|
|
745
|
0
|
|
|
|
|
|
git_iterator_free(it); |
746
|
|
|
|
|
|
|
} |
747
|
|
|
|
|
|
|
|
748
|
0
|
|
|
|
|
|
int git_note_commit_iterator_new( |
749
|
|
|
|
|
|
|
git_note_iterator **it, |
750
|
|
|
|
|
|
|
git_commit *notes_commit) |
751
|
|
|
|
|
|
|
{ |
752
|
|
|
|
|
|
|
int error; |
753
|
|
|
|
|
|
|
git_tree *tree; |
754
|
|
|
|
|
|
|
|
755
|
0
|
0
|
|
|
|
|
if ((error = git_commit_tree(&tree, notes_commit)) < 0) |
756
|
0
|
|
|
|
|
|
goto cleanup; |
757
|
|
|
|
|
|
|
|
758
|
0
|
0
|
|
|
|
|
if ((error = git_iterator_for_tree(it, tree, NULL)) < 0) |
759
|
0
|
|
|
|
|
|
git_iterator_free(*it); |
760
|
|
|
|
|
|
|
|
761
|
|
|
|
|
|
|
cleanup: |
762
|
0
|
|
|
|
|
|
git_tree_free(tree); |
763
|
|
|
|
|
|
|
|
764
|
0
|
|
|
|
|
|
return error; |
765
|
|
|
|
|
|
|
} |
766
|
|
|
|
|
|
|
|
767
|
0
|
|
|
|
|
|
int git_note_iterator_new( |
768
|
|
|
|
|
|
|
git_note_iterator **it, |
769
|
|
|
|
|
|
|
git_repository *repo, |
770
|
|
|
|
|
|
|
const char *notes_ref_in) |
771
|
|
|
|
|
|
|
{ |
772
|
|
|
|
|
|
|
int error; |
773
|
0
|
|
|
|
|
|
git_commit *commit = NULL; |
774
|
0
|
|
|
|
|
|
git_str notes_ref = GIT_STR_INIT; |
775
|
|
|
|
|
|
|
|
776
|
0
|
|
|
|
|
|
error = retrieve_note_commit(&commit, ¬es_ref, repo, notes_ref_in); |
777
|
0
|
0
|
|
|
|
|
if (error < 0) |
778
|
0
|
|
|
|
|
|
goto cleanup; |
779
|
|
|
|
|
|
|
|
780
|
0
|
|
|
|
|
|
error = git_note_commit_iterator_new(it, commit); |
781
|
|
|
|
|
|
|
|
782
|
|
|
|
|
|
|
cleanup: |
783
|
0
|
|
|
|
|
|
git_str_dispose(¬es_ref); |
784
|
0
|
|
|
|
|
|
git_commit_free(commit); |
785
|
|
|
|
|
|
|
|
786
|
0
|
|
|
|
|
|
return error; |
787
|
|
|
|
|
|
|
} |
788
|
|
|
|
|
|
|
|
789
|
0
|
|
|
|
|
|
int git_note_next( |
790
|
|
|
|
|
|
|
git_oid *note_id, |
791
|
|
|
|
|
|
|
git_oid *annotated_id, |
792
|
|
|
|
|
|
|
git_note_iterator *it) |
793
|
|
|
|
|
|
|
{ |
794
|
|
|
|
|
|
|
int error; |
795
|
|
|
|
|
|
|
const git_index_entry *item; |
796
|
|
|
|
|
|
|
|
797
|
0
|
0
|
|
|
|
|
if ((error = git_iterator_current(&item, it)) < 0) |
798
|
0
|
|
|
|
|
|
return error; |
799
|
|
|
|
|
|
|
|
800
|
0
|
|
|
|
|
|
git_oid_cpy(note_id, &item->id); |
801
|
|
|
|
|
|
|
|
802
|
0
|
0
|
|
|
|
|
if ((error = process_entry_path(item->path, annotated_id)) < 0) |
803
|
0
|
|
|
|
|
|
return error; |
804
|
|
|
|
|
|
|
|
805
|
0
|
0
|
|
|
|
|
if ((error = git_iterator_advance(NULL, it)) < 0 && error != GIT_ITEROVER) |
|
|
0
|
|
|
|
|
|
806
|
0
|
|
|
|
|
|
return error; |
807
|
|
|
|
|
|
|
|
808
|
0
|
|
|
|
|
|
return 0; |
809
|
|
|
|
|
|
|
} |