commit aecd22250a8ec26da244683ed64b290af0e1c5f3 from: Stefan Sperling via: Thomas Adam date: Thu Oct 20 16:16:03 2022 UTC let callers of got_pack_index() configure the rate limit of progress reporting commit - 142012ed272189c29b42a3ec63ff2598b82ec88f commit + aecd22250a8ec26da244683ed64b290af0e1c5f3 blob - 4ccb85602edfc0c368dc34ae06bdbbb56e4c04c8 blob + 5a2aab6936ab69339d4222d09c60d58f421d067c --- lib/got_lib_pack_index.h +++ lib/got_lib_pack_index.h @@ -21,4 +21,5 @@ const struct got_error * got_pack_index(struct got_pack *pack, int idxfd, FILE *tmpfile, FILE *delta_base_file, FILE *delta_accum_file, uint8_t *pack_sha1_expected, - got_pack_index_progress_cb progress_cb, void *progress_arg); + got_pack_index_progress_cb progress_cb, void *progress_arg, + struct got_ratelimit *rl); blob - 16dba396458c110a7862ab44e90a0b8da95e14c9 blob + d0b713ea9964a6d53335b7f910b6143346ea77e3 --- lib/pack_index.c +++ lib/pack_index.c @@ -611,7 +611,8 @@ report_progress(int nobj_total, int nobj_indexed, int const struct got_error * got_pack_index(struct got_pack *pack, int idxfd, FILE *tmpfile, FILE *delta_base_file, FILE *delta_accum_file, uint8_t *pack_sha1_expected, - got_pack_index_progress_cb progress_cb, void *progress_arg) + got_pack_index_progress_cb progress_cb, void *progress_arg, + struct got_ratelimit *rl) { const struct got_error *err; struct got_packfile_hdr hdr; @@ -627,7 +628,6 @@ got_pack_index(struct got_pack *pack, int idxfd, FILE size_t mapoff = 0; int p_indexed = 0, last_p_indexed = -1; int p_resolved = 0, last_p_resolved = -1; - struct got_ratelimit rl; /* Require that pack file header and SHA1 trailer are present. */ if (pack->filesize < sizeof(hdr) + SHA1_DIGEST_LENGTH) @@ -714,8 +714,6 @@ got_pack_index(struct got_pack *pack, int idxfd, FILE objects = calloc(nobj, sizeof(struct got_indexed_object)); if (objects == NULL) return got_error_from_errno("calloc"); - - got_ratelimit_init(&rl, 0, 500); /* * First pass: locate all objects and identify un-deltified objects. @@ -731,7 +729,7 @@ got_pack_index(struct got_pack *pack, int idxfd, FILE p_indexed = ((i + 1) * 100) / nobj; if (p_indexed != last_p_indexed) { err = report_progress(nobj, i + 1, nloose, 0, - &rl, progress_cb, progress_arg); + rl, progress_cb, progress_arg); if (err) goto done; last_p_indexed = p_indexed; @@ -876,7 +874,7 @@ got_pack_index(struct got_pack *pack, int idxfd, FILE p_resolved = ((nresolved + n) * 100) / nobj; if (p_resolved != last_p_resolved) { err = report_progress(nobj, nobj, - nloose, nresolved + n, &rl, + nloose, nresolved + n, rl, progress_cb, progress_arg); if (err) goto done; blob - 4c37f22628cde5152889139edf95ebd106cd856b blob + 79332977ce92e1d62e1c06929a238b1e4cf62516 --- libexec/got-index-pack/got-index-pack.c +++ libexec/got-index-pack/got-index-pack.c @@ -85,12 +85,15 @@ main(int argc, char **argv) struct got_pack pack; uint8_t pack_hash[SHA1_DIGEST_LENGTH]; off_t packfile_size; + struct got_ratelimit rl; #if 0 static int attached; while (!attached) sleep(1); #endif + got_ratelimit_init(&rl, 0, 500); + for (i = 0; i < nitems(tmpfiles); i++) tmpfiles[i] = NULL; @@ -197,8 +200,8 @@ main(int argc, char **argv) if (pack.map == MAP_FAILED) pack.map = NULL; /* fall back to read(2) */ #endif - err = got_pack_index(&pack, idxfd, tmpfiles[0], tmpfiles[1], tmpfiles[2], - pack_hash, send_index_pack_progress, &ibuf); + err = got_pack_index(&pack, idxfd, tmpfiles[0], tmpfiles[1], + tmpfiles[2], pack_hash, send_index_pack_progress, &ibuf, &rl); done: close_err = got_pack_close(&pack); if (close_err && err == NULL)