diff mbox series

[v8,14/15] bugreport: list contents of $OBJDIR/info

Message ID 20200220015858.181086-15-emilyshaffer@google.com (mailing list archive)
State New, archived
Headers show
Series add git-bugreport tool | expand

Commit Message

Emily Shaffer Feb. 20, 2020, 1:58 a.m. UTC
Miscellaneous information used about the object store can end up in
.git/objects/info; this can help us understand what may be going on with
the object store when the user is reporting a bug. Otherwise, it could
be difficult to track down what is going wrong with an object which
isn't kept locally to .git/objects/ or .git/objects/pack. Having some
understanding of where the user's objects may be kept can save us some
hops during the bug reporting process.

Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
---
 Documentation/git-bugreport.txt |  1 +
 bugreport.c                     | 54 +++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+)

Comments

Junio C Hamano Feb. 20, 2020, 10:18 p.m. UTC | #1
Emily Shaffer <emilyshaffer@google.com> writes:

> +static void list_contents_of_dir_recursively(struct strbuf *contents,
> +					     struct strbuf *dirpath)
> +{
> +	struct dirent *d;
> +	DIR *dir;
> +	size_t path_len;
> +
> +	dir = opendir(dirpath->buf);
> +	if (!dir)
> +		return;

No error detected?

> +	strbuf_complete(dirpath, '/');
> +	path_len = dirpath->len;
> +
> +	while ((d = readdir(dir))) {
> +		if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
> +			continue;
> +
> +		strbuf_addbuf(contents, dirpath);
> +		strbuf_addstr(contents, d->d_name);
> +		strbuf_complete_line(contents);
> +
> +		if (d->d_type == DT_DIR) {
> +			strbuf_addstr(dirpath, d->d_name);
> +			list_contents_of_dir_recursively(contents, dirpath);
> +		}
> +		strbuf_setlen(dirpath, path_len);

Shouldn't we be sorting the output?

> +	}
> +
> +	closedir(dir);
> +}

Hmph, it is somewhat sad that we have to reinvent a degraded copy of
"ls -aR" like this.

> +static void get_object_info_summary(struct strbuf *obj_info, int nongit)
> +{
> +	struct strbuf dirpath = STRBUF_INIT;
> +
> +	if (nongit) {
> +		strbuf_addstr(obj_info,
> +			"not run from a git repository - object info unavailable\n");
> +		return;
> +	}
> +
> +	strbuf_addstr(&dirpath, get_object_directory());
> +	strbuf_complete(&dirpath, '/');
> +	strbuf_addstr(&dirpath, "info/");

Would it help to use git_path() for this, perhaps like
git_path("objects/info/")?

By the way, do we store anything worth knowing in $GIT_DIR/info too?
Perhaps the per-repo attributes and excludes files whose presence
may hint at another question to ask when a user reports unexpected
behaviour from .gitignore?

> +	list_contents_of_dir_recursively(obj_info, &dirpath);
> +	strbuf_release(&dirpath);
> +}
> +
>  static const char * const bugreport_usage[] = {
>  	N_("git bugreport [-o|--output-directory <file>] [-s|--suffix <format>]"),
>  	NULL
> @@ -301,6 +352,9 @@ int cmd_main(int argc, const char **argv)
>  	get_header(&buffer, "Packed Object Summary");
>  	get_packed_object_summary(&buffer, nongit_ok);
>  
> +	get_header(&buffer, "Object Info Summary");
> +	get_object_info_summary(&buffer, nongit_ok);
> +
>  	report = fopen_for_writing(report_path.buf);
>  
>  	if (report == NULL) {
diff mbox series

Patch

diff --git a/Documentation/git-bugreport.txt b/Documentation/git-bugreport.txt
index eb41f0677f..a7ef3360d2 100644
--- a/Documentation/git-bugreport.txt
+++ b/Documentation/git-bugreport.txt
@@ -34,6 +34,7 @@  The following information is captured automatically:
  - A list of enabled hooks
  - The number of loose objects in the repository
  - The number of packs and packed objects in the repository
+ - A list of the contents of .git/objects/info (or equivalent)
 
 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 71191f1331..1d61e0f642 100644
--- a/bugreport.c
+++ b/bugreport.c
@@ -204,6 +204,57 @@  static void get_packed_object_summary(struct strbuf *obj_info, int nongit)
 
 }
 
+static void list_contents_of_dir_recursively(struct strbuf *contents,
+					     struct strbuf *dirpath)
+{
+	struct dirent *d;
+	DIR *dir;
+	size_t path_len;
+
+	dir = opendir(dirpath->buf);
+	if (!dir)
+		return;
+
+	strbuf_complete(dirpath, '/');
+	path_len = dirpath->len;
+
+	while ((d = readdir(dir))) {
+		if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
+			continue;
+
+		strbuf_addbuf(contents, dirpath);
+		strbuf_addstr(contents, d->d_name);
+		strbuf_complete_line(contents);
+
+		if (d->d_type == DT_DIR) {
+			strbuf_addstr(dirpath, d->d_name);
+			list_contents_of_dir_recursively(contents, dirpath);
+		}
+		strbuf_setlen(dirpath, path_len);
+	}
+
+	closedir(dir);
+}
+
+static void get_object_info_summary(struct strbuf *obj_info, int nongit)
+{
+	struct strbuf dirpath = STRBUF_INIT;
+
+	if (nongit) {
+		strbuf_addstr(obj_info,
+			"not run from a git repository - object info unavailable\n");
+		return;
+	}
+
+	strbuf_addstr(&dirpath, get_object_directory());
+	strbuf_complete(&dirpath, '/');
+	strbuf_addstr(&dirpath, "info/");
+
+	list_contents_of_dir_recursively(obj_info, &dirpath);
+
+	strbuf_release(&dirpath);
+}
+
 static const char * const bugreport_usage[] = {
 	N_("git bugreport [-o|--output-directory <file>] [-s|--suffix <format>]"),
 	NULL
@@ -301,6 +352,9 @@  int cmd_main(int argc, const char **argv)
 	get_header(&buffer, "Packed Object Summary");
 	get_packed_object_summary(&buffer, nongit_ok);
 
+	get_header(&buffer, "Object Info Summary");
+	get_object_info_summary(&buffer, nongit_ok);
+
 	report = fopen_for_writing(report_path.buf);
 
 	if (report == NULL) {