From: Junio C Hamano Date: Wed, 3 Oct 2007 11:28:24 +0000 (-0700) Subject: Merge branch 'mv/unknown' X-Git-Tag: v1.5.4-rc0~386 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/cc61ae82ec581f6cf1a38a45aaef894f085ccb16 Merge branch 'mv/unknown' * mv/unknown: Don't use "" for placeholders and suppress printing of empty user formats. --- cc61ae82ec581f6cf1a38a45aaef894f085ccb16 diff --cc builtin-rev-list.c index 414b2f32b2,0b74eb35bc..33726b8d84 --- a/builtin-rev-list.c +++ b/builtin-rev-list.c @@@ -80,12 -80,14 +80,13 @@@ static void show_commit(struct commit * 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) { diff --cc commit.c index 62cc74d7a9,c9a18180be..20fb2209cb --- a/commit.c +++ b/commit.c @@@ -876,19 -917,22 +876,16 @@@ void format_commit_message(const struc } 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, ""); - 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, diff --cc interpolate.c index 3de583238d,2f727cd05b..6ef53f2465 --- a/interpolate.c +++ b/interpolate.c @@@ -73,11 -76,15 +73,15 @@@ unsigned long interpolate(char *result /* Check for valid interpolation. */ if (i < ninterps) { value = interps[i].value; - valuelen = strlen(value); + if (!value) { + src += namelen; + continue; + } + valuelen = strlen(value); - if (newlen + valuelen + 1 < reslen) { + if (newlen + valuelen < reslen) { /* Substitute. */ - strncpy(dest, value, valuelen); + memcpy(dest, value, valuelen); dest += valuelen; } newlen += valuelen; diff --cc log-tree.c index 3e5e6acfaf,79e3dee276..23191543d5 --- a/log-tree.c +++ b/log-tree.c @@@ -271,17 -288,19 +271,18 @@@ void show_log(struct rev_info *opt, con /* * 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)