putchar('\n');
if (revs.verbose_header) {
- char *buf = NULL;
- unsigned long buflen = 0;
- pretty_print_commit(revs.commit_format, commit, ~0,
- &buf, &buflen,
- revs.abbrev, NULL, NULL, revs.date_mode);
- if (*buf)
- printf("%s%c", buf, hdr_termination);
- free(buf);
+ struct strbuf buf;
+ strbuf_init(&buf, 0);
+ pretty_print_commit(revs.commit_format, commit,
+ &buf, revs.abbrev, NULL, NULL, revs.date_mode);
- printf("%s%c", buf.buf, hdr_termination);
++ if (buf.len)
++ printf("%s%c", buf.buf, hdr_termination);
+ strbuf_release(&buf);
}
maybe_flush_or_die(stdout, "stdout");
if (commit->parents) {
}
if (msg[i])
table[IBODY].value = xstrdup(msg + i);
- for (i = 0; i < ARRAY_SIZE(table); i++)
- if (!table[i].value)
- interp_set_entry(table, i, "<unknown>");
- do {
- char *buf = *buf_p;
- unsigned long space = *space_p;
-
- space = interpolate(buf, space, format,
- table, ARRAY_SIZE(table));
- if (!space)
- break;
- buf = xrealloc(buf, space);
- *buf_p = buf;
- *space_p = space;
- } while (1);
+ len = interpolate(sb->buf + sb->len, strbuf_avail(sb),
+ format, table, ARRAY_SIZE(table));
+ if (len > strbuf_avail(sb)) {
+ strbuf_grow(sb, len);
+ interpolate(sb->buf + sb->len, strbuf_avail(sb) + 1,
+ format, table, ARRAY_SIZE(table));
+ }
+ strbuf_setlen(sb, sb->len + len);
interp_clear_table(table, ARRAY_SIZE(table));
-
- return strlen(*buf_p);
}
static void pp_header(enum cmit_fmt fmt,
/* Check for valid interpolation. */
if (i < ninterps) {
value = interps[i].value;
- valuelen = strlen(value);
+ if (!value) {
+ src += namelen;
+ continue;
+ }
- if (newlen + valuelen + 1 < reslen) {
+ valuelen = strlen(value);
+ if (newlen + valuelen < reslen) {
/* Substitute. */
- strncpy(dest, value, valuelen);
+ memcpy(dest, value, valuelen);
dest += valuelen;
}
newlen += valuelen;
/*
* And then the pretty-printed message itself
*/
- len = pretty_print_commit(opt->commit_format, commit, ~0u,
- &msgbuf, &msgbuf_len, abbrev, subject,
- extra_headers, opt->date_mode);
+ strbuf_init(&msgbuf, 0);
+ pretty_print_commit(opt->commit_format, commit, &msgbuf,
+ abbrev, subject, extra_headers, opt->date_mode);
if (opt->add_signoff)
- len = append_signoff(&msgbuf, &msgbuf_len, len,
- opt->add_signoff);
+ append_signoff(&msgbuf, opt->add_signoff);
if (opt->show_log_size)
- printf("log size %i\n", len);
+ printf("log size %i\n", (int)msgbuf.len);
- printf("%s%s%s", msgbuf.buf, extra, sep);
- if (*msgbuf)
- printf("%s%s%s", msgbuf, extra, sep);
- free(msgbuf);
++ if (msgbuf.len)
++ printf("%s%s%s", msgbuf.buf, extra, sep);
+ strbuf_release(&msgbuf);
}
int log_tree_diff_flush(struct rev_info *opt)