Merge branch 'mv/unknown'
authorJunio C Hamano <gitster@pobox.com>
Wed, 3 Oct 2007 11:28:24 +0000 (04:28 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 3 Oct 2007 11:28:24 +0000 (04:28 -0700)
* mv/unknown:
  Don't use "<unknown>" for placeholders and suppress printing of empty user formats.

1  2 
builtin-rev-list.c
commit.c
interpolate.c
log-tree.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
+++ 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, "<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,
diff --cc 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;
+                               }
  
 -                              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;
diff --cc 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)