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