Skip to content

Commit 7a226a6

Browse files
nasamuffingitster
authored andcommitted
bugreport: add packed object summary
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7a4dc0e commit 7a226a6

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

Documentation/git-bugreport.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ The following information is captured automatically:
3333
- Selected config values
3434
- A list of enabled hooks
3535
- The number of loose objects in the repository
36+
- The number of packs and packed objects in the repository
3637

3738
This tool is invoked via the typical Git setup process, which means that in some
3839
cases, it might not be able to launch - for example, if a relevant config file

bugreport.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,33 @@ static void get_loose_object_summary(struct strbuf *obj_info, int nongit) {
177177
total_count_questionable ? " (problem during count)" : "");
178178
}
179179

180+
static void get_packed_object_summary(struct strbuf *obj_info, int nongit)
181+
{
182+
struct packed_git *pack = NULL;
183+
int pack_count = 0;
184+
int object_count = 0;
185+
186+
if (nongit) {
187+
strbuf_addstr(obj_info,
188+
"not run from a git repository - no objects to show\n");
189+
return;
190+
}
191+
192+
for_each_pack(the_repository, pack) {
193+
pack_count++;
194+
/*
195+
* To accurately count how many objects are packed, look inside
196+
* the packfile's index.
197+
*/
198+
open_pack_index(pack);
199+
object_count += pack->num_objects;
200+
}
201+
202+
strbuf_addf(obj_info, "%d total packs (%d objects)\n", pack_count,
203+
object_count);
204+
205+
}
206+
180207
static const char * const bugreport_usage[] = {
181208
N_("git bugreport [-o|--output-directory <file>] [-s|--suffix <format>]"),
182209
NULL
@@ -271,6 +298,9 @@ int cmd_main(int argc, const char **argv)
271298
get_header(&buffer, "Loose Object Counts");
272299
get_loose_object_summary(&buffer, nongit_ok);
273300

301+
get_header(&buffer, "Packed Object Summary");
302+
get_packed_object_summary(&buffer, nongit_ok);
303+
274304
report = fopen_for_writing(report_path.buf);
275305

276306
if (report == NULL) {

object-store.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "list.h"
77
#include "sha1-array.h"
88
#include "strbuf.h"
9+
#include "packfile.h"
910

1011
struct object_directory {
1112
struct object_directory *next;
@@ -403,4 +404,9 @@ int for_each_object_in_pack(struct packed_git *p,
403404
int for_each_packed_object(each_packed_object_fn, void *,
404405
enum for_each_object_flags flags);
405406

407+
#define for_each_pack(repo, pack) \
408+
for (pack = get_all_packs(repo);\
409+
pack; \
410+
pack = pack->next)
411+
406412
#endif /* OBJECT_STORE_H */

packfile.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,8 +2061,7 @@ int for_each_packed_object(each_packed_object_fn cb, void *data,
20612061
int r = 0;
20622062
int pack_errors = 0;
20632063

2064-
prepare_packed_git(the_repository);
2065-
for (p = get_all_packs(the_repository); p; p = p->next) {
2064+
for_each_pack(the_repository, p) {
20662065
if ((flags & FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local)
20672066
continue;
20682067
if ((flags & FOR_EACH_OBJECT_PROMISOR_ONLY) &&

0 commit comments

Comments
 (0)