[PATCH 14/19] ui-summary.c: use struct strbuf instead of fixed-size buffers

Jason A. Donenfeld Jason at zx2c4.com
Sun Apr 7 14:20:26 CEST 2013


On Sun, Apr 7, 2013 at 11:30 AM, John Keeping <john at keeping.me.uk> wrote:
>         /* Prepend repo path to relative readme path unless tracked. */
> -       if (!ref && *ctx.repo->readme != '/')
> -               ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path,
> -                                              ctx.repo->readme));
> +       if (!ref && *ctx.repo->readme != '/') {
> +               struct strbuf buf = STRBUF_INIT;
> +               strbuf_addf(&buf, "%s/%s", ctx.repo->path, ctx.repo->readme);
> +               ctx.repo->readme = strbuf_detach(&buf, NULL);
> +       }

I do in fact see the merits of using strbuf and the purpose of this
patch set, but OTOH, this little chunk here illustrates the downsides
-- the extra verbosity this adds is really a bummer. Perhaps this
could be moved into a new fmtalloc helper function, if this pattern is
common?




More information about the CGit mailing list