From 5038de19377ccc334c0ce3e1f206dddc20ac88c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sat, 6 Apr 2019 18:34:23 +0700 Subject: packfile.c: add repo_approximate_object_count() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano diff --git a/packfile.c b/packfile.c index 16bcb75..2ad4fab 100644 --- a/packfile.c +++ b/packfile.c @@ -893,25 +893,25 @@ static void prepare_packed_git(struct repository *r); * all unreachable objects about to be pruned, in which case they're not really * interesting as a measure of repo size in the first place. */ -unsigned long approximate_object_count(void) +unsigned long repo_approximate_object_count(struct repository *r) { - if (!the_repository->objects->approximate_object_count_valid) { + if (!r->objects->approximate_object_count_valid) { unsigned long count; struct multi_pack_index *m; struct packed_git *p; - prepare_packed_git(the_repository); + prepare_packed_git(r); count = 0; - for (m = get_multi_pack_index(the_repository); m; m = m->next) + for (m = get_multi_pack_index(r); m; m = m->next) count += m->num_objects; - for (p = the_repository->objects->packed_git; p; p = p->next) { + for (p = r->objects->packed_git; p; p = p->next) { if (open_pack_index(p)) continue; count += p->num_objects; } - the_repository->objects->approximate_object_count = count; + r->objects->approximate_object_count = count; } - return the_repository->objects->approximate_object_count; + return r->objects->approximate_object_count; } static void *get_next_packed_git(const void *p) diff --git a/packfile.h b/packfile.h index d70c6d9..f04440f 100644 --- a/packfile.h +++ b/packfile.h @@ -57,7 +57,8 @@ struct packed_git *get_all_packs(struct repository *r); * Give a rough count of objects in the repository. This sacrifices accuracy * for speed. */ -unsigned long approximate_object_count(void); +unsigned long repo_approximate_object_count(struct repository *r); +#define approximate_object_count() repo_approximate_object_count(the_repository) extern struct packed_git *find_sha1_pack(const unsigned char *sha1, struct packed_git *packs); -- cgit v0.10.2-6-g49f6