[v5,12/15] bugreport: count loose objects
diff mbox series

Message ID 20200124033436.81097-13-emilyshaffer@google.com
State New
Headers show
Series
  • add git-bugreport tool
Related show

Commit Message

Emily Shaffer Jan. 24, 2020, 3:34 a.m. UTC
From: Emily Shaffer <emilyshaffer@google.com>

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>
---
The refactor removed much of the code Dscho suggested; and yet it
remains true that he helped me while developing this commit (although
his suggestions didn't survive). Shall I leave the Helped-by line or
remove it?

 - Emily


 bugreport.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

Comments

Junio C Hamano Feb. 4, 2020, 6:48 p.m. UTC | #1
emilyshaffer@google.com writes:

> From: Emily Shaffer <emilyshaffer@google.com>
>
> 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>
> ---
> The refactor removed much of the code Dscho suggested; and yet it
> remains true that he helped me while developing this commit (although
> his suggestions didn't survive). Shall I leave the Helped-by line or
> remove it?

You two collectively thought about viable alternatives and decided
to reject what was not wanted in the final result, and not having
that rejected code was good for the project, right?  If so, I would
say it still is the help that deserves recognition.  After all,
making the result better by removing things is harder than by adding
things ;-)

>  bugreport.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 46 insertions(+)
> ...

The patch text looked sensible.
Emily Shaffer Feb. 5, 2020, 2:50 a.m. UTC | #2
On Tue, Feb 04, 2020 at 10:48:30AM -0800, Junio C Hamano wrote:
> emilyshaffer@google.com writes:
> 
> > From: Emily Shaffer <emilyshaffer@google.com>
> >
> > 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>
> > ---
> > The refactor removed much of the code Dscho suggested; and yet it
> > remains true that he helped me while developing this commit (although
> > his suggestions didn't survive). Shall I leave the Helped-by line or
> > remove it?
> 
> You two collectively thought about viable alternatives and decided
> to reject what was not wanted in the final result, and not having
> that rejected code was good for the project, right?  If so, I would
> say it still is the help that deserves recognition.  After all,
> making the result better by removing things is harder than by adding
> things ;-)

Sounds great to me. I'd rather over-assign credit than under-assign (but
I don't think this is a case of over-assigning here).

> >  bugreport.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 46 insertions(+)
> > ...
> 
> The patch text looked sensible.

Thanks.

 - Emily

Patch
diff mbox series

diff --git a/bugreport.c b/bugreport.c
index 4c77009f1b..bf10857183 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_curl_version_info(struct strbuf *curl_info)
 {
@@ -171,6 +172,48 @@  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 local_loose_object_count = 0, total_loose_object_count = 0;
+	int local_count_questionable = 0, total_count_questionable = 0;
+
+	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 <file>]"),
 	NULL
@@ -246,6 +289,9 @@  int cmd_main(int argc, const char **argv)
 	get_header(&buffer, "Configured Hooks");
 	get_populated_hooks(&buffer, nongit_ok);
 
+	get_header(&buffer, "Loose Object Counts");
+	get_loose_object_summary(&buffer);
+
 	report = fopen_for_writing(report_path.buf);
 	strbuf_write(&buffer, report);
 	fclose(report);