@@ -33,6 +33,7 @@ The following information is captured automatically:
- Selected config values
- A list of enabled hooks
- The number of loose objects in the repository
+ - The number of packs and packed objects in the repository
OPTIONS
-------
@@ -177,6 +177,33 @@ static void get_loose_object_summary(struct strbuf *obj_info, int nongit) {
total_count_questionable ? " (problem during count)" : "");
}
+static void get_packed_object_summary(struct strbuf *obj_info, int nongit)
+{
+ struct packed_git *pack = NULL;
+ int pack_count = 0;
+ int object_count = 0;
+
+ if (nongit) {
+ strbuf_addstr(obj_info,
+ "not run from a git repository - no objects to show\n");
+ return;
+ }
+
+ for_each_pack(the_repository, pack) {
+ pack_count++;
+ /*
+ * To accurately count how many objects are packed, look inside
+ * the packfile's index.
+ */
+ open_pack_index(pack);
+ object_count += pack->num_objects;
+ }
+
+ strbuf_addf(obj_info, "%d total packs (%d objects)\n", pack_count,
+ object_count);
+
+}
+
static const char * const bugreport_usage[] = {
N_("git bugreport [-o|--output-directory <file>] [-s|--suffix <format>]"),
NULL
@@ -262,6 +289,9 @@ int cmd_main(int argc, const char **argv)
get_header(&buffer, "Loose Object Counts");
get_loose_object_summary(&buffer, nongit_ok);
+ get_header(&buffer, "Packed Object Summary");
+ get_packed_object_summary(&buffer, nongit_ok);
+
report = fopen_for_writing(report_path.buf);
if (report == NULL) {
@@ -6,6 +6,7 @@
#include "list.h"
#include "sha1-array.h"
#include "strbuf.h"
+#include "packfile.h"
struct object_directory {
struct object_directory *next;
@@ -403,4 +404,9 @@ int for_each_object_in_pack(struct packed_git *p,
int for_each_packed_object(each_packed_object_fn, void *,
enum for_each_object_flags flags);
+#define for_each_pack(repo, pack) \
+ for (pack = get_all_packs(repo);\
+ pack; \
+ pack = pack->next)
+
#endif /* OBJECT_STORE_H */
@@ -2061,8 +2061,7 @@ int for_each_packed_object(each_packed_object_fn cb, void *data,
int r = 0;
int pack_errors = 0;
- prepare_packed_git(the_repository);
- for (p = get_all_packs(the_repository); p; p = p->next) {
+ for_each_pack(the_repository, p) {
if ((flags & FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local)
continue;
if ((flags & FOR_EACH_OBJECT_PROMISOR_ONLY) &&
Alongside the loose object counts, it can be useful to show the number of packs and packed objects. This way we can check whether the repo has an appropriate ratio of packed to loose objects to help determine whether it's behaving correctly. Add a utility to easily traverse all packfiles in a given repository. Use it in packfile.c and remove a redundant call to prepare_packed_git(), which is already called in get_all_packs(). Signed-off-by: Emily Shaffer <emilyshaffer@google.com> --- Perhaps the macro should be in another patch? I didn't spend a lot of time looking for anybody who could conceivably be iterating packs; if I were to do so, I'd break this change out separately. I considered following the pattern in the rest of the file, where the foreach takes a callback and data pointer, but found it would be cumbersome to use with for_each_packed_object() - I'd have to add a new callback just to handle the pack, and bundle that function's callback data along with the callback pointer. It seemed like overkill. - Emily Documentation/git-bugreport.txt | 1 + bugreport.c | 30 ++++++++++++++++++++++++++++++ object-store.h | 6 ++++++ packfile.c | 3 +-- 4 files changed, 38 insertions(+), 2 deletions(-)