Skip to content

Commit

Permalink
bugreport: count loose objects
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
nasamuffin authored and gitster committed Feb 14, 2020
1 parent 0ae9bf1 commit 82e7f0b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions Documentation/git-bugreport.txt
Expand Up @@ -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

OPTIONS
-------
Expand Down
52 changes: 52 additions & 0 deletions bugreport.c
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 82e7f0b

Please sign in to comment.