deps/libgit2/src/libgit2/push.c

filter: Statementstmt 39.7% 111 / 279 Branchbran 27.7% 50 / 180 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 35.0% 161 / 459 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« deps/libgit2/src/libgit2/odb_pack.c ↑ Summary deps/libgit2/src/libgit2/xdiff/xemit.c »
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 "push.h"
9  
10 #include "git2.h"
11  
12 #include "pack.h"
13 #include "pack-objects.h"
14 #include "remote.h"
15 #include "vector.h"
16 #include "tree.h"
17  
18 0 static int push_spec_rref_cmp(const void *a, const void *b)
19 {
20 0 const push_spec *push_spec_a = a, *push_spec_b = b;
21  
22 0 return strcmp(push_spec_a->refspec.dst, push_spec_b->refspec.dst);
23 }
24  
25 0 static int push_status_ref_cmp(const void *a, const void *b)
26 {
27 0 const push_status *push_status_a = a, *push_status_b = b;
28  
29 0 return strcmp(push_status_a->ref, push_status_b->ref);
30 }
31  
32 2 int git_push_new(git_push **out, git_remote *remote, const git_push_options *opts)
33 {
34 git_push *p;
35  
36 2 *out = NULL;
37  
38 2 ▶ GIT_ERROR_CHECK_VERSION(opts, GIT_PUSH_OPTIONS_VERSION, "git_push_options");
Branch: 1 branch
BranchTrueFalseTotal
GIT_ERROR_CHECK_VERSION(opts, GIT_PUSH_OPTIONS_VERSION, "git_push_options"); 0 2 2
39  
40 2 p = git__calloc(1, sizeof(*p));
41 2 ▶ GIT_ERROR_CHECK_ALLOC(p);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ERROR_CHECK_ALLOC(p); 0 2 2
42  
43 2 p->repo = remote->repo;
44 2 p->remote = remote;
45 2 p->report_status = 1;
46 2 ▶ p->pb_parallelism = opts ? opts->pb_parallelism : 1;
Branch: 1 branch
BranchTrueFalseTotal
p->pb_parallelism = opts ? opts->pb_parallelism : 1; 2 0 2
47  
48 2 ▶ if (opts) {
Branch: 1 branch
BranchTrueFalseTotal
if (opts) { 2 0 2
49 2 ▶ GIT_ERROR_CHECK_VERSION(&opts->callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks");
Branch: 1 branch
BranchTrueFalseTotal
GIT_ERROR_CHECK_VERSION(&opts->callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks"); 0 2 2
50 2 memcpy(&p->callbacks, &opts->callbacks, sizeof(git_remote_callbacks));
51 }
52  
53 2 ▶ if (git_vector_init(&p->specs, 0, push_spec_rref_cmp) < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (git_vector_init(&p->specs, 0, push_spec_rref_cmp) < 0) { 0 2 2
54 0 git__free(p);
55 0 return -1;
56 }
57  
58 2 ▶ if (git_vector_init(&p->status, 0, push_status_ref_cmp) < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (git_vector_init(&p->status, 0, push_status_ref_cmp) < 0) { 0 2 2
59 0 git_vector_free(&p->specs);
60 0 git__free(p);
61 0 return -1;
62 }
63  
64 2 ▶ if (git_vector_init(&p->updates, 0, NULL) < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (git_vector_init(&p->updates, 0, NULL) < 0) { 0 2 2
65 0 git_vector_free(&p->status);
66 0 git_vector_free(&p->specs);
67 0 git__free(p);
68 0 return -1;
69 }
70  
71 2 *out = p;
72 2 return 0;
73 }
74  
75 0 static void free_refspec(push_spec *spec)
76 {
77 0 ▶ if (spec == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (spec == NULL) 0 0 0
78 0 return;
79  
80 0 git_refspec__dispose(&spec->refspec);
81 0 git__free(spec);
82 }
83  
84 2 static int check_rref(char *ref)
85 {
86 2 ▶ if (git__prefixcmp(ref, "refs/")) {
Branch: 1 branch
BranchTrueFalseTotal
if (git__prefixcmp(ref, "refs/")) { 0 2 2
87 0 git_error_set(GIT_ERROR_INVALID, "not a valid reference '%s'", ref);
88 0 return -1;
89 }
90  
91 2 return 0;
92 }
93  
94 2 static int check_lref(git_push *push, char *ref)
95 {
96 /* lref must be resolvable to an existing object */
97 git_object *obj;
98 2 int error = git_revparse_single(&obj, push->repo, ref);
99 2 git_object_free(obj);
100  
101 2 ▶ if (!error)
Branch: 1 branch
BranchTrueFalseTotal
if (!error) 2 0 2
102 2 return 0;
103  
104 0 ▶ if (error == GIT_ENOTFOUND)
Branch: 1 branch
BranchTrueFalseTotal
if (error == GIT_ENOTFOUND) 0 0 0
105 0 git_error_set(GIT_ERROR_REFERENCE,
106 "src refspec '%s' does not match any existing object", ref);
107 else
108 0 git_error_set(GIT_ERROR_INVALID, "not a valid reference '%s'", ref);
109 0 return -1;
110 }
111  
112 2 static int parse_refspec(git_push *push, push_spec **spec, const char *str)
113 {
114 push_spec *s;
115  
116 2 *spec = NULL;
117  
118 2 s = git__calloc(1, sizeof(*s));
119 2 ▶ GIT_ERROR_CHECK_ALLOC(s);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ERROR_CHECK_ALLOC(s); 0 2 2
120  
121 2 ▶ if (git_refspec__parse(&s->refspec, str, false) < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (git_refspec__parse(&s->refspec, str, false) < 0) { 0 2 2
122 0 git_error_set(GIT_ERROR_INVALID, "invalid refspec %s", str);
123 0 goto on_error;
124 }
125  
126 4 ▶ if (s->refspec.src && s->refspec.src[0] != '\0' &&
Branch: 1 branch
BranchTrueFalseTotal
if (s->refspec.src && s->refspec.src[0] != '\0' && 2 0 2
127 2 check_lref(push, s->refspec.src) < 0) {
128 0 goto on_error;
129 }
130  
131 2 ▶ if (check_rref(s->refspec.dst) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (check_rref(s->refspec.dst) < 0) 0 2 2
132 0 goto on_error;
133  
134 2 *spec = s;
135 2 return 0;
136  
137 0 on_error:
138 0 free_refspec(s);
139 0 return -1;
140 }
141  
142 2 int git_push_add_refspec(git_push *push, const char *refspec)
143 {
144 push_spec *spec;
145  
146 4 if (parse_refspec(push, &spec, refspec) < 0 ||
147 2 git_vector_insert(&push->specs, spec) < 0)
148 0 return -1;
149  
150 2 return 0;
151 }
152  
153 0 int git_push_update_tips(git_push *push, const git_remote_callbacks *callbacks)
154 {
155 0 git_str remote_ref_name = GIT_STR_INIT;
156 size_t i, j;
157 git_refspec *fetch_spec;
158 0 push_spec *push_spec = NULL;
159 git_reference *remote_ref;
160 push_status *status;
161 0 int error = 0;
162  
163 0 ▶ git_vector_foreach(&push->status, i, status) {
Branch: 1 branch
BranchTrueFalseTotal
git_vector_foreach(&push->status, i, status) { 0 0 0
164 0 int fire_callback = 1;
165  
166 /* Skip unsuccessful updates which have non-empty messages */
167 0 ▶ if (status->msg)
Branch: 1 branch
BranchTrueFalseTotal
if (status->msg) 0 0 0
168 0 continue;
169  
170 /* Find the corresponding remote ref */
171 0 fetch_spec = git_remote__matching_refspec(push->remote, status->ref);
172 0 ▶ if (!fetch_spec)
Branch: 1 branch
BranchTrueFalseTotal
if (!fetch_spec) 0 0 0
173 0 continue;
174  
175 /* Clear the buffer which can be dirty from previous iteration */
176 0 git_str_clear(&remote_ref_name);
177  
178 0 ▶ if ((error = git_refspec__transform(&remote_ref_name, fetch_spec, status->ref)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_refspec__transform(&remote_ref_name, fetch_spec, status->ref)) < 0) 0 0 0
179 0 goto on_error;
180  
181 /* Find matching push ref spec */
182 0 ▶ git_vector_foreach(&push->specs, j, push_spec) {
Branch: 1 branch
BranchTrueFalseTotal
git_vector_foreach(&push->specs, j, push_spec) { 0 0 0
183 0 ▶ if (!strcmp(push_spec->refspec.dst, status->ref))
Branch: 1 branch
BranchTrueFalseTotal
if (!strcmp(push_spec->refspec.dst, status->ref)) 0 0 0
184 0 break;
185 }
186  
187 /* Could not find the corresponding push ref spec for this push update */
188 0 ▶ if (j == push->specs.length)
Branch: 1 branch
BranchTrueFalseTotal
if (j == push->specs.length) 0 0 0
189 0 continue;
190  
191 /* Update the remote ref */
192 0 ▶ if (git_oid_is_zero(&push_spec->loid)) {
Branch: 1 branch
BranchTrueFalseTotal
if (git_oid_is_zero(&push_spec->loid)) { 0 0 0
193 0 error = git_reference_lookup(&remote_ref, push->remote->repo, git_str_cstr(&remote_ref_name));
194  
195 0 ▶ if (error >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (error >= 0) { 0 0 0
196 0 error = git_reference_delete(remote_ref);
197 0 git_reference_free(remote_ref);
198 }
199 } else {
200 0 error = git_reference_create(NULL, push->remote->repo,
201 0 git_str_cstr(&remote_ref_name), &push_spec->loid, 1,
202 "update by push");
203 }
204  
205 0 ▶ if (error < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (error < 0) { 0 0 0
206 0 ▶ if (error != GIT_ENOTFOUND)
Branch: 1 branch
BranchTrueFalseTotal
if (error != GIT_ENOTFOUND) 0 0 0
207 0 goto on_error;
208  
209 0 git_error_clear();
210 0 fire_callback = 0;
211 }
212  
213 0 ▶ if (fire_callback && callbacks && callbacks->update_tips) {
Branch: 3 branches
BranchTrueFalseTotal
if (fire_callback && callbacks && callbacks->update_tips) { 0 0 0
if (fire_callback && callbacks && callbacks->update_tips) { 0 0 0
if (fire_callback && callbacks && callbacks->update_tips) { 0 0 0
214 0 error = callbacks->update_tips(git_str_cstr(&remote_ref_name),
215 0 &push_spec->roid, &push_spec->loid, callbacks->payload);
216  
217 0 ▶ if (error < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (error < 0) 0 0 0
218 0 goto on_error;
219 }
220 }
221  
222 0 error = 0;
223  
224 0 on_error:
225 0 git_str_dispose(&remote_ref_name);
226 0 return error;
227 }
228  
229 /**
230 * Insert all tags until we find a non-tag object, which is returned
231 * in `out`.
232 */
233 0 static int enqueue_tag(git_object **out, git_push *push, git_oid *id)
234 {
235 0 git_object *obj = NULL, *target = NULL;
236 int error;
237  
238 0 ▶ if ((error = git_object_lookup(&obj, push->repo, id, GIT_OBJECT_TAG)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_object_lookup(&obj, push->repo, id, GIT_OBJECT_TAG)) < 0) 0 0 0
239 0 return error;
240  
241 0 ▶ while (git_object_type(obj) == GIT_OBJECT_TAG) {
Branch: 1 branch
BranchTrueFalseTotal
while (git_object_type(obj) == GIT_OBJECT_TAG) { 0 0 0
242 0 ▶ if ((error = git_packbuilder_insert(push->pb, git_object_id(obj), NULL)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_packbuilder_insert(push->pb, git_object_id(obj), NULL)) < 0) 0 0 0
243 0 break;
244  
245 0 ▶ if ((error = git_tag_target(&target, (git_tag *) obj)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_tag_target(&target, (git_tag *) obj)) < 0) 0 0 0
246 0 break;
247  
248 0 git_object_free(obj);
249 0 obj = target;
250 }
251  
252 0 ▶ if (error < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (error < 0) 0 0 0
253 0 git_object_free(obj);
254 else
255 0 *out = obj;
256  
257 0 return error;
258 }
259  
260 2 static int queue_objects(git_push *push)
261 {
262 git_remote_head *head;
263 push_spec *spec;
264 git_revwalk *rw;
265 unsigned int i;
266 2 int error = -1;
267  
268 2 ▶ if (git_revwalk_new(&rw, push->repo) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (git_revwalk_new(&rw, push->repo) < 0) 0 2 2
269 0 return -1;
270  
271 2 git_revwalk_sorting(rw, GIT_SORT_TIME);
272  
273 4 ▶ git_vector_foreach(&push->specs, i, spec) {
Branch: 1 branch
BranchTrueFalseTotal
git_vector_foreach(&push->specs, i, spec) { 2 2 4
274 git_object_t type;
275 size_t size;
276  
277 2 ▶ if (git_oid_is_zero(&spec->loid))
Branch: 1 branch
BranchTrueFalseTotal
if (git_oid_is_zero(&spec->loid)) 0 2 2
278 /*
279 * Delete reference on remote side;
280 * nothing to do here.
281 */
282 2 continue;
283  
284 2 ▶ if (git_oid_equal(&spec->loid, &spec->roid))
Branch: 1 branch
BranchTrueFalseTotal
if (git_oid_equal(&spec->loid, &spec->roid)) 0 2 2
285 0 continue; /* up-to-date */
286  
287 2 ▶ if ((error = git_odb_read_header(&size, &type, push->repo->_odb, &spec->loid)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_odb_read_header(&size, &type, push->repo->_odb, &spec->loid)) < 0) 0 2 2
288 0 goto on_error;
289  
290 2 ▶ if (type == GIT_OBJECT_TAG) {
Branch: 1 branch
BranchTrueFalseTotal
if (type == GIT_OBJECT_TAG) { 0 2 2
291 git_object *target;
292  
293 0 ▶ if ((error = enqueue_tag(&target, push, &spec->loid)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = enqueue_tag(&target, push, &spec->loid)) < 0) 0 0 0
294 0 goto on_error;
295  
296 0 ▶ if (git_object_type(target) == GIT_OBJECT_COMMIT) {
Branch: 1 branch
BranchTrueFalseTotal
if (git_object_type(target) == GIT_OBJECT_COMMIT) { 0 0 0
297 0 ▶ if ((error = git_revwalk_push(rw, git_object_id(target))) < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_revwalk_push(rw, git_object_id(target))) < 0) { 0 0 0
298 0 git_object_free(target);
299 0 goto on_error;
300 }
301 } else {
302 0 ▶ if ((error = git_packbuilder_insert(
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_packbuilder_insert( 0 0 0
303 push->pb, git_object_id(target), NULL)) < 0) {
304 0 git_object_free(target);
305 0 goto on_error;
306 }
307 }
308 0 git_object_free(target);
309 2 ▶ } else if ((error = git_revwalk_push(rw, &spec->loid)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
} else if ((error = git_revwalk_push(rw, &spec->loid)) < 0) 0 2 2
310 0 goto on_error;
311  
312 2 ▶ if (!spec->refspec.force) {
Branch: 1 branch
BranchTrueFalseTotal
if (!spec->refspec.force) { 2 0 2
313 git_oid base;
314  
315 2 ▶ if (git_oid_is_zero(&spec->roid))
Branch: 1 branch
BranchTrueFalseTotal
if (git_oid_is_zero(&spec->roid)) 2 0 2
316 2 continue;
317  
318 0 ▶ if (!git_odb_exists(push->repo->_odb, &spec->roid)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!git_odb_exists(push->repo->_odb, &spec->roid)) { 0 0 0
319 0 git_error_set(GIT_ERROR_REFERENCE,
320 "cannot push because a reference that you are trying to update on the remote contains commits that are not present locally.");
321 0 error = GIT_ENONFASTFORWARD;
322 0 goto on_error;
323 }
324  
325 0 error = git_merge_base(&base, push->repo,
326 0 &spec->loid, &spec->roid);
327  
328 0 ▶ if (error == GIT_ENOTFOUND ||
Branch: 2 branches
BranchTrueFalseTotal
if (error == GIT_ENOTFOUND || 0 0 0
if (error == GIT_ENOTFOUND || 0 0 0
329 0 ▶ (!error && !git_oid_equal(&base, &spec->roid))) {
Branch: 1 branch
BranchTrueFalseTotal
(!error && !git_oid_equal(&base, &spec->roid))) { 0 0 0
330 0 git_error_set(GIT_ERROR_REFERENCE,
331 "cannot push non-fastforwardable reference");
332 0 error = GIT_ENONFASTFORWARD;
333 0 goto on_error;
334 }
335  
336 0 ▶ if (error < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (error < 0) 0 0 0
337 0 goto on_error;
338 }
339 }
340  
341 2 ▶ git_vector_foreach(&push->remote->refs, i, head) {
Branch: 1 branch
BranchTrueFalseTotal
git_vector_foreach(&push->remote->refs, i, head) { 0 2 2
342 0 ▶ if (git_oid_is_zero(&head->oid))
Branch: 1 branch
BranchTrueFalseTotal
if (git_oid_is_zero(&head->oid)) 0 0 0
343 0 continue;
344  
345 0 ▶ if ((error = git_revwalk_hide(rw, &head->oid)) < 0 &&
Branch: 2 branches
BranchTrueFalseTotal
if ((error = git_revwalk_hide(rw, &head->oid)) < 0 && 0 0 0
if ((error = git_revwalk_hide(rw, &head->oid)) < 0 && 0 0 0
346 0 ▶ error != GIT_ENOTFOUND && error != GIT_EINVALIDSPEC && error != GIT_EPEEL)
Branch: 2 branches
BranchTrueFalseTotal
error != GIT_ENOTFOUND && error != GIT_EINVALIDSPEC && error != GIT_EPEEL) 0 0 0
error != GIT_ENOTFOUND && error != GIT_EINVALIDSPEC && error != GIT_EPEEL) 0 0 0
347 0 goto on_error;
348 }
349  
350 2 error = git_packbuilder_insert_walk(push->pb, rw);
351  
352 2 on_error:
353 2 git_revwalk_free(rw);
354 2 return error;
355 }
356  
357 2 static int add_update(git_push *push, push_spec *spec)
358 {
359 2 git_push_update *u = git__calloc(1, sizeof(git_push_update));
360 2 ▶ GIT_ERROR_CHECK_ALLOC(u);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ERROR_CHECK_ALLOC(u); 0 2 2
361  
362 2 u->src_refname = git__strdup(spec->refspec.src);
363 2 ▶ GIT_ERROR_CHECK_ALLOC(u->src_refname);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ERROR_CHECK_ALLOC(u->src_refname); 0 2 2
364  
365 2 u->dst_refname = git__strdup(spec->refspec.dst);
366 2 ▶ GIT_ERROR_CHECK_ALLOC(u->dst_refname);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ERROR_CHECK_ALLOC(u->dst_refname); 0 2 2
367  
368 2 git_oid_cpy(&u->src, &spec->roid);
369 2 git_oid_cpy(&u->dst, &spec->loid);
370  
371 2 return git_vector_insert(&push->updates, u);
372 }
373  
374 2 static int calculate_work(git_push *push)
375 {
376 git_remote_head *head;
377 push_spec *spec;
378 unsigned int i, j;
379  
380 /* Update local and remote oids*/
381  
382 4 ▶ git_vector_foreach(&push->specs, i, spec) {
Branch: 1 branch
BranchTrueFalseTotal
git_vector_foreach(&push->specs, i, spec) { 2 2 4
383 2 ▶ if (spec->refspec.src && spec->refspec.src[0]!= '\0') {
Branch: 2 branches
BranchTrueFalseTotal
if (spec->refspec.src && spec->refspec.src[0]!= '\0') { 2 0 2
if (spec->refspec.src && spec->refspec.src[0]!= '\0') { 2 0 2
384 /* This is a create or update. Local ref must exist. */
385 2 ▶ if (git_reference_name_to_id(
Branch: 1 branch
BranchTrueFalseTotal
if (git_reference_name_to_id( 0 2 2
386 2 &spec->loid, push->repo, spec->refspec.src) < 0) {
387 0 git_error_set(GIT_ERROR_REFERENCE, "no such reference '%s'", spec->refspec.src);
388 0 return -1;
389 }
390 }
391  
392 /* Remote ref may or may not (e.g. during create) already exist. */
393 2 ▶ git_vector_foreach(&push->remote->refs, j, head) {
Branch: 1 branch
BranchTrueFalseTotal
git_vector_foreach(&push->remote->refs, j, head) { 0 2 2
394 0 ▶ if (!strcmp(spec->refspec.dst, head->name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!strcmp(spec->refspec.dst, head->name)) { 0 0 0
395 0 git_oid_cpy(&spec->roid, &head->oid);
396 0 break;
397 }
398 }
399  
400 2 ▶ if (add_update(push, spec) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (add_update(push, spec) < 0) 0 2 2
401 0 return -1;
402 }
403  
404 2 return 0;
405 }
406  
407 2 static int do_push(git_push *push)
408 {
409 2 int error = 0;
410 2 git_transport *transport = push->remote->transport;
411 2 git_remote_callbacks *callbacks = &push->callbacks;
412  
413 2 ▶ if (!transport->push) {
Branch: 1 branch
BranchTrueFalseTotal
if (!transport->push) { 0 2 2
414 0 git_error_set(GIT_ERROR_NET, "remote transport doesn't support push");
415 0 error = -1;
416 0 goto on_error;
417 }
418  
419 /*
420 * A pack-file MUST be sent if either create or update command
421 * is used, even if the server already has all the necessary
422 * objects. In this case the client MUST send an empty pack-file.
423 */
424  
425 2 ▶ if ((error = git_packbuilder_new(&push->pb, push->repo)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_packbuilder_new(&push->pb, push->repo)) < 0) 0 2 2
426 0 goto on_error;
427  
428 2 git_packbuilder_set_threads(push->pb, push->pb_parallelism);
429  
430 2 ▶ if (callbacks && callbacks->pack_progress)
Branch: 2 branches
BranchTrueFalseTotal
if (callbacks && callbacks->pack_progress) 2 0 2
if (callbacks && callbacks->pack_progress) 2 0 2
431 2 ▶ if ((error = git_packbuilder_set_callbacks(push->pb, callbacks->pack_progress, callbacks->payload)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = git_packbuilder_set_callbacks(push->pb, callbacks->pack_progress, callbacks->payload)) < 0) 0 2 2
432 0 goto on_error;
433  
434 2 ▶ if ((error = calculate_work(push)) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((error = calculate_work(push)) < 0) 0 2 2
435 0 goto on_error;
436  
437 2 ▶ if (callbacks && callbacks->push_negotiation &&
Branch: 1 branch
BranchTrueFalseTotal
if (callbacks && callbacks->push_negotiation && 2 0 2
438 0 (error = callbacks->push_negotiation((const git_push_update **) push->updates.contents,
439 push->updates.length, callbacks->payload)) < 0)
440 0 goto on_error;
441  
442 4 if ((error = queue_objects(push)) < 0 ||
443 2 (error = transport->push(transport, push)) < 0)
444 0 goto on_error;
445  
446 2 on_error:
447 2 git_packbuilder_free(push->pb);
448 2 return error;
449 }
450  
451 2 static int filter_refs(git_remote *remote)
452 {
453 const git_remote_head **heads;
454 size_t heads_len, i;
455  
456 2 git_vector_clear(&remote->refs);
457  
458 2 ▶ if (git_remote_ls(&heads, &heads_len, remote) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (git_remote_ls(&heads, &heads_len, remote) < 0) 0 2 2
459 0 return -1;
460  
461 2 ▶ for (i = 0; i < heads_len; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < heads_len; i++) { 0 2 2
462 0 ▶ if (git_vector_insert(&remote->refs, (void *)heads[i]) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (git_vector_insert(&remote->refs, (void *)heads[i]) < 0) 0 0 0
463 0 return -1;
464 }
465  
466 2 return 0;
467 }
468  
469 2 int git_push_finish(git_push *push)
470 {
471 int error;
472  
473 2 ▶ if (!git_remote_connected(push->remote)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!git_remote_connected(push->remote)) { 0 2 2
474 0 git_error_set(GIT_ERROR_NET, "remote is disconnected");
475 0 return -1;
476 }
477  
478 4 if ((error = filter_refs(push->remote)) < 0 ||
479 2 (error = do_push(push)) < 0)
480 0 return error;
481  
482 2 ▶ if (!push->unpack_ok) {
Branch: 1 branch
BranchTrueFalseTotal
if (!push->unpack_ok) { 0 2 2
483 0 error = -1;
484 0 git_error_set(GIT_ERROR_NET, "unpacking the sent packfile failed on the remote");
485 }
486  
487 2 return error;
488 }
489  
490 1 int git_push_status_foreach(git_push *push,
491 int (*cb)(const char *ref, const char *msg, void *data),
492 void *data)
493 {
494 push_status *status;
495 unsigned int i;
496  
497 2 ▶ git_vector_foreach(&push->status, i, status) {
Branch: 1 branch
BranchTrueFalseTotal
git_vector_foreach(&push->status, i, status) { 1 1 2
498 1 int error = cb(status->ref, status->msg, data);
499 1 ▶ if (error)
Branch: 1 branch
BranchTrueFalseTotal
if (error) 0 1 1
500 0 return git_error_set_after_callback(error);
501 }
502  
503 1 return 0;
504 }
505  
506 0 void git_push_status_free(push_status *status)
507 {
508 0 ▶ if (status == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (status == NULL) 0 0 0
509 0 return;
510  
511 0 git__free(status->msg);
512 0 git__free(status->ref);
513 0 git__free(status);
514 }
515  
516 9 void git_push_free(git_push *push)
517 {
518 push_spec *spec;
519 push_status *status;
520 git_push_update *update;
521 unsigned int i;
522  
523 9 ▶ if (push == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (push == NULL) 9 0 9
524 9 return;
525  
526 0 ▶ git_vector_foreach(&push->specs, i, spec) {
Branch: 1 branch
BranchTrueFalseTotal
git_vector_foreach(&push->specs, i, spec) { 0 0 0
527 0 free_refspec(spec);
528 }
529 0 git_vector_free(&push->specs);
530  
531 0 ▶ git_vector_foreach(&push->status, i, status) {
Branch: 1 branch
BranchTrueFalseTotal
git_vector_foreach(&push->status, i, status) { 0 0 0
532 0 git_push_status_free(status);
533 }
534 0 git_vector_free(&push->status);
535  
536 0 ▶ git_vector_foreach(&push->updates, i, update) {
Branch: 1 branch
BranchTrueFalseTotal
git_vector_foreach(&push->updates, i, update) { 0 0 0
537 0 git__free(update->src_refname);
538 0 git__free(update->dst_refname);
539 0 git__free(update);
540 }
541 0 git_vector_free(&push->updates);
542  
543 0 git__free(push);
544 }
545  
546 0 int git_push_options_init(git_push_options *opts, unsigned int version)
547 {
548 0 ▶ GIT_INIT_STRUCTURE_FROM_TEMPLATE(
Branch: 1 branch
BranchTrueFalseTotal
GIT_INIT_STRUCTURE_FROM_TEMPLATE( 0 0 0
549 opts, version, git_push_options, GIT_PUSH_OPTIONS_INIT);
550 0 return 0;
551 }
552  
553 #ifndef GIT_DEPRECATE_HARD
554 0 int git_push_init_options(git_push_options *opts, unsigned int version)
555 {
556 0 return git_push_options_init(opts, version);
557 }
558 #endif
« deps/libgit2/src/libgit2/odb_pack.c ↑ Summary deps/libgit2/src/libgit2/xdiff/xemit.c »