MCPcopy Index your code
hub / github.com/git/git / relay_pack_data

Function relay_pack_data

upload-pack.c:221–297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

219};
220
221static int relay_pack_data(int pack_objects_out, struct output_state *os,
222 int use_sideband, int write_packfile_line,
223 bool *did_send_data)
224{
225 /*
226 * We keep the last byte to ourselves
227 * in case we detect broken rev-list, so that we
228 * can leave the stream corrupted. This is
229 * unfortunate -- unpack-objects would happily
230 * accept a valid packdata with trailing garbage,
231 * so appending garbage after we pass all the
232 * pack data is not good enough to signal
233 * breakage to downstream.
234 */
235 ssize_t readsz;
236
237 *did_send_data = false;
238
239 readsz = xread(pack_objects_out, os->buffer + os->used,
240 sizeof(os->buffer) - os->used);
241 if (readsz < 0) {
242 return readsz;
243 }
244 os->used += readsz;
245
246 while (!os->packfile_started) {
247 char *p;
248 if (os->used >= 4 && !memcmp(os->buffer, "PACK", 4)) {
249 os->packfile_started = 1;
250 if (write_packfile_line) {
251 if (os->packfile_uris_started)
252 packet_delim(1);
253 packet_write_fmt(1, "\1packfile\n");
254 *did_send_data = true;
255 }
256 break;
257 }
258 if ((p = memchr(os->buffer, '\n', os->used))) {
259 if (!os->packfile_uris_started) {
260 os->packfile_uris_started = 1;
261 if (!write_packfile_line)
262 BUG("packfile_uris requires sideband-all");
263 packet_write_fmt(1, "\1packfile-uris\n");
264 }
265 *p = '\0';
266 packet_write_fmt(1, "\1%s\n", os->buffer);
267 *did_send_data = true;
268
269 os->used -= p - os->buffer + 1;
270 memmove(os->buffer, p + 1, os->used);
271 } else {
272 /*
273 * Incomplete line.
274 */
275 return readsz;
276 }
277 }
278

Callers 1

create_pack_fileFunction · 0.85

Calls 4

xreadFunction · 0.85
packet_delimFunction · 0.85
packet_write_fmtFunction · 0.85
send_client_dataFunction · 0.85

Tested by

no test coverage detected