pack: move approximate object count to object store
The approximate_object_count() function maintains a rough count of objects in a repository to estimate how long object name abbreviates should be. Object names are scoped to a repository and the appropriate length may differ by repository, so the object count should not be global. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Mar 23, 2018 at 18:21 UTC
9a00580d0383fe60c70e966e66584e626ca3a846
2 files changed
+13
-6
object-store.h
+8
@@ -99,6 +99,14 @@ struct raw_object_store {
99
/* A most-recently-used ordered version of the packed_git list. */
100
struct list_head packed_git_mru;
101
102
+ /*
103
+ * A fast, rough count of the number of objects in the repository.
104
+ * These two fields are not meant for direct access. Use
105
+ * approximate_object_count() instead.
106
+ */
107
+ unsigned long approximate_object_count;
108
+ unsigned approximate_object_count_valid : 1;
109
+
110
/*
111
* Whether packed_git has already been populated with this repository's
112
* packs.
packfile.c
+5
-6
@@ -803,8 +803,6 @@ static void prepare_packed_git_one(char *objdir, int local)
803
strbuf_release(&path);
804
}
805
806
-static int approximate_object_count_valid;
807
-
806
/*
807
* Give a fast, rough count of the number of objects in the repository. This
808
* ignores loose objects completely. If you have a lot of them, then either
@@ -814,8 +812,8 @@ static int approximate_object_count_valid;
812
*/
813
unsigned long approximate_object_count(void)
814
{
817
- static unsigned long count;
818
- if (!approximate_object_count_valid) {
815
+ if (!the_repository->objects->approximate_object_count_valid) {
816
+ unsigned long count;
817
struct packed_git *p;
818
819
prepare_packed_git();
@@ -825,8 +823,9 @@ unsigned long approximate_object_count(void)
823
continue;
824
count += p->num_objects;
825
}
826
+ the_repository->objects->approximate_object_count = count;
827
}
829
- return count;
828
+ return the_repository->objects->approximate_object_count;
829
}
830
831
static void *get_next_packed_git(const void *p)
@@ -901,7 +900,7 @@ void prepare_packed_git(void)
900
901
void reprepare_packed_git(void)
902
{
904
- approximate_object_count_valid = 0;
903
+ the_repository->objects->approximate_object_count_valid = 0;
904
the_repository->objects->packed_git_initialized = 0;
905
prepare_packed_git();
906
}