From: Ævar Arnfjörð Bjarmason Date: Mon, 06 Feb 2023 20:45:49 GMT Subject: Re: [PATCH v8 3/3] credential: add WWW-Authenticate header to cred requests Message-ID: <230206.867cwu5xmu.gmgdl@evledraar.gmail.com> In-Reply-To: <149aedf55010718e22669575a148988eed0d8dcb.1675711789.git.gitgitgadget@gmail.com> On Mon, Feb 06 2023, Matthew John Cheetham via GitGitGadget wrote: > From: Matthew John Cheetham > @@ -263,6 +263,16 @@ static void credential_write_item(FILE *fp, const char *key, const char *value, > fprintf(fp, "%s=%s\n", key, value); > } > > +static void credential_write_strvec(FILE *fp, const char *key, > + const struct strvec *vec) > +{ > + char *full_key = xstrfmt("%s[]", key); FWIW you could avoid this allocation if you just renamed the current "credential_write_item()" to "credential_write_fmt()", and had it take a format instead of its current hardcoded "%s=%s\n". Then you could have two wrappers, credential_write_item() and credential_write_items() (instead of "strvec"), the first passing "%s=%s\n", the other "%s[]=%s\n". Just a thought. > + for (size_t i = 0; i < vec->nr; i++) { > + credential_write_item(fp, full_key, vec->v[i], 0); The {} here can be dropped in any case.