Re: [PATCH v8 14/15] bugreport: list contents of $OBJDIR/info
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Feb 20, 2020, 22:18 UTC
- Message-ID
- <xmqqwo8g9a2a.fsf@gitster-ct.c.googlers.com>
- In-Reply-To
- <20200220015858.181086-15-emilyshaffer@google.com>
Emily Shaffer <emilyshaffer@google.com> writes:
Show 10 quoted lines
> +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?
Show 16 quoted lines
> + 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.
Show 13 quoted lines
> +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?
Show 17 quoted lines
> + 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) {