summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmily Shaffer <emilyshaffer@google.com>2020-02-20 01:58:55 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-02-20 18:33:57 (GMT)
commit7a4dc0e09f5d082110dff7905f34cc01cdf80dc7 (patch)
treeb5513da5d227f0c7dce4f4c01a6aab4c4df429ce
parent13b1ca981f8a7711296bf128a835e51af76c4af8 (diff)
downloadgit-7a4dc0e09f5d082110dff7905f34cc01cdf80dc7.zip
git-7a4dc0e09f5d082110dff7905f34cc01cdf80dc7.tar.gz
git-7a4dc0e09f5d082110dff7905f34cc01cdf80dc7.tar.bz2
bugreport: count loose objects
The number of unpacked objects in a user's repository may help us understand the root of the problem they're seeing, especially if a command is running unusually slowly. Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> 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.c52
2 files changed, 53 insertions, 0 deletions
diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt
index 4d01528..4fe1c60 100644
--- a/Documentation/git-bugreport.txt
+++ b/Documentation/git-bugreport.txt
@@ -32,6 +32,7 @@ The following information is captured automatically:
- $SHELL
- Selected config values
- A list of enabled hooks
+ - The number of loose 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 b5a0714..fb7bc72 100644
--- a/bugreport.c
+++ b/bugreport.c
@@ -10,6 +10,7 @@
#include "bugreport-config-safelist.h"
#include "khash.h"
#include "run-command.h"
+#include "object-store.h"
static void get_git_remote_https_version_info(struct strbuf *version_info)
{
@@ -128,6 +129,54 @@ static void get_populated_hooks(struct strbuf *hook_info, int nongit)
}
}
+static int loose_object_cb(const struct object_id *oid, const char *path,
+ void *data) {
+ int *loose_object_count = data;
+
+ if (loose_object_count) {
+ (*loose_object_count)++;
+ return 0;
+ }
+
+ return 1;
+}
+
+static void get_loose_object_summary(struct strbuf *obj_info, int nongit) {
+
+ int local_loose_object_count = 0, total_loose_object_count = 0;
+ int local_count_questionable = 0, total_count_questionable = 0;
+
+ if (nongit) {
+ strbuf_addstr(obj_info,
+ "not run from a git repository - no objects to show\n");
+ return;
+ }
+
+ local_count_questionable = for_each_loose_object(
+ loose_object_cb,
+ &local_loose_object_count,
+ FOR_EACH_OBJECT_LOCAL_ONLY);
+
+ total_count_questionable = for_each_loose_object(
+ loose_object_cb,
+ &total_loose_object_count,
+ 0);
+
+ strbuf_addf(obj_info, "%d local loose objects%s\n",
+ local_loose_object_count,
+ local_count_questionable ? " (problem during count)" : "");
+
+ strbuf_addf(obj_info, "%d alternate loose objects%s\n",
+ total_loose_object_count - local_loose_object_count,
+ (local_count_questionable || total_count_questionable)
+ ? " (problem during count)"
+ : "");
+
+ strbuf_addf(obj_info, "%d total loose objects%s\n",
+ total_loose_object_count,
+ total_count_questionable ? " (problem during count)" : "");
+}
+
static const char * const bugreport_usage[] = {
N_("git bugreport [-o|--output-directory <file>] [-s|--suffix <format>]"),
NULL
@@ -219,6 +268,9 @@ int cmd_main(int argc, const char **argv)
get_header(&buffer, "Enabled Hooks");
get_populated_hooks(&buffer, nongit_ok);
+ get_header(&buffer, "Loose Object Counts");
+ get_loose_object_summary(&buffer, nongit_ok);
+
report = fopen_for_writing(report_path.buf);
if (report == NULL) {