On Tue, Oct 1, 2024 at 3:23 PM Junio C Hamano <gitster@xxxxxxxxx> wrote: > One thing that this worsens is that we now have two copies of the > literal "branch%02"PRIuMAX string. If we ever want to change one of > them, we must remember to change the other to match. > > Perhaps with another constant, this patch would become perfect, like > this? > > + static const char fmt[] = "branch%02"PRIuMAX; > > > - snprintf(buf, sizeof(buf), "branch%02"PRIuMAX, (uintmax_t)i); > > - refs[i].refname = xstrdup(buf); > > + refs[i].refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i); > > + refs[i].refname = xstrfmt(fmt, (uintmax_t)i); > > > refs[i].update_index = i + 1; > > refs[i].value_type = REFTABLE_REF_VAL1; > > t_reftable_set_hash(refs[i].value.val1, i, GIT_SHA1_FORMAT_ID); > > > > - logs[i].refname = xstrdup(buf); > > + logs[i].refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i); > > + logs[i].refname = xstrfmt(fmt, (uintmax_t)i); Even simpler would be merely to xstrdup() the string which was already formatted by xstrfmt(), I would think. refs[i].refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i); ... logs[i].refname = xstrdup(refs[i].refname);