]>
Commit | Line | Data |
---|---|---|
e7da9385 | 1 | #define USE_THE_REPOSITORY_VARIABLE |
41f43b82 | 2 | #define DISABLE_SIGN_COMPARE_WARNINGS |
e7da9385 | 3 | |
5579f44d | 4 | #include "git-compat-util.h" |
b2141fc1 | 5 | #include "config.h" |
32a8f510 | 6 | #include "environment.h" |
f394e093 | 7 | #include "gettext.h" |
41771fa4 | 8 | #include "hex.h" |
def88e9a LT |
9 | #include "refs.h" |
10 | #include "pkt-line.h" | |
958c24b1 | 11 | #include "sideband.h" |
109cd76d | 12 | #include "repository.h" |
68cd492a | 13 | #include "object-store.h" |
6f2d7430 | 14 | #include "oid-array.h" |
f6b42a81 | 15 | #include "object.h" |
f0243f26 | 16 | #include "commit.h" |
9b8dc263 JS |
17 | #include "diff.h" |
18 | #include "revision.h" | |
10ac85c7 | 19 | #include "list-objects-filter-options.h" |
cc41fa8d | 20 | #include "run-command.h" |
47a59185 | 21 | #include "connect.h" |
051e4005 | 22 | #include "sigchain.h" |
ff5effdf | 23 | #include "version.h" |
daebaa78 | 24 | #include "string-list.h" |
dbbcd44f | 25 | #include "strvec.h" |
74ea5c95 | 26 | #include "trace2.h" |
aa9bab29 | 27 | #include "protocol.h" |
a3d6b53e | 28 | #include "upload-pack.h" |
829a3215 | 29 | #include "commit-graph.h" |
ba3ca1ed | 30 | #include "commit-reach.h" |
120ad2b0 | 31 | #include "shallow.h" |
d48be35c | 32 | #include "write-or-die.h" |
b8f58c20 | 33 | #include "json-writer.h" |
b065063c | 34 | #include "strmap.h" |
d4602676 | 35 | #include "promisor-remote.h" |
def88e9a | 36 | |
208acbfb | 37 | /* Remember to update object flag allocation in object.h */ |
937a515a JH |
38 | #define THEY_HAVE (1u << 11) |
39 | #define OUR_REF (1u << 12) | |
40 | #define WANTED (1u << 13) | |
41 | #define COMMON_KNOWN (1u << 14) | |
937a515a | 42 | |
f53514bc JS |
43 | #define SHALLOW (1u << 16) |
44 | #define NOT_SHALLOW (1u << 17) | |
45 | #define CLIENT_SHALLOW (1u << 18) | |
390eb36b | 46 | #define HIDDEN_REF (1u << 19) |
f53514bc | 47 | |
d1035cac JT |
48 | #define ALL_FLAGS (THEY_HAVE | OUR_REF | WANTED | COMMON_KNOWN | SHALLOW | \ |
49 | NOT_SHALLOW | CLIENT_SHALLOW | HIDDEN_REF) | |
50 | ||
629060d9 CC |
51 | /* Enum for allowed unadvertised object request (UOR) */ |
52 | enum allow_uor { | |
53 | /* Allow specifying sha1 if it is a ref tip. */ | |
54 | ALLOW_TIP_SHA1 = 0x01, | |
55 | /* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */ | |
56 | ALLOW_REACHABLE_SHA1 = 0x02, | |
57 | /* Allow request of any sha1. Implies ALLOW_TIP_SHA1 and ALLOW_REACHABLE_SHA1. */ | |
58 | ALLOW_ANY_SHA1 = 0x07 | |
59 | }; | |
960deccb | 60 | |
a8497288 CC |
61 | /* |
62 | * Please annotate, and if possible group together, fields used only | |
63 | * for protocol v0 or only for protocol v2. | |
64 | */ | |
e8498322 | 65 | struct upload_pack_data { |
a8497288 | 66 | struct string_list symref; /* v0 only */ |
e8498322 CC |
67 | struct object_array want_obj; |
68 | struct object_array have_obj; | |
b065063c | 69 | struct strmap wanted_refs; /* v2 only */ |
c45841ff | 70 | struct strvec hidden_refs; |
e8498322 CC |
71 | |
72 | struct object_array shallows; | |
388b96df | 73 | struct oidset deepen_not; |
de0e9f74 | 74 | struct object_array extra_edge_obj; |
e8498322 CC |
75 | int depth; |
76 | timestamp_t deepen_since; | |
77 | int deepen_rev_list; | |
78 | int deepen_relative; | |
f203a88c | 79 | int keepalive; |
35b43a10 | 80 | int shallow_nr; |
f01c7916 | 81 | timestamp_t oldest_have; |
e8498322 | 82 | |
d40f04e0 | 83 | unsigned int timeout; /* v0 only */ |
e9d882b8 CC |
84 | enum { |
85 | NO_MULTI_ACK = 0, | |
86 | MULTI_ACK = 1, | |
87 | MULTI_ACK_DETAILED = 2 | |
88 | } multi_ack; /* v0 only */ | |
d40f04e0 | 89 | |
f8edd1ca CC |
90 | /* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */ |
91 | int use_sideband; | |
92 | ||
dd4b732d | 93 | struct string_list uri_protocols; |
629060d9 | 94 | enum allow_uor allow_uor; |
f1514c6a | 95 | |
e8498322 | 96 | struct list_objects_filter_options filter_options; |
6dd3456a | 97 | struct string_list allowed_filters; |
e8498322 CC |
98 | |
99 | struct packet_writer writer; | |
100 | ||
1b261c20 | 101 | char *pack_objects_hook; |
339a9840 | 102 | |
a8497288 | 103 | unsigned stateless_rpc : 1; /* v0 only */ |
d40f04e0 CC |
104 | unsigned no_done : 1; /* v0 only */ |
105 | unsigned daemon_mode : 1; /* v0 only */ | |
59a90261 | 106 | unsigned filter_capability_requested : 1; /* v0 only */ |
e8498322 CC |
107 | |
108 | unsigned use_thin_pack : 1; | |
109 | unsigned use_ofs_delta : 1; | |
110 | unsigned no_progress : 1; | |
111 | unsigned use_include_tag : 1; | |
9c1e657a | 112 | unsigned wait_for_done : 1; |
59abe196 | 113 | unsigned allow_filter : 1; |
6dd3456a | 114 | unsigned allow_filter_fallback : 1; |
5b01a4e8 | 115 | unsigned long tree_filter_max_depth; |
a8497288 CC |
116 | |
117 | unsigned done : 1; /* v2 only */ | |
d1d7a945 | 118 | unsigned allow_ref_in_want : 1; /* v2 only */ |
e3835cd4 | 119 | unsigned allow_sideband_all : 1; /* v2 only */ |
fae96274 | 120 | unsigned seen_haves : 1; /* v2 only */ |
a922bfa3 | 121 | unsigned allow_packfile_uris : 1; /* v2 only */ |
791e1adf | 122 | unsigned advertise_sid : 1; |
933e3a4e | 123 | unsigned sent_capabilities : 1; |
e8498322 CC |
124 | }; |
125 | ||
126 | static void upload_pack_data_init(struct upload_pack_data *data) | |
127 | { | |
438528f6 | 128 | struct string_list symref = STRING_LIST_INIT_DUP; |
b065063c | 129 | struct strmap wanted_refs = STRMAP_INIT; |
c45841ff | 130 | struct strvec hidden_refs = STRVEC_INIT; |
e8498322 CC |
131 | struct object_array want_obj = OBJECT_ARRAY_INIT; |
132 | struct object_array have_obj = OBJECT_ARRAY_INIT; | |
e8498322 | 133 | struct object_array shallows = OBJECT_ARRAY_INIT; |
388b96df | 134 | struct oidset deepen_not = OID_ARRAY_INIT; |
dd4b732d | 135 | struct string_list uri_protocols = STRING_LIST_INIT_DUP; |
de0e9f74 | 136 | struct object_array extra_edge_obj = OBJECT_ARRAY_INIT; |
6dd3456a | 137 | struct string_list allowed_filters = STRING_LIST_INIT_DUP; |
e8498322 CC |
138 | |
139 | memset(data, 0, sizeof(*data)); | |
438528f6 | 140 | data->symref = symref; |
e8498322 | 141 | data->wanted_refs = wanted_refs; |
9b67eb6f | 142 | data->hidden_refs = hidden_refs; |
e8498322 CC |
143 | data->want_obj = want_obj; |
144 | data->have_obj = have_obj; | |
e8498322 CC |
145 | data->shallows = shallows; |
146 | data->deepen_not = deepen_not; | |
dd4b732d | 147 | data->uri_protocols = uri_protocols; |
de0e9f74 | 148 | data->extra_edge_obj = extra_edge_obj; |
6dd3456a TB |
149 | data->allowed_filters = allowed_filters; |
150 | data->allow_filter_fallback = 1; | |
5b01a4e8 | 151 | data->tree_filter_max_depth = ULONG_MAX; |
e8498322 | 152 | packet_writer_init(&data->writer, 1); |
2a01bded | 153 | list_objects_filter_init(&data->filter_options); |
f203a88c CC |
154 | |
155 | data->keepalive = 5; | |
791e1adf | 156 | data->advertise_sid = 0; |
e8498322 CC |
157 | } |
158 | ||
159 | static void upload_pack_data_clear(struct upload_pack_data *data) | |
160 | { | |
438528f6 | 161 | string_list_clear(&data->symref, 1); |
b065063c | 162 | strmap_clear(&data->wanted_refs, 1); |
c45841ff | 163 | strvec_clear(&data->hidden_refs); |
e8498322 CC |
164 | object_array_clear(&data->want_obj); |
165 | object_array_clear(&data->have_obj); | |
e8498322 | 166 | object_array_clear(&data->shallows); |
388b96df | 167 | oidset_clear(&data->deepen_not); |
de0e9f74 | 168 | object_array_clear(&data->extra_edge_obj); |
e8498322 | 169 | list_objects_filter_release(&data->filter_options); |
8d133f50 | 170 | string_list_clear(&data->allowed_filters, 0); |
3b373150 | 171 | string_list_clear(&data->uri_protocols, 0); |
339a9840 CC |
172 | |
173 | free((char *)data->pack_objects_hook); | |
e8498322 CC |
174 | } |
175 | ||
d40f04e0 | 176 | static void reset_timeout(unsigned int timeout) |
960deccb PA |
177 | { |
178 | alarm(timeout); | |
179 | } | |
fb9040cc | 180 | |
f8edd1ca CC |
181 | static void send_client_data(int fd, const char *data, ssize_t sz, |
182 | int use_sideband) | |
583b7ea3 | 183 | { |
4c4b7d1d LF |
184 | if (use_sideband) { |
185 | send_sideband(1, fd, data, sz, use_sideband); | |
fcf0fe9e | 186 | return; |
4c4b7d1d | 187 | } |
958c24b1 JH |
188 | if (fd == 3) |
189 | /* emergency quit */ | |
190 | fd = 2; | |
191 | if (fd == 2) { | |
93822c22 | 192 | /* XXX: are we happy to lose stuff here? */ |
958c24b1 | 193 | xwrite(fd, data, sz); |
fcf0fe9e | 194 | return; |
583b7ea3 | 195 | } |
cdf4fb8e | 196 | write_or_die(fd, data, sz); |
583b7ea3 JH |
197 | } |
198 | ||
b790e0f6 NTND |
199 | static int write_one_shallow(const struct commit_graft *graft, void *cb_data) |
200 | { | |
201 | FILE *fp = cb_data; | |
202 | if (graft->nr_parent == -1) | |
7683e2e6 | 203 | fprintf(fp, "--shallow %s\n", oid_to_hex(&graft->oid)); |
b790e0f6 NTND |
204 | return 0; |
205 | } | |
206 | ||
acaaca7d | 207 | struct output_state { |
55a9651d JV |
208 | /* |
209 | * We do writes no bigger than LARGE_PACKET_DATA_MAX - 1, because with | |
210 | * sideband-64k the band designator takes up 1 byte of space. Because | |
211 | * relay_pack_data keeps the last byte to itself, we make the buffer 1 | |
212 | * byte bigger than the intended maximum write size. | |
213 | */ | |
214 | char buffer[(LARGE_PACKET_DATA_MAX - 1) + 1]; | |
acaaca7d | 215 | int used; |
dd4b732d JT |
216 | unsigned packfile_uris_started : 1; |
217 | unsigned packfile_started : 1; | |
acaaca7d JT |
218 | }; |
219 | ||
220 | static int relay_pack_data(int pack_objects_out, struct output_state *os, | |
dd4b732d | 221 | int use_sideband, int write_packfile_line) |
acaaca7d JT |
222 | { |
223 | /* | |
224 | * We keep the last byte to ourselves | |
225 | * in case we detect broken rev-list, so that we | |
226 | * can leave the stream corrupted. This is | |
227 | * unfortunate -- unpack-objects would happily | |
228 | * accept a valid packdata with trailing garbage, | |
229 | * so appending garbage after we pass all the | |
230 | * pack data is not good enough to signal | |
231 | * breakage to downstream. | |
232 | */ | |
233 | ssize_t readsz; | |
234 | ||
235 | readsz = xread(pack_objects_out, os->buffer + os->used, | |
236 | sizeof(os->buffer) - os->used); | |
237 | if (readsz < 0) { | |
238 | return readsz; | |
239 | } | |
240 | os->used += readsz; | |
241 | ||
dd4b732d JT |
242 | while (!os->packfile_started) { |
243 | char *p; | |
244 | if (os->used >= 4 && !memcmp(os->buffer, "PACK", 4)) { | |
245 | os->packfile_started = 1; | |
246 | if (write_packfile_line) { | |
247 | if (os->packfile_uris_started) | |
248 | packet_delim(1); | |
249 | packet_write_fmt(1, "\1packfile\n"); | |
250 | } | |
251 | break; | |
252 | } | |
253 | if ((p = memchr(os->buffer, '\n', os->used))) { | |
254 | if (!os->packfile_uris_started) { | |
255 | os->packfile_uris_started = 1; | |
256 | if (!write_packfile_line) | |
257 | BUG("packfile_uris requires sideband-all"); | |
258 | packet_write_fmt(1, "\1packfile-uris\n"); | |
259 | } | |
260 | *p = '\0'; | |
261 | packet_write_fmt(1, "\1%s\n", os->buffer); | |
262 | ||
263 | os->used -= p - os->buffer + 1; | |
264 | memmove(os->buffer, p + 1, os->used); | |
265 | } else { | |
266 | /* | |
267 | * Incomplete line. | |
268 | */ | |
269 | return readsz; | |
270 | } | |
271 | } | |
272 | ||
acaaca7d JT |
273 | if (os->used > 1) { |
274 | send_client_data(1, os->buffer, os->used - 1, use_sideband); | |
275 | os->buffer[0] = os->buffer[os->used - 1]; | |
276 | os->used = 1; | |
277 | } else { | |
278 | send_client_data(1, os->buffer, os->used, use_sideband); | |
279 | os->used = 0; | |
280 | } | |
281 | ||
282 | return readsz; | |
283 | } | |
284 | ||
dd4b732d JT |
285 | static void create_pack_file(struct upload_pack_data *pack_data, |
286 | const struct string_list *uri_protocols) | |
fb9040cc | 287 | { |
d3180279 | 288 | struct child_process pack_objects = CHILD_PROCESS_INIT; |
55a9651d | 289 | struct output_state *output_state = xcalloc(1, sizeof(struct output_state)); |
acaaca7d | 290 | char progress[128]; |
583b7ea3 JH |
291 | char abort_msg[] = "aborting due to possible repository " |
292 | "corruption on the remote side."; | |
1456b043 | 293 | ssize_t sz; |
65a3629e | 294 | int i; |
cdab4858 | 295 | FILE *pipe_fd; |
75bfc6c2 | 296 | |
339a9840 | 297 | if (!pack_data->pack_objects_hook) |
20b20a22 JK |
298 | pack_objects.git_cmd = 1; |
299 | else { | |
c972bf4c JK |
300 | strvec_push(&pack_objects.args, pack_data->pack_objects_hook); |
301 | strvec_push(&pack_objects.args, "git"); | |
20b20a22 JK |
302 | pack_objects.use_shell = 1; |
303 | } | |
304 | ||
35b43a10 | 305 | if (pack_data->shallow_nr) { |
c972bf4c JK |
306 | strvec_push(&pack_objects.args, "--shallow-file"); |
307 | strvec_push(&pack_objects.args, ""); | |
f0cea83f | 308 | } |
c972bf4c JK |
309 | strvec_push(&pack_objects.args, "pack-objects"); |
310 | strvec_push(&pack_objects.args, "--revs"); | |
b5a2068c | 311 | if (pack_data->use_thin_pack) |
c972bf4c | 312 | strvec_push(&pack_objects.args, "--thin"); |
75bfc6c2 | 313 | |
c972bf4c | 314 | strvec_push(&pack_objects.args, "--stdout"); |
35b43a10 | 315 | if (pack_data->shallow_nr) |
c972bf4c | 316 | strvec_push(&pack_objects.args, "--shallow"); |
b5a2068c | 317 | if (!pack_data->no_progress) |
c972bf4c | 318 | strvec_push(&pack_objects.args, "--progress"); |
b5a2068c | 319 | if (pack_data->use_ofs_delta) |
c972bf4c | 320 | strvec_push(&pack_objects.args, "--delta-base-offset"); |
b5a2068c | 321 | if (pack_data->use_include_tag) |
c972bf4c | 322 | strvec_push(&pack_objects.args, "--include-tag"); |
d4602676 CC |
323 | if (repo_has_accepted_promisor_remote(the_repository)) |
324 | strvec_push(&pack_objects.args, "--missing=allow-promisor"); | |
c9f03259 | 325 | if (pack_data->filter_options.choice) { |
cf9ceb5a | 326 | const char *spec = |
c9f03259 | 327 | expand_list_objects_filter_spec(&pack_data->filter_options); |
ad5df6b7 | 328 | strvec_pushf(&pack_objects.args, "--filter=%s", spec); |
10ac85c7 | 329 | } |
dd4b732d JT |
330 | if (uri_protocols) { |
331 | for (i = 0; i < uri_protocols->nr; i++) | |
c972bf4c | 332 | strvec_pushf(&pack_objects.args, "--uri-protocol=%s", |
dd4b732d JT |
333 | uri_protocols->items[i].string); |
334 | } | |
cc41fa8d | 335 | |
b9612197 | 336 | pack_objects.in = -1; |
cc41fa8d JS |
337 | pack_objects.out = -1; |
338 | pack_objects.err = -1; | |
309a4028 | 339 | pack_objects.clean_on_exit = 1; |
21edd3f1 | 340 | |
4c324c00 | 341 | if (start_command(&pack_objects)) |
7e44c935 | 342 | die("git upload-pack: unable to fork git-pack-objects"); |
b1c71b72 | 343 | |
cdab4858 NTND |
344 | pipe_fd = xfdopen(pack_objects.in, "w"); |
345 | ||
35b43a10 | 346 | if (pack_data->shallow_nr) |
b790e0f6 NTND |
347 | for_each_commit_graft(write_one_shallow, pipe_fd); |
348 | ||
c9f03259 | 349 | for (i = 0; i < pack_data->want_obj.nr; i++) |
cdab4858 | 350 | fprintf(pipe_fd, "%s\n", |
c9f03259 | 351 | oid_to_hex(&pack_data->want_obj.objects[i].item->oid)); |
cdab4858 | 352 | fprintf(pipe_fd, "--not\n"); |
c9f03259 | 353 | for (i = 0; i < pack_data->have_obj.nr; i++) |
cdab4858 | 354 | fprintf(pipe_fd, "%s\n", |
c9f03259 | 355 | oid_to_hex(&pack_data->have_obj.objects[i].item->oid)); |
de0e9f74 | 356 | for (i = 0; i < pack_data->extra_edge_obj.nr; i++) |
cdab4858 | 357 | fprintf(pipe_fd, "%s\n", |
de0e9f74 | 358 | oid_to_hex(&pack_data->extra_edge_obj.objects[i].item->oid)); |
cdab4858 NTND |
359 | fprintf(pipe_fd, "\n"); |
360 | fflush(pipe_fd); | |
361 | fclose(pipe_fd); | |
f0cea83f | 362 | |
cc41fa8d JS |
363 | /* We read from pack_objects.err to capture stderr output for |
364 | * progress bar, and pack_objects.out to capture the pack data. | |
b1c71b72 | 365 | */ |
b1c71b72 JH |
366 | |
367 | while (1) { | |
b1c71b72 | 368 | struct pollfd pfd[2]; |
f203a88c | 369 | int pe, pu, pollsize, polltimeout; |
05e95155 | 370 | int ret; |
b1c71b72 | 371 | |
d40f04e0 | 372 | reset_timeout(pack_data->timeout); |
0d516ada | 373 | |
b1c71b72 | 374 | pollsize = 0; |
363b7817 | 375 | pe = pu = -1; |
b1c71b72 | 376 | |
cc41fa8d JS |
377 | if (0 <= pack_objects.out) { |
378 | pfd[pollsize].fd = pack_objects.out; | |
b1c71b72 JH |
379 | pfd[pollsize].events = POLLIN; |
380 | pu = pollsize; | |
381 | pollsize++; | |
382 | } | |
cc41fa8d JS |
383 | if (0 <= pack_objects.err) { |
384 | pfd[pollsize].fd = pack_objects.err; | |
363b7817 JH |
385 | pfd[pollsize].events = POLLIN; |
386 | pe = pollsize; | |
387 | pollsize++; | |
388 | } | |
b1c71b72 | 389 | |
4c324c00 JS |
390 | if (!pollsize) |
391 | break; | |
392 | ||
f203a88c CC |
393 | polltimeout = pack_data->keepalive < 0 |
394 | ? -1 | |
395 | : 1000 * pack_data->keepalive; | |
396 | ||
397 | ret = poll(pfd, pollsize, polltimeout); | |
6c71f8b0 | 398 | |
05e95155 | 399 | if (ret < 0) { |
4c324c00 | 400 | if (errno != EINTR) { |
d2b6afa2 | 401 | error_errno("poll failed, resuming"); |
4c324c00 | 402 | sleep(1); |
b1c71b72 | 403 | } |
4c324c00 JS |
404 | continue; |
405 | } | |
6b59f51b NP |
406 | if (0 <= pe && (pfd[pe].revents & (POLLIN|POLLHUP))) { |
407 | /* Status ready; we ship that in the side-band | |
408 | * or dump to the standard error. | |
409 | */ | |
410 | sz = xread(pack_objects.err, progress, | |
411 | sizeof(progress)); | |
412 | if (0 < sz) | |
f8edd1ca CC |
413 | send_client_data(2, progress, sz, |
414 | pack_data->use_sideband); | |
6b59f51b NP |
415 | else if (sz == 0) { |
416 | close(pack_objects.err); | |
417 | pack_objects.err = -1; | |
418 | } | |
419 | else | |
420 | goto fail; | |
421 | /* give priority to status messages */ | |
422 | continue; | |
423 | } | |
4c324c00 | 424 | if (0 <= pu && (pfd[pu].revents & (POLLIN|POLLHUP))) { |
acaaca7d | 425 | int result = relay_pack_data(pack_objects.out, |
55a9651d | 426 | output_state, |
dd4b732d JT |
427 | pack_data->use_sideband, |
428 | !!uri_protocols); | |
acaaca7d JT |
429 | |
430 | if (result == 0) { | |
4c324c00 JS |
431 | close(pack_objects.out); |
432 | pack_objects.out = -1; | |
acaaca7d | 433 | } else if (result < 0) { |
4c324c00 | 434 | goto fail; |
b1c71b72 | 435 | } |
4c324c00 | 436 | } |
05e95155 JK |
437 | |
438 | /* | |
439 | * We hit the keepalive timeout without saying anything; send | |
440 | * an empty message on the data sideband just to let the other | |
441 | * side know we're still working on it, but don't have any data | |
442 | * yet. | |
443 | * | |
444 | * If we don't have a sideband channel, there's no room in the | |
445 | * protocol to say anything, so those clients are just out of | |
446 | * luck. | |
447 | */ | |
f8edd1ca | 448 | if (!ret && pack_data->use_sideband) { |
05e95155 JK |
449 | static const char buf[] = "0005\1"; |
450 | write_or_die(1, buf, 5); | |
451 | } | |
4c324c00 | 452 | } |
b1c71b72 | 453 | |
4c324c00 | 454 | if (finish_command(&pack_objects)) { |
7e44c935 | 455 | error("git upload-pack: git-pack-objects died with error."); |
4c324c00 JS |
456 | goto fail; |
457 | } | |
b1c71b72 | 458 | |
4c324c00 | 459 | /* flush the data */ |
55a9651d JV |
460 | if (output_state->used > 0) { |
461 | send_client_data(1, output_state->buffer, output_state->used, | |
f8edd1ca | 462 | pack_data->use_sideband); |
4c324c00 | 463 | fprintf(stderr, "flushed.\n"); |
b1c71b72 | 464 | } |
55a9651d | 465 | free(output_state); |
f8edd1ca | 466 | if (pack_data->use_sideband) |
4c324c00 JS |
467 | packet_flush(1); |
468 | return; | |
469 | ||
b1c71b72 | 470 | fail: |
c68d5dbc | 471 | free(output_state); |
3f4c7a08 | 472 | send_client_data(3, abort_msg, strlen(abort_msg), |
f8edd1ca | 473 | pack_data->use_sideband); |
7e44c935 | 474 | die("git upload-pack: %s", abort_msg); |
fb9040cc LT |
475 | } |
476 | ||
ea2c6e60 | 477 | static int do_got_oid(struct upload_pack_data *data, const struct object_id *oid) |
def88e9a | 478 | { |
937a515a | 479 | int we_knew_they_have = 0; |
a6ca601c | 480 | struct object *o = parse_object_with_flags(the_repository, oid, |
6cd05e76 JK |
481 | PARSE_OBJECT_SKIP_HASH_CHECK | |
482 | PARSE_OBJECT_DISCARD_TREE); | |
b1e9fff7 | 483 | |
b1e9fff7 | 484 | if (!o) |
cf93982f | 485 | die("oops (%s)", oid_to_hex(oid)); |
182a8dab | 486 | if (o->type == OBJ_COMMIT) { |
b1e9fff7 | 487 | struct commit_list *parents; |
937a515a | 488 | struct commit *commit = (struct commit *)o; |
b1e9fff7 | 489 | if (o->flags & THEY_HAVE) |
937a515a JH |
490 | we_knew_they_have = 1; |
491 | else | |
492 | o->flags |= THEY_HAVE; | |
f01c7916 CC |
493 | if (!data->oldest_have || (commit->date < data->oldest_have)) |
494 | data->oldest_have = commit->date; | |
937a515a | 495 | for (parents = commit->parents; |
b1e9fff7 JH |
496 | parents; |
497 | parents = parents->next) | |
498 | parents->item->object.flags |= THEY_HAVE; | |
fb9040cc | 499 | } |
937a515a | 500 | if (!we_knew_they_have) { |
460ed0d4 | 501 | add_object_array(o, NULL, &data->have_obj); |
937a515a JH |
502 | return 1; |
503 | } | |
504 | return 0; | |
505 | } | |
506 | ||
ea2c6e60 CC |
507 | static int got_oid(struct upload_pack_data *data, |
508 | const char *hex, struct object_id *oid) | |
509 | { | |
510 | if (get_oid_hex(hex, oid)) | |
511 | die("git upload-pack: expected SHA1 object, got '%s'", hex); | |
062b914c | 512 | if (!has_object(the_repository, oid, 0)) |
ea2c6e60 CC |
513 | return -1; |
514 | return do_got_oid(data, oid); | |
515 | } | |
516 | ||
08667348 | 517 | static int ok_to_give_up(struct upload_pack_data *data) |
937a515a | 518 | { |
d7f92784 | 519 | timestamp_t min_generation = GENERATION_NUMBER_ZERO; |
937a515a | 520 | |
08667348 | 521 | if (!data->have_obj.nr) |
937a515a JH |
522 | return 0; |
523 | ||
08667348 | 524 | return can_all_from_reach_with_flag(&data->want_obj, THEY_HAVE, |
f01c7916 | 525 | COMMON_KNOWN, data->oldest_have, |
4fbcca4e | 526 | min_generation); |
def88e9a LT |
527 | } |
528 | ||
07977695 CC |
529 | static int get_common_commits(struct upload_pack_data *data, |
530 | struct packet_reader *reader) | |
def88e9a | 531 | { |
cf93982f | 532 | struct object_id oid; |
533 | char last_hex[GIT_MAX_HEXSZ + 1]; | |
49bee717 SP |
534 | int got_common = 0; |
535 | int got_other = 0; | |
4e10cf9a | 536 | int sent_ready = 0; |
def88e9a | 537 | |
eeefa7c9 | 538 | for (;;) { |
8bf3b758 NTND |
539 | const char *arg; |
540 | ||
d40f04e0 | 541 | reset_timeout(data->timeout); |
def88e9a | 542 | |
01f9ec64 | 543 | if (packet_reader_read(reader) != PACKET_READ_NORMAL) { |
e9d882b8 | 544 | if (data->multi_ack == MULTI_ACK_DETAILED |
07977695 CC |
545 | && got_common |
546 | && !got_other | |
08667348 | 547 | && ok_to_give_up(data)) { |
4e10cf9a | 548 | sent_ready = 1; |
81c634e9 | 549 | packet_write_fmt(1, "ACK %s ready\n", last_hex); |
4e10cf9a | 550 | } |
53d69506 | 551 | if (data->have_obj.nr == 0 || data->multi_ack) |
81c634e9 | 552 | packet_write_fmt(1, "NAK\n"); |
4e10cf9a | 553 | |
d40f04e0 | 554 | if (data->no_done && sent_ready) { |
81c634e9 | 555 | packet_write_fmt(1, "ACK %s\n", last_hex); |
4e10cf9a JH |
556 | return 0; |
557 | } | |
df654abc | 558 | if (data->stateless_rpc) |
42526b47 | 559 | exit(0); |
49bee717 SP |
560 | got_common = 0; |
561 | got_other = 0; | |
def88e9a LT |
562 | continue; |
563 | } | |
01f9ec64 | 564 | if (skip_prefix(reader->line, "have ", &arg)) { |
460ed0d4 | 565 | switch (got_oid(data, arg, &oid)) { |
937a515a | 566 | case -1: /* they have what we do not */ |
49bee717 | 567 | got_other = 1; |
53d69506 | 568 | if (data->multi_ack |
08667348 | 569 | && ok_to_give_up(data)) { |
cf93982f | 570 | const char *hex = oid_to_hex(&oid); |
e9d882b8 | 571 | if (data->multi_ack == MULTI_ACK_DETAILED) { |
4e10cf9a | 572 | sent_ready = 1; |
81c634e9 | 573 | packet_write_fmt(1, "ACK %s ready\n", hex); |
4e10cf9a | 574 | } else |
81c634e9 | 575 | packet_write_fmt(1, "ACK %s continue\n", hex); |
78affc49 | 576 | } |
937a515a JH |
577 | break; |
578 | default: | |
49bee717 | 579 | got_common = 1; |
55dc227d | 580 | oid_to_hex_r(last_hex, &oid); |
e9d882b8 | 581 | if (data->multi_ack == MULTI_ACK_DETAILED) |
81c634e9 | 582 | packet_write_fmt(1, "ACK %s common\n", last_hex); |
53d69506 | 583 | else if (data->multi_ack) |
81c634e9 | 584 | packet_write_fmt(1, "ACK %s continue\n", last_hex); |
07977695 | 585 | else if (data->have_obj.nr == 1) |
81c634e9 | 586 | packet_write_fmt(1, "ACK %s\n", last_hex); |
937a515a | 587 | break; |
af2d3aa4 | 588 | } |
def88e9a LT |
589 | continue; |
590 | } | |
01f9ec64 | 591 | if (!strcmp(reader->line, "done")) { |
07977695 | 592 | if (data->have_obj.nr > 0) { |
53d69506 | 593 | if (data->multi_ack) |
81c634e9 | 594 | packet_write_fmt(1, "ACK %s\n", last_hex); |
1bd8c8f0 JS |
595 | return 0; |
596 | } | |
81c634e9 | 597 | packet_write_fmt(1, "NAK\n"); |
def88e9a LT |
598 | return -1; |
599 | } | |
01f9ec64 | 600 | die("git upload-pack: expected SHA1 list, got '%s'", reader->line); |
def88e9a | 601 | } |
def88e9a LT |
602 | } |
603 | ||
18b6b1b5 TB |
604 | static int allow_hidden_refs(enum allow_uor allow_uor) |
605 | { | |
606 | if ((allow_uor & ALLOW_ANY_SHA1) == ALLOW_ANY_SHA1) | |
607 | return 1; | |
608 | return !(allow_uor & (ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1)); | |
609 | } | |
610 | ||
611 | static void for_each_namespaced_ref_1(each_ref_fn fn, | |
612 | struct upload_pack_data *data) | |
613 | { | |
614 | const char **excludes = NULL; | |
615 | /* | |
616 | * If `data->allow_uor` allows fetching hidden refs, we need to | |
617 | * mark all references (including hidden ones), to check in | |
618 | * `is_our_ref()` below. | |
619 | * | |
620 | * Otherwise, we only care about whether each reference's object | |
621 | * has the OUR_REF bit set or not, so do not need to visit | |
622 | * hidden references. | |
623 | */ | |
624 | if (allow_hidden_refs(data->allow_uor)) | |
625 | excludes = hidden_refs_to_excludes(&data->hidden_refs); | |
626 | ||
2e5c4758 PS |
627 | refs_for_each_namespaced_ref(get_main_ref_store(the_repository), |
628 | excludes, fn, data); | |
18b6b1b5 TB |
629 | } |
630 | ||
631 | ||
629060d9 | 632 | static int is_our_ref(struct object *o, enum allow_uor allow_uor) |
390eb36b | 633 | { |
18b6b1b5 | 634 | return o->flags & ((allow_hidden_refs(allow_uor) ? 0 : HIDDEN_REF) | OUR_REF); |
390eb36b JH |
635 | } |
636 | ||
2997178e NTND |
637 | /* |
638 | * on successful case, it's up to the caller to close cmd->out | |
639 | */ | |
640 | static int do_reachable_revlist(struct child_process *cmd, | |
079aa97e | 641 | struct object_array *src, |
f1514c6a | 642 | struct object_array *reachable, |
629060d9 | 643 | enum allow_uor allow_uor) |
051e4005 | 644 | { |
051e4005 | 645 | struct object *o; |
a698d67b | 646 | FILE *cmd_in = NULL; |
051e4005 JH |
647 | int i; |
648 | ||
2b709893 | 649 | strvec_pushl(&cmd->args, "rev-list", "--stdin", NULL); |
2997178e NTND |
650 | cmd->git_cmd = 1; |
651 | cmd->no_stderr = 1; | |
652 | cmd->in = -1; | |
653 | cmd->out = -1; | |
051e4005 JH |
654 | |
655 | /* | |
7fcbd37f NTND |
656 | * If the next rev-list --stdin encounters an unknown commit, |
657 | * it terminates, which will cause SIGPIPE in the write loop | |
051e4005 JH |
658 | * below. |
659 | */ | |
660 | sigchain_push(SIGPIPE, SIG_IGN); | |
661 | ||
2997178e | 662 | if (start_command(cmd)) |
7fcbd37f NTND |
663 | goto error; |
664 | ||
a698d67b RS |
665 | cmd_in = xfdopen(cmd->in, "w"); |
666 | ||
74d414c9 PS |
667 | for (i = get_max_object_index(the_repository); 0 < i; ) { |
668 | o = get_indexed_object(the_repository, --i); | |
2a745324 BH |
669 | if (!o) |
670 | continue; | |
079aa97e NTND |
671 | if (reachable && o->type == OBJ_COMMIT) |
672 | o->flags &= ~TMP_MARK; | |
629060d9 | 673 | if (!is_our_ref(o, allow_uor)) |
051e4005 | 674 | continue; |
a698d67b | 675 | if (fprintf(cmd_in, "^%s\n", oid_to_hex(&o->oid)) < 0) |
051e4005 JH |
676 | goto error; |
677 | } | |
3f0f6624 NTND |
678 | for (i = 0; i < src->nr; i++) { |
679 | o = src->objects[i].item; | |
629060d9 | 680 | if (is_our_ref(o, allow_uor)) { |
079aa97e NTND |
681 | if (reachable) |
682 | add_object_array(o, NULL, reachable); | |
051e4005 | 683 | continue; |
079aa97e NTND |
684 | } |
685 | if (reachable && o->type == OBJ_COMMIT) | |
686 | o->flags |= TMP_MARK; | |
a698d67b | 687 | if (fprintf(cmd_in, "%s\n", oid_to_hex(&o->oid)) < 0) |
051e4005 JH |
688 | goto error; |
689 | } | |
a698d67b RS |
690 | if (ferror(cmd_in) || fflush(cmd_in)) |
691 | goto error; | |
692 | fclose(cmd_in); | |
2997178e NTND |
693 | cmd->in = -1; |
694 | sigchain_pop(SIGPIPE); | |
051e4005 | 695 | |
2997178e NTND |
696 | return 0; |
697 | ||
698 | error: | |
051e4005 JH |
699 | sigchain_pop(SIGPIPE); |
700 | ||
a698d67b RS |
701 | if (cmd_in) |
702 | fclose(cmd_in); | |
2997178e NTND |
703 | if (cmd->out >= 0) |
704 | close(cmd->out); | |
705 | return -1; | |
706 | } | |
707 | ||
f1514c6a | 708 | static int get_reachable_list(struct upload_pack_data *data, |
079aa97e NTND |
709 | struct object_array *reachable) |
710 | { | |
711 | struct child_process cmd = CHILD_PROCESS_INIT; | |
712 | int i; | |
713 | struct object *o; | |
55dc227d | 714 | char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */ |
715 | const unsigned hexsz = the_hash_algo->hexsz; | |
ac2e7d54 | 716 | int ret; |
079aa97e | 717 | |
f1514c6a | 718 | if (do_reachable_revlist(&cmd, &data->shallows, reachable, |
ac2e7d54 PS |
719 | data->allow_uor) < 0) { |
720 | ret = -1; | |
721 | goto out; | |
722 | } | |
079aa97e | 723 | |
55dc227d | 724 | while ((i = read_in_full(cmd.out, namebuf, hexsz + 1)) == hexsz + 1) { |
62b89d43 | 725 | struct object_id oid; |
55dc227d | 726 | const char *p; |
079aa97e | 727 | |
62b89d43 | 728 | if (parse_oid_hex(namebuf, &oid, &p) || *p != '\n') |
079aa97e NTND |
729 | break; |
730 | ||
d0229abd | 731 | o = lookup_object(the_repository, &oid); |
079aa97e NTND |
732 | if (o && o->type == OBJ_COMMIT) { |
733 | o->flags &= ~TMP_MARK; | |
734 | } | |
735 | } | |
74d414c9 PS |
736 | for (i = get_max_object_index(the_repository); 0 < i; i--) { |
737 | o = get_indexed_object(the_repository, i - 1); | |
079aa97e NTND |
738 | if (o && o->type == OBJ_COMMIT && |
739 | (o->flags & TMP_MARK)) { | |
740 | add_object_array(o, NULL, reachable); | |
741 | o->flags &= ~TMP_MARK; | |
742 | } | |
743 | } | |
744 | close(cmd.out); | |
745 | ||
ac2e7d54 PS |
746 | if (finish_command(&cmd)) { |
747 | ret = -1; | |
748 | goto out; | |
749 | } | |
079aa97e | 750 | |
ac2e7d54 PS |
751 | ret = 0; |
752 | ||
753 | out: | |
754 | child_process_clear(&cmd); | |
755 | return ret; | |
079aa97e NTND |
756 | } |
757 | ||
629060d9 | 758 | static int has_unreachable(struct object_array *src, enum allow_uor allow_uor) |
2997178e NTND |
759 | { |
760 | struct child_process cmd = CHILD_PROCESS_INIT; | |
761 | char buf[1]; | |
762 | int i; | |
763 | ||
629060d9 | 764 | if (do_reachable_revlist(&cmd, src, NULL, allow_uor) < 0) |
ac2e7d54 | 765 | goto error; |
051e4005 JH |
766 | |
767 | /* | |
768 | * The commits out of the rev-list are not ancestors of | |
769 | * our ref. | |
770 | */ | |
2997178e | 771 | i = read_in_full(cmd.out, buf, 1); |
051e4005 JH |
772 | if (i) |
773 | goto error; | |
774 | close(cmd.out); | |
7fcbd37f | 775 | cmd.out = -1; |
051e4005 JH |
776 | |
777 | /* | |
778 | * rev-list may have died by encountering a bad commit | |
779 | * in the history, in which case we do want to bail out | |
780 | * even when it showed no commit. | |
781 | */ | |
782 | if (finish_command(&cmd)) | |
783 | goto error; | |
784 | ||
785 | /* All the non-tip ones are ancestors of what we advertised */ | |
3f0f6624 | 786 | return 0; |
051e4005 JH |
787 | |
788 | error: | |
7fcbd37f NTND |
789 | if (cmd.out >= 0) |
790 | close(cmd.out); | |
ac2e7d54 | 791 | child_process_clear(&cmd); |
3f0f6624 NTND |
792 | return 1; |
793 | } | |
7fcbd37f | 794 | |
b08c9742 | 795 | static void check_non_tip(struct upload_pack_data *data) |
3f0f6624 NTND |
796 | { |
797 | int i; | |
798 | ||
799 | /* | |
800 | * In the normal in-process case without | |
801 | * uploadpack.allowReachableSHA1InWant, | |
802 | * non-tip requests can never happen. | |
803 | */ | |
629060d9 | 804 | if (!data->stateless_rpc && !(data->allow_uor & ALLOW_REACHABLE_SHA1)) |
3f0f6624 | 805 | goto error; |
629060d9 | 806 | if (!has_unreachable(&data->want_obj, data->allow_uor)) |
3f0f6624 NTND |
807 | /* All the non-tip ones are ancestors of what we advertised */ |
808 | return; | |
051e4005 JH |
809 | |
810 | error: | |
811 | /* Pick one of them (we know there at least is one) */ | |
b08c9742 CC |
812 | for (i = 0; i < data->want_obj.nr; i++) { |
813 | struct object *o = data->want_obj.objects[i].item; | |
629060d9 | 814 | if (!is_our_ref(o, data->allow_uor)) { |
7ba7c52d DS |
815 | error("git upload-pack: not our ref %s", |
816 | oid_to_hex(&o->oid)); | |
b08c9742 | 817 | packet_writer_error(&data->writer, |
014ade74 JK |
818 | "upload-pack: not our ref %s", |
819 | oid_to_hex(&o->oid)); | |
5f33a843 | 820 | exit(128); |
014ade74 | 821 | } |
051e4005 JH |
822 | } |
823 | } | |
824 | ||
35b43a10 | 825 | static void send_shallow(struct upload_pack_data *data, |
bc2e795c | 826 | struct commit_list *result) |
5c24cdea NTND |
827 | { |
828 | while (result) { | |
829 | struct object *object = &result->item->object; | |
830 | if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) { | |
35b43a10 | 831 | packet_writer_write(&data->writer, "shallow %s", |
bc2e795c | 832 | oid_to_hex(&object->oid)); |
19143f13 | 833 | register_shallow(the_repository, &object->oid); |
35b43a10 | 834 | data->shallow_nr++; |
5c24cdea NTND |
835 | } |
836 | result = result->next; | |
837 | } | |
838 | } | |
839 | ||
329f9960 | 840 | static void send_unshallow(struct upload_pack_data *data) |
e8e44de7 | 841 | { |
e8e44de7 | 842 | int i; |
873700c9 | 843 | |
329f9960 CC |
844 | for (i = 0; i < data->shallows.nr; i++) { |
845 | struct object *object = data->shallows.objects[i].item; | |
e8e44de7 NTND |
846 | if (object->flags & NOT_SHALLOW) { |
847 | struct commit_list *parents; | |
329f9960 | 848 | packet_writer_write(&data->writer, "unshallow %s", |
bc2e795c | 849 | oid_to_hex(&object->oid)); |
e8e44de7 | 850 | object->flags &= ~CLIENT_SHALLOW; |
873700c9 NTND |
851 | /* |
852 | * We want to _register_ "object" as shallow, but we | |
853 | * also need to traverse object's parents to deepen a | |
854 | * shallow clone. Unregister it for now so we can | |
855 | * parse and add the parents to the want list, then | |
856 | * re-register it. | |
857 | */ | |
e92b848c | 858 | unregister_shallow(&object->oid); |
e8e44de7 NTND |
859 | object->parsed = 0; |
860 | parse_commit_or_die((struct commit *)object); | |
861 | parents = ((struct commit *)object)->parents; | |
862 | while (parents) { | |
863 | add_object_array(&parents->item->object, | |
329f9960 | 864 | NULL, &data->want_obj); |
e8e44de7 NTND |
865 | parents = parents->next; |
866 | } | |
de0e9f74 | 867 | add_object_array(object, NULL, &data->extra_edge_obj); |
e8e44de7 NTND |
868 | } |
869 | /* make sure commit traversal conforms to client */ | |
19143f13 | 870 | register_shallow(the_repository, &object->oid); |
e8e44de7 | 871 | } |
873700c9 NTND |
872 | } |
873 | ||
e8207717 | 874 | static int check_ref(const char *refname_full, const char *referent UNUSED, const struct object_id *oid, |
5056cf4a | 875 | int flag, void *cb_data); |
b1492f22 | 876 | static void deepen(struct upload_pack_data *data, int depth) |
873700c9 | 877 | { |
c8813487 | 878 | if (depth == INFINITE_DEPTH && !is_repository_shallow(the_repository)) { |
873700c9 NTND |
879 | int i; |
880 | ||
b1492f22 CC |
881 | for (i = 0; i < data->shallows.nr; i++) { |
882 | struct object *object = data->shallows.objects[i].item; | |
873700c9 NTND |
883 | object->flags |= NOT_SHALLOW; |
884 | } | |
b1492f22 | 885 | } else if (data->deepen_relative) { |
cccf74e2 NTND |
886 | struct object_array reachable_shallows = OBJECT_ARRAY_INIT; |
887 | struct commit_list *result; | |
888 | ||
5056cf4a JT |
889 | /* |
890 | * Checking for reachable shallows requires that our refs be | |
891 | * marked with OUR_REF. | |
892 | */ | |
2e5c4758 PS |
893 | refs_head_ref_namespaced(get_main_ref_store(the_repository), |
894 | check_ref, data); | |
18b6b1b5 | 895 | for_each_namespaced_ref_1(check_ref, data); |
5056cf4a | 896 | |
f1514c6a | 897 | get_reachable_list(data, &reachable_shallows); |
cccf74e2 NTND |
898 | result = get_shallow_commits(&reachable_shallows, |
899 | depth + 1, | |
900 | SHALLOW, NOT_SHALLOW); | |
35b43a10 | 901 | send_shallow(data, result); |
cccf74e2 NTND |
902 | free_commit_list(result); |
903 | object_array_clear(&reachable_shallows); | |
873700c9 NTND |
904 | } else { |
905 | struct commit_list *result; | |
906 | ||
b1492f22 | 907 | result = get_shallow_commits(&data->want_obj, depth, |
873700c9 | 908 | SHALLOW, NOT_SHALLOW); |
35b43a10 | 909 | send_shallow(data, result); |
873700c9 NTND |
910 | free_commit_list(result); |
911 | } | |
912 | ||
329f9960 | 913 | send_unshallow(data); |
e8e44de7 NTND |
914 | } |
915 | ||
446e42c5 CC |
916 | static void deepen_by_rev_list(struct upload_pack_data *data, |
917 | int ac, | |
918 | const char **av) | |
569e554b NTND |
919 | { |
920 | struct commit_list *result; | |
921 | ||
6abada18 | 922 | disable_commit_graph(the_repository); |
569e554b | 923 | result = get_shallow_commits_by_rev_list(ac, av, SHALLOW, NOT_SHALLOW); |
35b43a10 | 924 | send_shallow(data, result); |
569e554b | 925 | free_commit_list(result); |
329f9960 | 926 | send_unshallow(data); |
685fbd32 BW |
927 | } |
928 | ||
929 | /* Returns 1 if a shallow list is sent or 0 otherwise */ | |
ee703c8a | 930 | static int send_shallow_list(struct upload_pack_data *data) |
685fbd32 BW |
931 | { |
932 | int ret = 0; | |
933 | ||
ee703c8a | 934 | if (data->depth > 0 && data->deepen_rev_list) |
685fbd32 | 935 | die("git upload-pack: deepen and deepen-since (or deepen-not) cannot be used together"); |
ee703c8a | 936 | if (data->depth > 0) { |
b1492f22 | 937 | deepen(data, data->depth); |
685fbd32 | 938 | ret = 1; |
ee703c8a | 939 | } else if (data->deepen_rev_list) { |
c972bf4c | 940 | struct strvec av = STRVEC_INIT; |
685fbd32 BW |
941 | int i; |
942 | ||
c972bf4c | 943 | strvec_push(&av, "rev-list"); |
ee703c8a | 944 | if (data->deepen_since) |
c972bf4c | 945 | strvec_pushf(&av, "--max-age=%"PRItime, data->deepen_since); |
388b96df JK |
946 | if (oidset_size(&data->deepen_not)) { |
947 | const struct object_id *oid; | |
948 | struct oidset_iter iter; | |
c972bf4c | 949 | strvec_push(&av, "--not"); |
388b96df JK |
950 | oidset_iter_init(&data->deepen_not, &iter); |
951 | while ((oid = oidset_iter_next(&iter))) | |
720ba25d | 952 | strvec_push(&av, oid_to_hex(oid)); |
c972bf4c | 953 | strvec_push(&av, "--not"); |
685fbd32 | 954 | } |
ee703c8a CC |
955 | for (i = 0; i < data->want_obj.nr; i++) { |
956 | struct object *o = data->want_obj.objects[i].item; | |
c972bf4c | 957 | strvec_push(&av, oid_to_hex(&o->oid)); |
685fbd32 | 958 | } |
d70a9eb6 | 959 | deepen_by_rev_list(data, av.nr, av.v); |
c972bf4c | 960 | strvec_clear(&av); |
685fbd32 BW |
961 | ret = 1; |
962 | } else { | |
ee703c8a | 963 | if (data->shallows.nr > 0) { |
685fbd32 | 964 | int i; |
ee703c8a | 965 | for (i = 0; i < data->shallows.nr; i++) |
00624d60 | 966 | register_shallow(the_repository, |
ee703c8a | 967 | &data->shallows.objects[i].item->oid); |
685fbd32 BW |
968 | } |
969 | } | |
970 | ||
35b43a10 | 971 | data->shallow_nr += data->shallows.nr; |
685fbd32 | 972 | return ret; |
569e554b NTND |
973 | } |
974 | ||
ae2948f3 BW |
975 | static int process_shallow(const char *line, struct object_array *shallows) |
976 | { | |
977 | const char *arg; | |
978 | if (skip_prefix(line, "shallow ", &arg)) { | |
979 | struct object_id oid; | |
980 | struct object *object; | |
981 | if (get_oid_hex(arg, &oid)) | |
982 | die("invalid shallow line: %s", line); | |
109cd76d | 983 | object = parse_object(the_repository, &oid); |
ae2948f3 BW |
984 | if (!object) |
985 | return 1; | |
986 | if (object->type != OBJ_COMMIT) | |
987 | die("invalid shallow object %s", oid_to_hex(&oid)); | |
988 | if (!(object->flags & CLIENT_SHALLOW)) { | |
989 | object->flags |= CLIENT_SHALLOW; | |
990 | add_object_array(object, NULL, shallows); | |
991 | } | |
992 | return 1; | |
993 | } | |
994 | ||
995 | return 0; | |
996 | } | |
997 | ||
998 | static int process_deepen(const char *line, int *depth) | |
999 | { | |
1000 | const char *arg; | |
1001 | if (skip_prefix(line, "deepen ", &arg)) { | |
1002 | char *end = NULL; | |
1003 | *depth = (int)strtol(arg, &end, 0); | |
1004 | if (!end || *end || *depth <= 0) | |
1005 | die("Invalid deepen: %s", line); | |
1006 | return 1; | |
1007 | } | |
1008 | ||
1009 | return 0; | |
1010 | } | |
1011 | ||
1012 | static int process_deepen_since(const char *line, timestamp_t *deepen_since, int *deepen_rev_list) | |
1013 | { | |
1014 | const char *arg; | |
1015 | if (skip_prefix(line, "deepen-since ", &arg)) { | |
1016 | char *end = NULL; | |
1017 | *deepen_since = parse_timestamp(arg, &end, 0); | |
1018 | if (!end || *end || !deepen_since || | |
1019 | /* revisions.c's max_age -1 is special */ | |
1020 | *deepen_since == -1) | |
1021 | die("Invalid deepen-since: %s", line); | |
1022 | *deepen_rev_list = 1; | |
1023 | return 1; | |
1024 | } | |
1025 | return 0; | |
1026 | } | |
1027 | ||
388b96df | 1028 | static int process_deepen_not(const char *line, struct oidset *deepen_not, int *deepen_rev_list) |
ae2948f3 BW |
1029 | { |
1030 | const char *arg; | |
1031 | if (skip_prefix(line, "deepen-not ", &arg)) { | |
5a875ff7 | 1032 | int cnt; |
ae2948f3 BW |
1033 | char *ref = NULL; |
1034 | struct object_id oid; | |
5a875ff7 EN |
1035 | cnt = expand_ref(the_repository, arg, strlen(arg), &oid, &ref); |
1036 | if (cnt > 1) | |
ae2948f3 | 1037 | die("git upload-pack: ambiguous deepen-not: %s", line); |
5a875ff7 EN |
1038 | if (cnt < 1) |
1039 | die("git upload-pack: deepen-not is not a ref: %s", line); | |
388b96df | 1040 | oidset_insert(deepen_not, &oid); |
ae2948f3 BW |
1041 | free(ref); |
1042 | *deepen_rev_list = 1; | |
1043 | return 1; | |
1044 | } | |
1045 | return 0; | |
569e554b NTND |
1046 | } |
1047 | ||
6dd3456a TB |
1048 | NORETURN __attribute__((format(printf,2,3))) |
1049 | static void send_err_and_die(struct upload_pack_data *data, | |
1050 | const char *fmt, ...) | |
1051 | { | |
1052 | struct strbuf buf = STRBUF_INIT; | |
1053 | va_list ap; | |
1054 | ||
1055 | va_start(ap, fmt); | |
1056 | strbuf_vaddf(&buf, fmt, ap); | |
1057 | va_end(ap); | |
1058 | ||
1059 | packet_writer_error(&data->writer, "%s", buf.buf); | |
1060 | die("%s", buf.buf); | |
1061 | } | |
1062 | ||
1063 | static void check_one_filter(struct upload_pack_data *data, | |
1064 | struct list_objects_filter_options *opts) | |
1065 | { | |
1066 | const char *key = list_object_filter_config_name(opts->choice); | |
1067 | struct string_list_item *item = string_list_lookup(&data->allowed_filters, | |
1068 | key); | |
1069 | int allowed; | |
1070 | ||
1071 | if (item) | |
1072 | allowed = (intptr_t)item->util; | |
1073 | else | |
1074 | allowed = data->allow_filter_fallback; | |
1075 | ||
1076 | if (!allowed) | |
1077 | send_err_and_die(data, "filter '%s' not supported", key); | |
5b01a4e8 TB |
1078 | |
1079 | if (opts->choice == LOFC_TREE_DEPTH && | |
1080 | opts->tree_exclude_depth > data->tree_filter_max_depth) | |
1081 | send_err_and_die(data, | |
1082 | "tree filter allows max depth %lu, but got %lu", | |
1083 | data->tree_filter_max_depth, | |
1084 | opts->tree_exclude_depth); | |
6dd3456a TB |
1085 | } |
1086 | ||
1087 | static void check_filter_recurse(struct upload_pack_data *data, | |
1088 | struct list_objects_filter_options *opts) | |
1089 | { | |
1090 | size_t i; | |
1091 | ||
1092 | check_one_filter(data, opts); | |
1093 | if (opts->choice != LOFC_COMBINE) | |
1094 | return; | |
1095 | ||
1096 | for (i = 0; i < opts->sub_nr; i++) | |
1097 | check_filter_recurse(data, &opts->sub[i]); | |
1098 | } | |
1099 | ||
1100 | static void die_if_using_banned_filter(struct upload_pack_data *data) | |
1101 | { | |
1102 | check_filter_recurse(data, &data->filter_options); | |
1103 | } | |
1104 | ||
d92ae2c0 CC |
1105 | static void receive_needs(struct upload_pack_data *data, |
1106 | struct packet_reader *reader) | |
fb9040cc | 1107 | { |
051e4005 | 1108 | int has_non_tip = 0; |
fb9040cc | 1109 | |
35b43a10 | 1110 | data->shallow_nr = 0; |
fb9040cc | 1111 | for (;;) { |
565ebbf7 | 1112 | struct object *o; |
f47182c8 | 1113 | const char *features; |
cf93982f | 1114 | struct object_id oid_buf; |
8bf3b758 | 1115 | const char *arg; |
7ce4c8f7 | 1116 | size_t feature_len; |
8bf3b758 | 1117 | |
d40f04e0 | 1118 | reset_timeout(data->timeout); |
01f9ec64 | 1119 | if (packet_reader_read(reader) != PACKET_READ_NORMAL) |
ed09aef0 | 1120 | break; |
e091eb93 | 1121 | |
7a516764 | 1122 | if (process_shallow(reader->line, &data->shallows)) |
ed09aef0 | 1123 | continue; |
7a516764 | 1124 | if (process_deepen(reader->line, &data->depth)) |
016e6ccb | 1125 | continue; |
7a516764 | 1126 | if (process_deepen_since(reader->line, &data->deepen_since, &data->deepen_rev_list)) |
569e554b | 1127 | continue; |
7a516764 | 1128 | if (process_deepen_not(reader->line, &data->deepen_not, &data->deepen_rev_list)) |
269a7a83 | 1129 | continue; |
ae2948f3 | 1130 | |
01f9ec64 | 1131 | if (skip_prefix(reader->line, "filter ", &arg)) { |
59a90261 | 1132 | if (!data->filter_capability_requested) |
10ac85c7 | 1133 | die("git upload-pack: filtering capability not negotiated"); |
d92ae2c0 CC |
1134 | list_objects_filter_die_if_populated(&data->filter_options); |
1135 | parse_list_objects_filter(&data->filter_options, arg); | |
6dd3456a | 1136 | die_if_using_banned_filter(data); |
10ac85c7 JH |
1137 | continue; |
1138 | } | |
9bfa0f9b | 1139 | |
01f9ec64 | 1140 | if (!skip_prefix(reader->line, "want ", &arg) || |
55dc227d | 1141 | parse_oid_hex(arg, &oid_buf, &features)) |
7e44c935 | 1142 | die("git upload-pack: protocol error, " |
01f9ec64 | 1143 | "expected to get object ID, not '%s'", reader->line); |
f47182c8 | 1144 | |
cccf74e2 | 1145 | if (parse_feature_request(features, "deepen-relative")) |
7a516764 | 1146 | data->deepen_relative = 1; |
f47182c8 | 1147 | if (parse_feature_request(features, "multi_ack_detailed")) |
e9d882b8 | 1148 | data->multi_ack = MULTI_ACK_DETAILED; |
f47182c8 | 1149 | else if (parse_feature_request(features, "multi_ack")) |
e9d882b8 | 1150 | data->multi_ack = MULTI_ACK; |
f47182c8 | 1151 | if (parse_feature_request(features, "no-done")) |
d40f04e0 | 1152 | data->no_done = 1; |
f47182c8 | 1153 | if (parse_feature_request(features, "thin-pack")) |
b5a2068c | 1154 | data->use_thin_pack = 1; |
f47182c8 | 1155 | if (parse_feature_request(features, "ofs-delta")) |
b5a2068c | 1156 | data->use_ofs_delta = 1; |
f47182c8 | 1157 | if (parse_feature_request(features, "side-band-64k")) |
f8edd1ca | 1158 | data->use_sideband = LARGE_PACKET_MAX; |
f47182c8 | 1159 | else if (parse_feature_request(features, "side-band")) |
f8edd1ca | 1160 | data->use_sideband = DEFAULT_PACKET_MAX; |
f47182c8 | 1161 | if (parse_feature_request(features, "no-progress")) |
b5a2068c | 1162 | data->no_progress = 1; |
f47182c8 | 1163 | if (parse_feature_request(features, "include-tag")) |
b5a2068c | 1164 | data->use_include_tag = 1; |
59abe196 CC |
1165 | if (data->allow_filter && |
1166 | parse_feature_request(features, "filter")) | |
59a90261 | 1167 | data->filter_capability_requested = 1; |
565ebbf7 | 1168 | |
82959467 JS |
1169 | arg = parse_feature_value(features, "session-id", &feature_len, NULL); |
1170 | if (arg) { | |
1171 | char *client_sid = xstrndup(arg, feature_len); | |
1172 | trace2_data_string("transfer", NULL, "client-sid", client_sid); | |
1173 | free(client_sid); | |
1174 | } | |
1175 | ||
a6ca601c | 1176 | o = parse_object_with_flags(the_repository, &oid_buf, |
6cd05e76 JK |
1177 | PARSE_OBJECT_SKIP_HASH_CHECK | |
1178 | PARSE_OBJECT_DISCARD_TREE); | |
bdb31ead | 1179 | if (!o) { |
4ace0283 | 1180 | packet_writer_error(&data->writer, |
bc2e795c JT |
1181 | "upload-pack: not our ref %s", |
1182 | oid_to_hex(&oid_buf)); | |
9f9aa761 | 1183 | die("git upload-pack: not our ref %s", |
cf93982f | 1184 | oid_to_hex(&oid_buf)); |
bdb31ead | 1185 | } |
565ebbf7 JH |
1186 | if (!(o->flags & WANTED)) { |
1187 | o->flags |= WANTED; | |
629060d9 CC |
1188 | if (!((data->allow_uor & ALLOW_ANY_SHA1) == ALLOW_ANY_SHA1 |
1189 | || is_our_ref(o, data->allow_uor))) | |
051e4005 | 1190 | has_non_tip = 1; |
d92ae2c0 | 1191 | add_object_array(o, NULL, &data->want_obj); |
565ebbf7 | 1192 | } |
fb9040cc | 1193 | } |
9462e3f5 | 1194 | |
051e4005 JH |
1195 | /* |
1196 | * We have sent all our refs already, and the other end | |
1197 | * should have chosen out of them. When we are operating | |
1198 | * in the stateless RPC mode, however, their choice may | |
1199 | * have been based on the set of older refs advertised | |
1200 | * by another process that handled the initial request. | |
1201 | */ | |
1202 | if (has_non_tip) | |
b08c9742 | 1203 | check_non_tip(data); |
051e4005 | 1204 | |
f8edd1ca | 1205 | if (!data->use_sideband && data->daemon_mode) |
b5a2068c | 1206 | data->no_progress = 1; |
9462e3f5 | 1207 | |
7a516764 | 1208 | if (data->depth == 0 && !data->deepen_rev_list && data->shallows.nr == 0) |
f53514bc | 1209 | return; |
569e554b | 1210 | |
ee703c8a | 1211 | if (send_shallow_list(data)) |
685fbd32 | 1212 | packet_flush(1); |
fb9040cc LT |
1213 | } |
1214 | ||
daebaa78 | 1215 | /* return non-zero if the ref is hidden, otherwise 0 */ |
78a766ab | 1216 | static int mark_our_ref(const char *refname, const char *refname_full, |
c45841ff | 1217 | const struct object_id *oid, const struct strvec *hidden_refs) |
cbbe50db | 1218 | { |
45a187cc | 1219 | struct object *o = lookup_unknown_object(the_repository, oid); |
daebaa78 | 1220 | |
9b67eb6f | 1221 | if (ref_is_hidden(refname, refname_full, hidden_refs)) { |
390eb36b | 1222 | o->flags |= HIDDEN_REF; |
daebaa78 | 1223 | return 1; |
390eb36b | 1224 | } |
3f1da57f | 1225 | o->flags |= OUR_REF; |
cbbe50db JH |
1226 | return 0; |
1227 | } | |
1228 | ||
e8207717 | 1229 | static int check_ref(const char *refname_full, const char *referent UNUSED,const struct object_id *oid, |
9b67eb6f | 1230 | int flag UNUSED, void *cb_data) |
e172755b | 1231 | { |
78a766ab | 1232 | const char *refname = strip_namespace(refname_full); |
9b67eb6f | 1233 | struct upload_pack_data *data = cb_data; |
78a766ab | 1234 | |
9b67eb6f | 1235 | mark_our_ref(refname, refname_full, oid, &data->hidden_refs); |
e172755b JK |
1236 | return 0; |
1237 | } | |
1238 | ||
7171d8c1 JH |
1239 | static void format_symref_info(struct strbuf *buf, struct string_list *symref) |
1240 | { | |
1241 | struct string_list_item *item; | |
1242 | ||
1243 | if (!symref->nr) | |
1244 | return; | |
1245 | for_each_string_list_item(item, symref) | |
1246 | strbuf_addf(buf, " symref=%s:%s", item->string, (char *)item->util); | |
1247 | } | |
1248 | ||
791e1adf JS |
1249 | static void format_session_id(struct strbuf *buf, struct upload_pack_data *d) { |
1250 | if (d->advertise_sid) | |
1251 | strbuf_addf(buf, " session-id=%s", trace2_session_id()); | |
1252 | } | |
1253 | ||
933e3a4e | 1254 | static void write_v0_ref(struct upload_pack_data *data, |
1255 | const char *refname, const char *refname_nons, | |
1256 | const struct object_id *oid) | |
def88e9a | 1257 | { |
ed09aef0 | 1258 | static const char *capabilities = "multi_ack thin-pack side-band" |
cccf74e2 NTND |
1259 | " side-band-64k ofs-delta shallow deepen-since deepen-not" |
1260 | " deepen-relative no-progress include-tag multi_ack_detailed"; | |
21758aff | 1261 | struct object_id peeled; |
b5b16990 | 1262 | |
9b67eb6f | 1263 | if (mark_our_ref(refname_nons, refname, oid, &data->hidden_refs)) |
933e3a4e | 1264 | return; |
cbbe50db | 1265 | |
7171d8c1 JH |
1266 | if (capabilities) { |
1267 | struct strbuf symref_info = STRBUF_INIT; | |
791e1adf | 1268 | struct strbuf session_id = STRBUF_INIT; |
7171d8c1 | 1269 | |
762f9276 | 1270 | format_symref_info(&symref_info, &data->symref); |
791e1adf | 1271 | format_session_id(&session_id, data); |
70afef5c | 1272 | packet_fwrite_fmt(stdout, "%s %s%c%s%s%s%s%s%s%s object-format=%s agent=%s\n", |
363e98bf | 1273 | oid_to_hex(oid), refname_nons, |
cf2ad8e6 | 1274 | 0, capabilities, |
629060d9 | 1275 | (data->allow_uor & ALLOW_TIP_SHA1) ? |
7199c093 | 1276 | " allow-tip-sha1-in-want" : "", |
629060d9 | 1277 | (data->allow_uor & ALLOW_REACHABLE_SHA1) ? |
68ee6289 | 1278 | " allow-reachable-sha1-in-want" : "", |
f234da80 | 1279 | data->no_done ? " no-done" : "", |
7171d8c1 | 1280 | symref_info.buf, |
59abe196 | 1281 | data->allow_filter ? " filter" : "", |
791e1adf | 1282 | session_id.buf, |
bf30dbf8 | 1283 | the_hash_algo->name, |
ff5effdf | 1284 | git_user_agent_sanitized()); |
7171d8c1 | 1285 | strbuf_release(&symref_info); |
791e1adf | 1286 | strbuf_release(&session_id); |
933e3a4e | 1287 | data->sent_capabilities = 1; |
7171d8c1 | 1288 | } else { |
70afef5c | 1289 | packet_fwrite_fmt(stdout, "%s %s\n", oid_to_hex(oid), refname_nons); |
7171d8c1 | 1290 | } |
1f5881bb | 1291 | capabilities = NULL; |
30aaff43 | 1292 | if (!peel_iterated_oid(the_repository, oid, &peeled)) |
70afef5c | 1293 | packet_fwrite_fmt(stdout, "%s %s^{}\n", oid_to_hex(&peeled), refname_nons); |
933e3a4e | 1294 | return; |
1295 | } | |
1296 | ||
e8207717 | 1297 | static int send_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid, |
933e3a4e | 1298 | int flag UNUSED, void *cb_data) |
1299 | { | |
1300 | write_v0_ref(cb_data, refname, strip_namespace(refname), oid); | |
def88e9a LT |
1301 | return 0; |
1302 | } | |
1303 | ||
e8207717 | 1304 | static int find_symref(const char *refname, const char *referent UNUSED, |
5cf88fd8 | 1305 | const struct object_id *oid UNUSED, |
7dabd056 | 1306 | int flag, void *cb_data) |
7171d8c1 JH |
1307 | { |
1308 | const char *symref_target; | |
1309 | struct string_list_item *item; | |
7171d8c1 JH |
1310 | |
1311 | if ((flag & REF_ISSYMREF) == 0) | |
1312 | return 0; | |
2e5c4758 PS |
1313 | symref_target = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), |
1314 | refname, 0, NULL, &flag); | |
7171d8c1 JH |
1315 | if (!symref_target || (flag & REF_ISSYMREF) == 0) |
1316 | die("'%s' is a symref but it is not?", refname); | |
533e0882 JK |
1317 | item = string_list_append(cb_data, strip_namespace(refname)); |
1318 | item->util = xstrdup(strip_namespace(symref_target)); | |
7171d8c1 JH |
1319 | return 0; |
1320 | } | |
1321 | ||
6dd3456a | 1322 | static int parse_object_filter_config(const char *var, const char *value, |
8868b1eb GC |
1323 | const struct key_value_info *kvi, |
1324 | struct upload_pack_data *data) | |
6dd3456a TB |
1325 | { |
1326 | struct strbuf buf = STRBUF_INIT; | |
1327 | const char *sub, *key; | |
1328 | size_t sub_len; | |
1329 | ||
1330 | if (parse_config_key(var, "uploadpackfilter", &sub, &sub_len, &key)) | |
1331 | return 0; | |
1332 | ||
1333 | if (!sub) { | |
1334 | if (!strcmp(key, "allow")) | |
1335 | data->allow_filter_fallback = git_config_bool(var, value); | |
1336 | return 0; | |
1337 | } | |
1338 | ||
1339 | strbuf_add(&buf, sub, sub_len); | |
1340 | ||
1341 | if (!strcmp(key, "allow")) | |
1342 | string_list_insert(&data->allowed_filters, buf.buf)->util = | |
1343 | (void *)(intptr_t)git_config_bool(var, value); | |
5b01a4e8 TB |
1344 | else if (!strcmp(buf.buf, "tree") && !strcmp(key, "maxdepth")) { |
1345 | if (!value) { | |
1346 | strbuf_release(&buf); | |
1347 | return config_error_nonbool(var); | |
1348 | } | |
1349 | string_list_insert(&data->allowed_filters, buf.buf)->util = | |
1350 | (void *)(intptr_t)1; | |
8868b1eb GC |
1351 | data->tree_filter_max_depth = git_config_ulong(var, value, |
1352 | kvi); | |
5b01a4e8 | 1353 | } |
6dd3456a TB |
1354 | |
1355 | strbuf_release(&buf); | |
1356 | return 0; | |
1357 | } | |
1358 | ||
a4e7e317 | 1359 | static int upload_pack_config(const char *var, const char *value, |
8868b1eb | 1360 | const struct config_context *ctx, |
a4e7e317 | 1361 | void *cb_data) |
daebaa78 | 1362 | { |
f203a88c CC |
1363 | struct upload_pack_data *data = cb_data; |
1364 | ||
7199c093 FM |
1365 | if (!strcmp("uploadpack.allowtipsha1inwant", var)) { |
1366 | if (git_config_bool(var, value)) | |
629060d9 | 1367 | data->allow_uor |= ALLOW_TIP_SHA1; |
7199c093 | 1368 | else |
629060d9 | 1369 | data->allow_uor &= ~ALLOW_TIP_SHA1; |
68ee6289 FM |
1370 | } else if (!strcmp("uploadpack.allowreachablesha1inwant", var)) { |
1371 | if (git_config_bool(var, value)) | |
629060d9 | 1372 | data->allow_uor |= ALLOW_REACHABLE_SHA1; |
68ee6289 | 1373 | else |
629060d9 | 1374 | data->allow_uor &= ~ALLOW_REACHABLE_SHA1; |
f8edeaa0 DT |
1375 | } else if (!strcmp("uploadpack.allowanysha1inwant", var)) { |
1376 | if (git_config_bool(var, value)) | |
629060d9 | 1377 | data->allow_uor |= ALLOW_ANY_SHA1; |
f8edeaa0 | 1378 | else |
629060d9 | 1379 | data->allow_uor &= ~ALLOW_ANY_SHA1; |
7199c093 | 1380 | } else if (!strcmp("uploadpack.keepalive", var)) { |
8868b1eb | 1381 | data->keepalive = git_config_int(var, value, ctx->kvi); |
f203a88c CC |
1382 | if (!data->keepalive) |
1383 | data->keepalive = -1; | |
10ac85c7 | 1384 | } else if (!strcmp("uploadpack.allowfilter", var)) { |
59abe196 | 1385 | data->allow_filter = git_config_bool(var, value); |
516e2b76 | 1386 | } else if (!strcmp("uploadpack.allowrefinwant", var)) { |
d1d7a945 | 1387 | data->allow_ref_in_want = git_config_bool(var, value); |
0bbc0bc5 | 1388 | } else if (!strcmp("uploadpack.allowsidebandall", var)) { |
e3835cd4 | 1389 | data->allow_sideband_all = git_config_bool(var, value); |
a922bfa3 JK |
1390 | } else if (!strcmp("uploadpack.blobpackfileuri", var)) { |
1391 | if (value) | |
1392 | data->allow_packfile_uris = 1; | |
8e712ef6 EN |
1393 | } else if (!strcmp("core.precomposeunicode", var)) { |
1394 | precomposed_unicode = git_config_bool(var, value); | |
791e1adf JS |
1395 | } else if (!strcmp("transfer.advertisesid", var)) { |
1396 | data->advertise_sid = git_config_bool(var, value); | |
05e95155 | 1397 | } |
aaaa8818 | 1398 | |
8868b1eb | 1399 | if (parse_object_filter_config(var, value, ctx->kvi, data) < 0) |
d43a21bd | 1400 | return -1; |
6dd3456a | 1401 | |
9b67eb6f | 1402 | return parse_hide_refs_config(var, value, "uploadpack", &data->hidden_refs); |
daebaa78 JH |
1403 | } |
1404 | ||
a4e7e317 GC |
1405 | static int upload_pack_protected_config(const char *var, const char *value, |
1406 | const struct config_context *ctx UNUSED, | |
1407 | void *cb_data) | |
5b3c6507 GC |
1408 | { |
1409 | struct upload_pack_data *data = cb_data; | |
1410 | ||
1411 | if (!strcmp("uploadpack.packobjectshook", var)) | |
1412 | return git_config_string(&data->pack_objects_hook, var, value); | |
1413 | return 0; | |
1414 | } | |
1415 | ||
922fdefb JK |
1416 | static void get_upload_pack_config(struct repository *r, |
1417 | struct upload_pack_data *data) | |
5b3c6507 | 1418 | { |
922fdefb | 1419 | repo_config(r, upload_pack_config, data); |
5b3c6507 | 1420 | git_protected_config(upload_pack_protected_config, data); |
37aa89b0 JK |
1421 | |
1422 | data->allow_sideband_all |= git_env_bool("GIT_TEST_SIDEBAND_ALL", 0); | |
5b3c6507 GC |
1423 | } |
1424 | ||
f234da80 ÆAB |
1425 | void upload_pack(const int advertise_refs, const int stateless_rpc, |
1426 | const int timeout) | |
def88e9a | 1427 | { |
01f9ec64 | 1428 | struct packet_reader reader; |
ebf8ebcc | 1429 | struct upload_pack_data data; |
960deccb | 1430 | |
ebf8ebcc | 1431 | upload_pack_data_init(&data); |
922fdefb | 1432 | get_upload_pack_config(the_repository, &data); |
8a0e6f16 | 1433 | |
f234da80 ÆAB |
1434 | data.stateless_rpc = stateless_rpc; |
1435 | data.timeout = timeout; | |
1436 | if (data.timeout) | |
1437 | data.daemon_mode = 1; | |
df654abc | 1438 | |
2e5c4758 PS |
1439 | refs_head_ref_namespaced(get_main_ref_store(the_repository), |
1440 | find_symref, &data.symref); | |
a6080a0a | 1441 | |
f234da80 | 1442 | if (advertise_refs || !data.stateless_rpc) { |
d40f04e0 | 1443 | reset_timeout(data.timeout); |
f234da80 ÆAB |
1444 | if (advertise_refs) |
1445 | data.no_done = 1; | |
2e5c4758 PS |
1446 | refs_head_ref_namespaced(get_main_ref_store(the_repository), |
1447 | send_ref, &data); | |
18b6b1b5 | 1448 | for_each_namespaced_ref_1(send_ref, &data); |
933e3a4e | 1449 | if (!data.sent_capabilities) { |
1450 | const char *refname = "capabilities^{}"; | |
7d70b29c | 1451 | write_v0_ref(&data, refname, refname, null_oid(the_hash_algo)); |
933e3a4e | 1452 | } |
70afef5c JV |
1453 | /* |
1454 | * fflush stdout before calling advertise_shallow_grafts because send_ref | |
1455 | * uses stdio. | |
1456 | */ | |
1457 | fflush_or_die(stdout); | |
a3d6b53e BW |
1458 | advertise_shallow_grafts(1); |
1459 | packet_flush(1); | |
1460 | } else { | |
2e5c4758 PS |
1461 | refs_head_ref_namespaced(get_main_ref_store(the_repository), |
1462 | check_ref, &data); | |
18b6b1b5 | 1463 | for_each_namespaced_ref_1(check_ref, &data); |
aa9bab29 | 1464 | } |
01f9ec64 | 1465 | |
f234da80 | 1466 | if (!advertise_refs) { |
ebf8ebcc CC |
1467 | packet_reader_init(&reader, 0, NULL, 0, |
1468 | PACKET_READ_CHOMP_NEWLINE | | |
1469 | PACKET_READ_DIE_ON_ERR_PACKET); | |
1470 | ||
d92ae2c0 | 1471 | receive_needs(&data, &reader); |
fb3d1a08 DD |
1472 | |
1473 | /* | |
1474 | * An EOF at this exact point in negotiation should be | |
1475 | * acceptable from stateless clients as they will consume the | |
1476 | * shallow list before doing subsequent rpc with haves/etc. | |
1477 | */ | |
1478 | if (data.stateless_rpc) | |
1479 | reader.options |= PACKET_READ_GENTLE_ON_EOF; | |
1480 | ||
1481 | if (data.want_obj.nr && | |
1482 | packet_reader_peek(&reader) != PACKET_READ_EOF) { | |
1483 | reader.options &= ~PACKET_READ_GENTLE_ON_EOF; | |
07977695 | 1484 | get_common_commits(&data, &reader); |
cae2ee10 | 1485 | create_pack_file(&data, NULL); |
ebf8ebcc | 1486 | } |
a3d6b53e | 1487 | } |
08450ef7 | 1488 | |
ebf8ebcc | 1489 | upload_pack_data_clear(&data); |
def88e9a | 1490 | } |
04b33055 | 1491 | |
bc2e795c JT |
1492 | static int parse_want(struct packet_writer *writer, const char *line, |
1493 | struct object_array *want_obj) | |
3145ea95 BW |
1494 | { |
1495 | const char *arg; | |
1496 | if (skip_prefix(line, "want ", &arg)) { | |
1497 | struct object_id oid; | |
1498 | struct object *o; | |
1499 | ||
1500 | if (get_oid_hex(arg, &oid)) | |
1501 | die("git upload-pack: protocol error, " | |
1502 | "expected to get oid, not '%s'", line); | |
1503 | ||
9a8c3c4a | 1504 | o = parse_object_with_flags(the_repository, &oid, |
6cd05e76 JK |
1505 | PARSE_OBJECT_SKIP_HASH_CHECK | |
1506 | PARSE_OBJECT_DISCARD_TREE); | |
4de65626 | 1507 | |
3145ea95 | 1508 | if (!o) { |
bc2e795c JT |
1509 | packet_writer_error(writer, |
1510 | "upload-pack: not our ref %s", | |
1511 | oid_to_hex(&oid)); | |
3145ea95 BW |
1512 | die("git upload-pack: not our ref %s", |
1513 | oid_to_hex(&oid)); | |
1514 | } | |
1515 | ||
1516 | if (!(o->flags & WANTED)) { | |
1517 | o->flags |= WANTED; | |
1d1243fe | 1518 | add_object_array(o, NULL, want_obj); |
3145ea95 BW |
1519 | } |
1520 | ||
1521 | return 1; | |
1522 | } | |
1523 | ||
1524 | return 0; | |
1525 | } | |
1526 | ||
bc2e795c | 1527 | static int parse_want_ref(struct packet_writer *writer, const char *line, |
b065063c | 1528 | struct strmap *wanted_refs, |
c45841ff | 1529 | struct strvec *hidden_refs, |
1d1243fe | 1530 | struct object_array *want_obj) |
516e2b76 | 1531 | { |
39551406 KA |
1532 | const char *refname_nons; |
1533 | if (skip_prefix(line, "want-ref ", &refname_nons)) { | |
516e2b76 | 1534 | struct object_id oid; |
4de65626 | 1535 | struct object *o = NULL; |
39551406 | 1536 | struct strbuf refname = STRBUF_INIT; |
516e2b76 | 1537 | |
39551406 | 1538 | strbuf_addf(&refname, "%s%s", get_git_namespace(), refname_nons); |
9b67eb6f | 1539 | if (ref_is_hidden(refname_nons, refname.buf, hidden_refs) || |
2e5c4758 | 1540 | refs_read_ref(get_main_ref_store(the_repository), refname.buf, &oid)) { |
39551406 KA |
1541 | packet_writer_error(writer, "unknown ref %s", refname_nons); |
1542 | die("unknown ref %s", refname_nons); | |
516e2b76 | 1543 | } |
39551406 | 1544 | strbuf_release(&refname); |
516e2b76 | 1545 | |
b065063c JK |
1546 | if (strmap_put(wanted_refs, refname_nons, oiddup(&oid))) { |
1547 | packet_writer_error(writer, "duplicate want-ref %s", | |
1548 | refname_nons); | |
1549 | die("duplicate want-ref %s", refname_nons); | |
1550 | } | |
516e2b76 | 1551 | |
4de65626 PS |
1552 | if (!starts_with(refname_nons, "refs/tags/")) { |
1553 | struct commit *commit = lookup_commit_in_graph(the_repository, &oid); | |
1554 | if (commit) | |
1555 | o = &commit->object; | |
1556 | } | |
1557 | ||
1558 | if (!o) | |
74d414c9 | 1559 | o = parse_object_or_die(the_repository, &oid, refname_nons); |
4de65626 | 1560 | |
516e2b76 BW |
1561 | if (!(o->flags & WANTED)) { |
1562 | o->flags |= WANTED; | |
1d1243fe | 1563 | add_object_array(o, NULL, want_obj); |
516e2b76 BW |
1564 | } |
1565 | ||
1566 | return 1; | |
1567 | } | |
1568 | ||
1569 | return 0; | |
1570 | } | |
1571 | ||
fae96274 | 1572 | static int parse_have(const char *line, struct upload_pack_data *data) |
3145ea95 BW |
1573 | { |
1574 | const char *arg; | |
1575 | if (skip_prefix(line, "have ", &arg)) { | |
1576 | struct object_id oid; | |
1577 | ||
fae96274 JK |
1578 | got_oid(data, arg, &oid); |
1579 | data->seen_haves = 1; | |
3145ea95 | 1580 | return 1; |
aa9bab29 BW |
1581 | } |
1582 | ||
def88e9a LT |
1583 | return 0; |
1584 | } | |
3145ea95 | 1585 | |
b8f58c20 RC |
1586 | static void trace2_fetch_info(struct upload_pack_data *data) |
1587 | { | |
1588 | struct json_writer jw = JSON_WRITER_INIT; | |
1589 | ||
1590 | jw_object_begin(&jw, 0); | |
fae96274 | 1591 | jw_object_intmax(&jw, "haves", data->have_obj.nr); |
b8f58c20 | 1592 | jw_object_intmax(&jw, "wants", data->want_obj.nr); |
b065063c | 1593 | jw_object_intmax(&jw, "want-refs", strmap_get_size(&data->wanted_refs)); |
b8f58c20 RC |
1594 | jw_object_intmax(&jw, "depth", data->depth); |
1595 | jw_object_intmax(&jw, "shallows", data->shallows.nr); | |
1596 | jw_object_bool(&jw, "deepen-since", data->deepen_since); | |
388b96df | 1597 | jw_object_intmax(&jw, "deepen-not", oidset_size(&data->deepen_not)); |
b8f58c20 RC |
1598 | jw_object_bool(&jw, "deepen-relative", data->deepen_relative); |
1599 | if (data->filter_options.choice) | |
1600 | jw_object_string(&jw, "filter", list_object_filter_config_name(data->filter_options.choice)); | |
1601 | else | |
1602 | jw_object_null(&jw, "filter"); | |
1603 | jw_end(&jw); | |
1604 | ||
1605 | trace2_data_json("upload-pack", the_repository, "fetch-info", &jw); | |
1606 | ||
1607 | jw_release(&jw); | |
1608 | } | |
1609 | ||
3145ea95 | 1610 | static void process_args(struct packet_reader *request, |
389f161a | 1611 | struct upload_pack_data *data) |
3145ea95 | 1612 | { |
4845b772 | 1613 | while (packet_reader_read(request) == PACKET_READ_NORMAL) { |
3145ea95 | 1614 | const char *arg = request->line; |
ba95710a | 1615 | const char *p; |
3145ea95 BW |
1616 | |
1617 | /* process want */ | |
389f161a | 1618 | if (parse_want(&data->writer, arg, &data->want_obj)) |
3145ea95 | 1619 | continue; |
d1d7a945 | 1620 | if (data->allow_ref_in_want && |
bc2e795c | 1621 | parse_want_ref(&data->writer, arg, &data->wanted_refs, |
9b67eb6f | 1622 | &data->hidden_refs, &data->want_obj)) |
516e2b76 | 1623 | continue; |
3145ea95 | 1624 | /* process have line */ |
fae96274 | 1625 | if (parse_have(arg, data)) |
3145ea95 BW |
1626 | continue; |
1627 | ||
1628 | /* process args like thin-pack */ | |
1629 | if (!strcmp(arg, "thin-pack")) { | |
b5a2068c | 1630 | data->use_thin_pack = 1; |
3145ea95 BW |
1631 | continue; |
1632 | } | |
1633 | if (!strcmp(arg, "ofs-delta")) { | |
b5a2068c | 1634 | data->use_ofs_delta = 1; |
3145ea95 BW |
1635 | continue; |
1636 | } | |
1637 | if (!strcmp(arg, "no-progress")) { | |
b5a2068c | 1638 | data->no_progress = 1; |
3145ea95 BW |
1639 | continue; |
1640 | } | |
1641 | if (!strcmp(arg, "include-tag")) { | |
b5a2068c | 1642 | data->use_include_tag = 1; |
3145ea95 BW |
1643 | continue; |
1644 | } | |
1645 | if (!strcmp(arg, "done")) { | |
1646 | data->done = 1; | |
1647 | continue; | |
1648 | } | |
9c1e657a JT |
1649 | if (!strcmp(arg, "wait-for-done")) { |
1650 | data->wait_for_done = 1; | |
1651 | continue; | |
1652 | } | |
3145ea95 | 1653 | |
685fbd32 BW |
1654 | /* Shallow related arguments */ |
1655 | if (process_shallow(arg, &data->shallows)) | |
1656 | continue; | |
1657 | if (process_deepen(arg, &data->depth)) | |
1658 | continue; | |
1659 | if (process_deepen_since(arg, &data->deepen_since, | |
1660 | &data->deepen_rev_list)) | |
1661 | continue; | |
1662 | if (process_deepen_not(arg, &data->deepen_not, | |
1663 | &data->deepen_rev_list)) | |
1664 | continue; | |
1665 | if (!strcmp(arg, "deepen-relative")) { | |
1666 | data->deepen_relative = 1; | |
1667 | continue; | |
1668 | } | |
1669 | ||
59abe196 | 1670 | if (data->allow_filter && skip_prefix(arg, "filter ", &p)) { |
08450ef7 CC |
1671 | list_objects_filter_die_if_populated(&data->filter_options); |
1672 | parse_list_objects_filter(&data->filter_options, p); | |
6dd3456a | 1673 | die_if_using_banned_filter(data); |
ba95710a JT |
1674 | continue; |
1675 | } | |
1676 | ||
37aa89b0 | 1677 | if (data->allow_sideband_all && |
07c3c2aa | 1678 | !strcmp(arg, "sideband-all")) { |
0bbc0bc5 JT |
1679 | data->writer.use_sideband = 1; |
1680 | continue; | |
1681 | } | |
1682 | ||
a922bfa3 JK |
1683 | if (data->allow_packfile_uris && |
1684 | skip_prefix(arg, "packfile-uris ", &p)) { | |
179776f9 JK |
1685 | if (data->uri_protocols.nr) |
1686 | send_err_and_die(data, | |
1687 | "multiple packfile-uris lines forbidden"); | |
dd4b732d JT |
1688 | string_list_split(&data->uri_protocols, p, ',', -1); |
1689 | continue; | |
1690 | } | |
1691 | ||
3145ea95 | 1692 | /* ignore unknown lines maybe? */ |
7cc6ed2d | 1693 | die("unexpected line: '%s'", arg); |
3145ea95 | 1694 | } |
4845b772 | 1695 | |
dd4b732d JT |
1696 | if (data->uri_protocols.nr && !data->writer.use_sideband) |
1697 | string_list_clear(&data->uri_protocols, 0); | |
1698 | ||
4845b772 JK |
1699 | if (request->status != PACKET_READ_FLUSH) |
1700 | die(_("expected flush after fetch arguments")); | |
b8f58c20 RC |
1701 | |
1702 | if (trace2_is_enabled()) | |
1703 | trace2_fetch_info(data); | |
3145ea95 BW |
1704 | } |
1705 | ||
fae96274 | 1706 | static int send_acks(struct upload_pack_data *data, struct object_array *acks) |
3145ea95 BW |
1707 | { |
1708 | int i; | |
1709 | ||
6fbbc437 | 1710 | packet_writer_write(&data->writer, "acknowledgments\n"); |
3145ea95 BW |
1711 | |
1712 | /* Send Acks */ | |
1713 | if (!acks->nr) | |
6fbbc437 | 1714 | packet_writer_write(&data->writer, "NAK\n"); |
3145ea95 BW |
1715 | |
1716 | for (i = 0; i < acks->nr; i++) { | |
6fbbc437 | 1717 | packet_writer_write(&data->writer, "ACK %s\n", |
fae96274 | 1718 | oid_to_hex(&acks->objects[i].item->oid)); |
3145ea95 BW |
1719 | } |
1720 | ||
9c1e657a | 1721 | if (!data->wait_for_done && ok_to_give_up(data)) { |
3145ea95 | 1722 | /* Send Ready */ |
6fbbc437 | 1723 | packet_writer_write(&data->writer, "ready\n"); |
3145ea95 BW |
1724 | return 1; |
1725 | } | |
1726 | ||
1727 | return 0; | |
1728 | } | |
1729 | ||
389f161a | 1730 | static int process_haves_and_send_acks(struct upload_pack_data *data) |
3145ea95 | 1731 | { |
3145ea95 BW |
1732 | int ret = 0; |
1733 | ||
3145ea95 BW |
1734 | if (data->done) { |
1735 | ret = 1; | |
fae96274 | 1736 | } else if (send_acks(data, &data->have_obj)) { |
bc2e795c | 1737 | packet_writer_delim(&data->writer); |
3145ea95 BW |
1738 | ret = 1; |
1739 | } else { | |
1740 | /* Add Flush */ | |
bc2e795c | 1741 | packet_writer_flush(&data->writer); |
3145ea95 BW |
1742 | ret = 0; |
1743 | } | |
1744 | ||
3145ea95 BW |
1745 | return ret; |
1746 | } | |
1747 | ||
516e2b76 BW |
1748 | static void send_wanted_ref_info(struct upload_pack_data *data) |
1749 | { | |
b065063c JK |
1750 | struct hashmap_iter iter; |
1751 | const struct strmap_entry *e; | |
516e2b76 | 1752 | |
b065063c | 1753 | if (strmap_empty(&data->wanted_refs)) |
516e2b76 BW |
1754 | return; |
1755 | ||
bc2e795c | 1756 | packet_writer_write(&data->writer, "wanted-refs\n"); |
516e2b76 | 1757 | |
b065063c | 1758 | strmap_for_each_entry(&data->wanted_refs, &iter, e) { |
bc2e795c | 1759 | packet_writer_write(&data->writer, "%s %s\n", |
b065063c JK |
1760 | oid_to_hex(e->value), |
1761 | e->key); | |
516e2b76 BW |
1762 | } |
1763 | ||
bc2e795c | 1764 | packet_writer_delim(&data->writer); |
516e2b76 BW |
1765 | } |
1766 | ||
389f161a | 1767 | static void send_shallow_info(struct upload_pack_data *data) |
685fbd32 BW |
1768 | { |
1769 | /* No shallow info needs to be sent */ | |
1770 | if (!data->depth && !data->deepen_rev_list && !data->shallows.nr && | |
00624d60 | 1771 | !is_repository_shallow(the_repository)) |
685fbd32 BW |
1772 | return; |
1773 | ||
bc2e795c | 1774 | packet_writer_write(&data->writer, "shallow-info\n"); |
685fbd32 | 1775 | |
ee703c8a | 1776 | if (!send_shallow_list(data) && |
00624d60 | 1777 | is_repository_shallow(the_repository)) |
b1492f22 | 1778 | deepen(data, INFINITE_DEPTH); |
685fbd32 BW |
1779 | |
1780 | packet_delim(1); | |
1781 | } | |
1782 | ||
bf0468e2 JS |
1783 | enum upload_state { |
1784 | UPLOAD_PROCESS_ARGS = 0, | |
1785 | UPLOAD_SEND_ACKS, | |
1786 | UPLOAD_SEND_PACK, | |
1787 | UPLOAD_DONE, | |
3145ea95 BW |
1788 | }; |
1789 | ||
922fdefb | 1790 | int upload_pack_v2(struct repository *r, struct packet_reader *request) |
3145ea95 | 1791 | { |
bf0468e2 | 1792 | enum upload_state state = UPLOAD_PROCESS_ARGS; |
3145ea95 | 1793 | struct upload_pack_data data; |
d1035cac | 1794 | |
74d414c9 | 1795 | clear_object_flags(the_repository, ALL_FLAGS); |
3145ea95 BW |
1796 | |
1797 | upload_pack_data_init(&data); | |
f8edd1ca | 1798 | data.use_sideband = LARGE_PACKET_MAX; |
922fdefb | 1799 | get_upload_pack_config(r, &data); |
8a0e6f16 | 1800 | |
bf0468e2 | 1801 | while (state != UPLOAD_DONE) { |
3145ea95 | 1802 | switch (state) { |
bf0468e2 | 1803 | case UPLOAD_PROCESS_ARGS: |
389f161a | 1804 | process_args(request, &data); |
3145ea95 | 1805 | |
9c1e657a | 1806 | if (!data.want_obj.nr && !data.wait_for_done) { |
3145ea95 | 1807 | /* |
9c1e657a JT |
1808 | * Request didn't contain any 'want' lines (and |
1809 | * the request does not contain | |
1810 | * "wait-for-done", in which it is reasonable | |
1811 | * to just send 'have's without 'want's); guess | |
1812 | * they didn't want anything. | |
3145ea95 | 1813 | */ |
bf0468e2 | 1814 | state = UPLOAD_DONE; |
fae96274 | 1815 | } else if (data.seen_haves) { |
3145ea95 BW |
1816 | /* |
1817 | * Request had 'have' lines, so lets ACK them. | |
1818 | */ | |
bf0468e2 | 1819 | state = UPLOAD_SEND_ACKS; |
3145ea95 BW |
1820 | } else { |
1821 | /* | |
1822 | * Request had 'want's but no 'have's so we can | |
e02cc08a | 1823 | * immediately go to construct and send a pack. |
3145ea95 | 1824 | */ |
bf0468e2 | 1825 | state = UPLOAD_SEND_PACK; |
3145ea95 BW |
1826 | } |
1827 | break; | |
bf0468e2 | 1828 | case UPLOAD_SEND_ACKS: |
389f161a | 1829 | if (process_haves_and_send_acks(&data)) |
bf0468e2 | 1830 | state = UPLOAD_SEND_PACK; |
3145ea95 | 1831 | else |
bf0468e2 | 1832 | state = UPLOAD_DONE; |
3145ea95 | 1833 | break; |
bf0468e2 | 1834 | case UPLOAD_SEND_PACK: |
516e2b76 | 1835 | send_wanted_ref_info(&data); |
389f161a | 1836 | send_shallow_info(&data); |
685fbd32 | 1837 | |
dd4b732d JT |
1838 | if (data.uri_protocols.nr) { |
1839 | create_pack_file(&data, &data.uri_protocols); | |
1840 | } else { | |
1841 | packet_writer_write(&data.writer, "packfile\n"); | |
1842 | create_pack_file(&data, NULL); | |
1843 | } | |
bf0468e2 | 1844 | state = UPLOAD_DONE; |
3145ea95 | 1845 | break; |
bf0468e2 | 1846 | case UPLOAD_DONE: |
3145ea95 BW |
1847 | continue; |
1848 | } | |
1849 | } | |
1850 | ||
1851 | upload_pack_data_clear(&data); | |
1852 | return 0; | |
1853 | } | |
685fbd32 BW |
1854 | |
1855 | int upload_pack_advertise(struct repository *r, | |
1856 | struct strbuf *value) | |
1857 | { | |
9a7b2295 JK |
1858 | struct upload_pack_data data; |
1859 | ||
1860 | upload_pack_data_init(&data); | |
1861 | get_upload_pack_config(r, &data); | |
516e2b76 | 1862 | |
ba95710a | 1863 | if (value) { |
9c1e657a | 1864 | strbuf_addstr(value, "shallow wait-for-done"); |
516e2b76 | 1865 | |
9a7b2295 | 1866 | if (data.allow_filter) |
ba95710a | 1867 | strbuf_addstr(value, " filter"); |
516e2b76 | 1868 | |
9a7b2295 | 1869 | if (data.allow_ref_in_want) |
516e2b76 | 1870 | strbuf_addstr(value, " ref-in-want"); |
0bbc0bc5 | 1871 | |
9a7b2295 | 1872 | if (data.allow_sideband_all) |
0bbc0bc5 | 1873 | strbuf_addstr(value, " sideband-all"); |
dd4b732d | 1874 | |
a922bfa3 | 1875 | if (data.allow_packfile_uris) |
dd4b732d | 1876 | strbuf_addstr(value, " packfile-uris"); |
ba95710a | 1877 | } |
516e2b76 | 1878 | |
9a7b2295 JK |
1879 | upload_pack_data_clear(&data); |
1880 | ||
685fbd32 BW |
1881 | return 1; |
1882 | } |