packfile.c: add repo_approximate_object_count()

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Apr 6, 2019 at 18:34 UTC 5038de19377ccc334c0ce3e1f206dddc20ac88c1
2 files changed +9 -8
packfile.c
+7 -7
@@ -893,25 +893,25 @@ static void prepare_packed_git(struct repository *r);
893 * all unreachable objects about to be pruned, in which case they're not really
894 * interesting as a measure of repo size in the first place.
895 */
896 -unsigned long approximate_object_count(void)
896 +unsigned long repo_approximate_object_count(struct repository *r)
897 {
898 - if (!the_repository->objects->approximate_object_count_valid) {
898 + if (!r->objects->approximate_object_count_valid) {
899 unsigned long count;
900 struct multi_pack_index *m;
901 struct packed_git *p;
902
903 - prepare_packed_git(the_repository);
903 + prepare_packed_git(r);
904 count = 0;
905 - for (m = get_multi_pack_index(the_repository); m; m = m->next)
905 + for (m = get_multi_pack_index(r); m; m = m->next)
906 count += m->num_objects;
907 - for (p = the_repository->objects->packed_git; p; p = p->next) {
907 + for (p = r->objects->packed_git; p; p = p->next) {
908 if (open_pack_index(p))
909 continue;
910 count += p->num_objects;
911 }
912 - the_repository->objects->approximate_object_count = count;
912 + r->objects->approximate_object_count = count;
913 }
914 - return the_repository->objects->approximate_object_count;
914 + return r->objects->approximate_object_count;
915 }
916
917 static void *get_next_packed_git(const void *p)
packfile.h
+2 -1
@@ -57,7 +57,8 @@ struct packed_git *get_all_packs(struct repository *r);
57 * Give a rough count of objects in the repository. This sacrifices accuracy
58 * for speed.
59 */
60 -unsigned long approximate_object_count(void);
60 +unsigned long repo_approximate_object_count(struct repository *r);
61 +#define approximate_object_count() repo_approximate_object_count(the_repository)
62
63 extern struct packed_git *find_sha1_pack(const unsigned char *sha1,
64 struct packed_git *packs);