Re: [PATCH v8 15/15] bugreport: summarize contents of alternates file
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Feb 20, 2020, 22:22 UTC
- Message-ID
- <xmqqsgj499w3.fsf@gitster-ct.c.googlers.com>
- In-Reply-To
- <20200220015858.181086-16-emilyshaffer@google.com>
Emily Shaffer <emilyshaffer@google.com> writes:
Show 16 quoted lines
> +static void get_alternates_summary(struct strbuf *alternates_info, int nongit)
> +{
> + struct strbuf alternates_path = STRBUF_INIT;
> + struct strbuf alternate = STRBUF_INIT;
> + FILE *file;
> + size_t exists = 0, broken = 0;
> +
> + if (nongit) {
> + strbuf_addstr(alternates_info,
> + "not run from a git repository - alternates unavailable\n");
> + return;
> + }
> +
> + strbuf_addstr(&alternates_path, get_object_directory());
> + strbuf_complete(&alternates_path, '/');
> + strbuf_addstr(&alternates_path, "info/alternates");git_path()?
Show 10 quoted lines
> + file = fopen(alternates_path.buf, "r");
> + if (!file) {
> + strbuf_addstr(alternates_info, "No alternates file found.\n");
> + strbuf_release(&alternates_path);
> + return;
> + }
> +
> + while (strbuf_getline(&alternate, file) != EOF) {
> + if (!access(alternate.buf, F_OK))
> + exists++;F_OK reported as "exists" makes quite a lot of sense.
> + else > + broken++;
So, shouldn't this rather be "missing"?
Show 7 quoted lines
> + } > + > + strbuf_addf(alternates_info, > + "%zd alternates found (%zd working, %zd broken)\n", > + exists + broken, > + exists, > + broken);
I don't see the point of using size_t for this. Just use int for both, like you did for object count in the step that counds loose and packed objects.
Show 18 quoted lines
> + fclose(file);
> + strbuf_release(&alternate);
> + strbuf_release(&alternates_path);
> +}
> +
> static const char * const bugreport_usage[] = {
> N_("git bugreport [-o|--output-directory <file>] [-s|--suffix <format>]"),
> NULL
> @@ -355,6 +397,9 @@ int cmd_main(int argc, const char **argv)
> get_header(&buffer, "Object Info Summary");
> get_object_info_summary(&buffer, nongit_ok);
>
> + get_header(&buffer, "Alternates");
> + get_alternates_summary(&buffer, nongit_ok);
> +
> report = fopen_for_writing(report_path.buf);
>
> if (report == NULL) {