Re: [PATCH v4 13/15] bugreport: add packed object summary
On Fri, Dec 13, 2019 at 01:56:07PM -0800, Junio C Hamano wrote:
Show 16 quoted lines
> Emily Shaffer <emilyshaffer@google.com> writes:
>
> > Alongside the list of loose objects, it's useful to see the list of
> > object packs as well. It can help us to examine what Git did and did not
> > pack.
>
> Not exactly the same comment, but is in the same spirit, as the
> previous step applies to this one.
>
> Would it be too much work to libify the bulk of cmd_count_objects()
> that computes numbers, making the cmd_count_objects() into a thin
> wrapper that calls the libified "counter/collector" function and
> prints the resulting numbers received from it?
>
> That way, the get_packed_object_summary() can be another consumer
> of the same "counter/collector" function, no?
That sounds like a good approach. Will do.
Show 55 quoted lines
>
> > Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
> > ---
> > bugreport.c | 31 +++++++++++++++++++++++++++++++
> > 1 file changed, 31 insertions(+)
> >
> > diff --git a/bugreport.c b/bugreport.c
> > index 3abb83d77f..992d8f9de7 100644
> > --- a/bugreport.c
> > +++ b/bugreport.c
> > @@ -234,6 +234,34 @@ static void get_loose_object_summary(struct strbuf *obj_info) {
> > strbuf_release(&dirpath);
> > }
> >
> > +static void get_packed_object_summary(struct strbuf *obj_info)
> > +{
> > + struct strbuf dirpath = STRBUF_INIT;
> > + struct dirent *d;
> > + DIR *dir = NULL;
> > +
> > + strbuf_addstr(&dirpath, get_object_directory());
> > + strbuf_complete(&dirpath, '/');
> > + strbuf_addstr(&dirpath, "pack/");
> > +
> > + dir = opendir(dirpath.buf);
> > + if (!dir) {
> > + strbuf_addf(obj_info, "could not open packed object directory '%s'\n",
> > + dirpath.buf);
> > + strbuf_release(&dirpath);
> > + return;
> > + }
> > +
> > + while ((d = readdir(dir))) {
> > + strbuf_addbuf(obj_info, &dirpath);
> > + strbuf_addstr(obj_info, d->d_name);
> > + strbuf_complete_line(obj_info);
> > + }
> > +
> > + closedir(dir);
> > + strbuf_release(&dirpath);
> > +}
> > +
> > static const char * const bugreport_usage[] = {
> > N_("git bugreport [-o|--output <file>]"),
> > NULL
> > @@ -307,6 +335,9 @@ int cmd_main(int argc, const char **argv)
> > get_header(&buffer, "Loose Object Counts");
> > get_loose_object_summary(&buffer);
> >
> > + get_header(&buffer, "Packed Object Summary");
> > + get_packed_object_summary(&buffer);
> > +
> > report = fopen_for_writing(report_path.buf);
> > strbuf_write(&buffer, report);
> > fclose(report);