stagit

fork of git.codemadness.org/stagit
Log | Files | Refs | README | LICENSE

commit bd7f58c9853d08e124e836d0c2e83c048a4f52eb (tree)
parent 6d75d6e2dc96e6df2e71ef4894295d01a7e235f2
Author: Motiejus Jakštys <motiejus@jakstys.lt>
Date:   Mon, 29 Jun 2026 16:46:30 +0000

progress

Diffstat:
Mstagit.c | 34++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+), 0 deletions(-)

diff --git a/stagit.c b/stagit.c @@ -1484,13 +1484,39 @@ writetreepage(const git_oid *commitid, git_repository *r) return 0; } +struct progress { + size_t done; + size_t total; + time_t last_report; + pthread_mutex_t mtx; +}; + struct tree_work { git_oid *oids; size_t start, end; const char *repodir; + struct progress *prog; int failed; }; +static void +progress_report(struct progress *p) +{ + time_t now; + + pthread_mutex_lock(&p->mtx); + p->done++; + now = time(NULL); + if (now - p->last_report >= 10) { + p->last_report = now; + fprintf(stderr, "writetrees: %zu/%zu commits, " + "%u unique trees, %u unique blobs\n", + p->done, p->total, + treeset.count, blobset.count); + } + pthread_mutex_unlock(&p->mtx); +} + static void * tree_worker(void *arg) { @@ -1509,6 +1535,7 @@ tree_worker(void *arg) w->failed = 1; break; } + progress_report(w->prog); } git_repository_free(r); @@ -1546,10 +1573,13 @@ writetrees(const git_oid *head) return; } + struct progress prog = { .total = noids, .mtx = PTHREAD_MUTEX_INITIALIZER }; + if (nthreads <= 1) { for (i = 0; i < noids; i++) { if (writetreepage(&oids[i], repo) < 0) errx(1, "writetreepage failed"); + progress_report(&prog); } } else { pthread_t *threads; @@ -1571,6 +1601,7 @@ writetrees(const git_oid *head) works[t].start = t * per; works[t].end = (t == nt - 1) ? noids : (t + 1) * per; works[t].repodir = repodir; + works[t].prog = &prog; if (pthread_create(&threads[t], NULL, tree_worker, &works[t])) err(1, "pthread_create"); @@ -1586,6 +1617,9 @@ writetrees(const git_oid *head) errx(1, "tree worker failed"); } + fprintf(stderr, "writetrees: done, %u unique trees, %u unique blobs\n", + treeset.count, blobset.count); + free(oids); }