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

index 414b2f32b293c9d6d7ca2a821f903de64ea8ea21,0b74eb35bcfae2dfe2145b33b1d56c0b90d7385f..33726b8d8426b4878ed63184dc280957ba4434e0
@@@ -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 62cc74d7a9a2e7cddd5048602e4c793269287add,c9a18180be5872acb9fc4e021b61492b71a0d9c9..20fb2209cbcbc19343e7e52378e74afef52e3a6e
+++ 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
index 3de583238d854675ae872047a2d2b7fb09a66969,2f727cd05b0d071d9aa750b90fe3c16c12ccbe5e..6ef53f246511a1943e375d5d5913a4ec52e2c663
@@@ -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
index 3e5e6acfafb5345b8ed4f67599270e841b194ade,79e3dee276e5b99b11c4f6986aaff74ad6ad7f5e..23191543d5324f20622048103a821ded4d13b77a
@@@ -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)