summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmily Shaffer <emilyshaffer@google.com>2020-02-20 01:58:56 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-02-20 18:33:57 (GMT)
commit7a226a68913d92fa7a95d754c2eaf4f9402707d4 (patch)
tree208ebc9f391a2cd40c461df323c22098fdcb8fcc
parent7a4dc0e09f5d082110dff7905f34cc01cdf80dc7 (diff)
downloadgit-7a226a68913d92fa7a95d754c2eaf4f9402707d4.zip
git-7a226a68913d92fa7a95d754c2eaf4f9402707d4.tar.gz
git-7a226a68913d92fa7a95d754c2eaf4f9402707d4.tar.bz2
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 <emilyshaffer@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--Documentation/git-bugreport.txt1
-rw-r--r--bugreport.c30
-rw-r--r--object-store.h6
-rw-r--r--packfile.c3
4 files changed, 38 insertions, 2 deletions
diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt
index 4fe1c60..eb41f06 100644
--- a/Documentation/git-bugreport.txt
+++ b/Documentation/git-bugreport.txt
@@ -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
This tool is invoked via the typical Git setup process, which means that in some
cases, it might not be able to launch - for example, if a relevant config file
diff --git a/bugreport.c b/bugreport.c
index fb7bc72..71191f1 100644
--- a/bugreport.c
+++ b/bugreport.c
@@ -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
@@ -271,6 +298,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) {
diff --git a/object-store.h b/object-store.h
index 55ee639..518c734 100644
--- a/object-store.h
+++ b/object-store.h
@@ -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 */
diff --git a/packfile.c b/packfile.c
index 7e7c04e..6873827 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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) &&