| 1329 | ); |
| 1330 | |
| 1331 | static void write_pack_file(void) |
| 1332 | { |
| 1333 | uint32_t i = 0, j; |
| 1334 | struct hashfile *f; |
| 1335 | off_t offset; |
| 1336 | uint32_t nr_remaining = nr_result; |
| 1337 | time_t last_mtime = 0; |
| 1338 | struct object_entry **write_order; |
| 1339 | |
| 1340 | if (progress > pack_to_stdout) |
| 1341 | progress_state = start_progress(the_repository, |
| 1342 | _("Writing objects"), nr_result); |
| 1343 | ALLOC_ARRAY(written_list, to_pack.nr_objects); |
| 1344 | write_order = compute_write_order(); |
| 1345 | |
| 1346 | do { |
| 1347 | unsigned char hash[GIT_MAX_RAWSZ]; |
| 1348 | char *pack_tmp_name = NULL; |
| 1349 | |
| 1350 | if (pack_to_stdout) { |
| 1351 | /* |
| 1352 | * This command is most often invoked via |
| 1353 | * git-upload-pack(1), which will typically chunk data |
| 1354 | * into pktlines. As such, we use the maximum data |
| 1355 | * length of them as buffer length. |
| 1356 | * |
| 1357 | * Note that we need to subtract one though to |
| 1358 | * accommodate for the sideband byte. |
| 1359 | */ |
| 1360 | struct hashfd_options opts = { |
| 1361 | .progress = progress_state, |
| 1362 | .buffer_len = LARGE_PACKET_DATA_MAX - 1, |
| 1363 | }; |
| 1364 | f = hashfd_ext(the_repository->hash_algo, 1, |
| 1365 | "<stdout>", &opts); |
| 1366 | } else { |
| 1367 | f = create_tmp_packfile(the_repository, &pack_tmp_name); |
| 1368 | } |
| 1369 | |
| 1370 | offset = write_pack_header(f, nr_remaining); |
| 1371 | |
| 1372 | if (reuse_packfiles_nr) { |
| 1373 | assert(pack_to_stdout); |
| 1374 | for (j = 0; j < reuse_packfiles_nr; j++) { |
| 1375 | reused_chunks_nr = 0; |
| 1376 | write_reused_pack(&reuse_packfiles[j], f); |
| 1377 | if (reused_chunks_nr) |
| 1378 | reuse_packfiles_used_nr++; |
| 1379 | } |
| 1380 | offset = hashfile_total(f); |
| 1381 | } |
| 1382 | |
| 1383 | nr_written = 0; |
| 1384 | for (; i < to_pack.nr_objects; i++) { |
| 1385 | struct object_entry *e = write_order[i]; |
| 1386 | if (write_one(f, e, &offset) == WRITE_ONE_BREAK) |
| 1387 | break; |
| 1388 | display_progress(progress_state, written); |
no test coverage detected