From: Emily Shaffer <emilyshaffer@xxxxxxxxxx> 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. Signed-off-by: Emily Shaffer <emilyshaffer@xxxxxxxxxx> --- bugreport.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/bugreport.c b/bugreport.c index bf10857183..45cc1764e0 100644 --- a/bugreport.c +++ b/bugreport.c @@ -214,6 +214,41 @@ static void get_loose_object_summary(struct strbuf *obj_info) { total_count_questionable ? " (problem during count)" : ""); } +struct packed_object_cb_data { + struct packed_git *last_pack; + int pack_count; + int object_count; +}; + +static int packed_object_cb(const struct object_id *oid, + struct packed_git *pack, + uint32_t pos, + void *data) { + struct packed_object_cb_data *cb_data = data; + + if (!cb_data) + return 1; + + if (pack && pack != cb_data->last_pack) { + cb_data->last_pack = pack; + cb_data->pack_count++; + } + + cb_data->object_count++; + + return 0; +} + +static void get_packed_object_summary(struct strbuf *obj_info) +{ + struct packed_object_cb_data cb_data = {NULL, 0, 0}; + + for_each_packed_object(packed_object_cb, &cb_data, 0); + + strbuf_addf(obj_info, "%d total packs (%d objects)\n", + cb_data.pack_count, cb_data.object_count); +} + static const char * const bugreport_usage[] = { N_("git bugreport [-o|--output <file>]"), NULL @@ -292,6 +327,9 @@ int cmd_main(int argc, const char **argv) get_header(&buffer, "Loose Object Counts"); get_loose_object_summary(&buffer); + get_header(&buffer, "Packed Object Summary"); + get_packed_object_summary(&buffer); + report = fopen_for_writing(report_path.buf); strbuf_write(&buffer, report); fclose(report); -- 2.25.0.341.g760bfbb309-goog