Commit Diff


commit - e3f8625647b5837c386e831cce4e69268343b5d9
commit + d0f1e2f1b9f0e472831dc88cc9885c61d52c87f1
blob - 483b83598ba5e1661ebbc0d8fb41bc95091a622b
blob + 08a453bfb0c380f3a41b86d6d1d0c7024fd94604
--- libexec/got-index-pack/Makefile
+++ libexec/got-index-pack/Makefile
@@ -4,7 +4,7 @@
 
 PROG=		got-index-pack
 SRCS=		got-index-pack.c error.c inflate.c object_parse.c object_idset.c \
-		delta_cache.c delta.c pack.c path.c privsep.c sha1.c
+		delta_cache.c delta.c pack.c path.c privsep.c sha1.c ratelimit.c
 
 CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
 LDADD = -lutil -lz
blob - bd07835c365de5a12c8b254209ac1fbe27a312a9
blob + 8c98a684210fa971a6971574e89365cac98a43db
--- libexec/got-index-pack/got-index-pack.c
+++ libexec/got-index-pack/got-index-pack.c
@@ -52,6 +52,7 @@
 #include "got_lib_privsep.h"
 #include "got_lib_pack.h"
 #include "got_lib_delta_cache.h"
+#include "got_lib_ratelimit.h"
 
 #ifndef nitems
 #define nitems(_a)	(sizeof((_a)) / sizeof((_a)[0]))
@@ -594,9 +595,18 @@ update_packidx(struct got_packidx *packidx, int nobj,
 
 static const struct got_error *
 send_index_pack_progress(struct imsgbuf *ibuf, int nobj_total,
-    int nobj_indexed, int nobj_loose, int nobj_resolved)
+    int nobj_indexed, int nobj_loose, int nobj_resolved,
+    struct got_ratelimit *rl)
 {
+	const struct got_error *err;
 	struct got_imsg_index_pack_progress iprogress;
+	int elapsed = 0;
+
+	if (rl) {
+		err = got_ratelimit_check(&elapsed, rl);
+		if (err || !elapsed)
+			return err;
+	}
 
 	iprogress.nobj_total = nobj_total;
 	iprogress.nobj_indexed = nobj_indexed;
@@ -638,6 +648,7 @@ index_pack(struct got_pack *pack, int idxfd, FILE *tmp
 	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)
@@ -725,6 +736,8 @@ index_pack(struct got_pack *pack, int idxfd, FILE *tmp
 	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.
 	 *
@@ -739,7 +752,7 @@ index_pack(struct got_pack *pack, int idxfd, FILE *tmp
 		p_indexed = ((i + 1) * 100) / nobj;
 		if (p_indexed != last_p_indexed) {
 			err = send_index_pack_progress(ibuf, nobj, i + 1,
-			    nloose, 0);
+			    nloose, 0, &rl);
 			if (err)
 				goto done;
 			last_p_indexed = p_indexed;
@@ -884,7 +897,7 @@ index_pack(struct got_pack *pack, int idxfd, FILE *tmp
 			p_resolved = ((nresolved + n) * 100) / nobj;
 			if (p_resolved != last_p_resolved) {
 				err = send_index_pack_progress(ibuf, nobj,
-				    nobj, nloose, nresolved + n);
+				    nobj, nloose, nresolved + n, &rl);
 				if (err)
 					goto done;
 				last_p_resolved = p_resolved;
@@ -911,7 +924,8 @@ index_pack(struct got_pack *pack, int idxfd, FILE *tmp
 		goto done;
 	}
 
-	err = send_index_pack_progress(ibuf, nobj, nobj, nloose, nresolved);
+	err = send_index_pack_progress(ibuf, nobj, nobj, nloose, nresolved,
+	    NULL);
 	if (err)
 		goto done;