Merge branch 'rs/pretty-use-prefixcmp'
authorJunio C Hamano <gitster@pobox.com>
Fri, 18 Jan 2013 19:20:08 +0000 (11:20 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 18 Jan 2013 19:20:08 +0000 (11:20 -0800)
* rs/pretty-use-prefixcmp:
pretty: use prefixcmp instead of memcmp on NUL-terminated strings

1  2 
pretty.c
diff --combined pretty.c
index 92c839fe641da15d05c2afe2b498a9fe390624c8,94c6a34fa8b1e93a535b3c37fc4aa7e269993645..01795de68704f9690aea2b9c36e557b31a151ca6
+++ b/pretty.c
@@@ -567,7 -567,7 +567,7 @@@ char *logmsg_reencode(const struct comm
        char *encoding;
        char *out;
  
 -      if (!*output_encoding)
 +      if (!output_encoding || !*output_encoding)
                return NULL;
        encoding = get_header(commit, "encoding");
        use_encoding = encoding ? encoding : utf8;
@@@ -966,7 -966,7 +966,7 @@@ static size_t format_commit_one(struct 
  
                        if (!end)
                                return 0;
-                       if (!memcmp(begin, "auto,", 5)) {
+                       if (!prefixcmp(begin, "auto,")) {
                                if (!want_color(c->pretty_ctx->color))
                                        return end - placeholder + 1;
                                begin += 5;
                }
                return 0;       /* unknown %g placeholder */
        case 'N':
 -              if (c->pretty_ctx->show_notes) {
 -                      format_display_notes(commit->object.sha1, sb,
 -                                  get_log_output_encoding(), 0);
 +              if (c->pretty_ctx->notes_message) {
 +                      strbuf_addstr(sb, c->pretty_ctx->notes_message);
                        return 1;
                }
                return 0;
@@@ -1257,15 -1258,23 +1257,15 @@@ void format_commit_message(const struc
                           const struct pretty_print_context *pretty_ctx)
  {
        struct format_commit_context context;
 -      static const char utf8[] = "UTF-8";
        const char *output_enc = pretty_ctx->output_encoding;
  
        memset(&context, 0, sizeof(context));
        context.commit = commit;
        context.pretty_ctx = pretty_ctx;
        context.wrap_start = sb->len;
 -      context.message = commit->buffer;
 -      if (output_enc) {
 -              char *enc = get_header(commit, "encoding");
 -              if (strcmp(enc ? enc : utf8, output_enc)) {
 -                      context.message = logmsg_reencode(commit, output_enc);
 -                      if (!context.message)
 -                              context.message = commit->buffer;
 -              }
 -              free(enc);
 -      }
 +      context.message = logmsg_reencode(commit, output_enc);
 +      if (!context.message)
 +              context.message = commit->buffer;
  
        strbuf_expand(sb, format, format_commit_item, &context);
        rewrap_message_tail(sb, &context, 0, 0, 0);
@@@ -1301,7 -1310,7 +1301,7 @@@ static void pp_header(const struct pret
                        continue;
                }
  
-               if (!memcmp(line, "parent ", 7)) {
+               if (!prefixcmp(line, "parent ")) {
                        if (linelen != 48)
                                die("bad parent line in commit");
                        continue;
                 * FULL shows both authors but not dates.
                 * FULLER shows both authors and dates.
                 */
-               if (!memcmp(line, "author ", 7)) {
+               if (!prefixcmp(line, "author ")) {
                        strbuf_grow(sb, linelen + 80);
                        pp_user_info(pp, "Author", sb, line + 7, encoding);
                }
-               if (!memcmp(line, "committer ", 10) &&
+               if (!prefixcmp(line, "committer ") &&
                    (pp->fmt == CMIT_FMT_FULL || pp->fmt == CMIT_FMT_FULLER)) {
                        strbuf_grow(sb, linelen + 80);
                        pp_user_info(pp, "Commit", sb, line + 10, encoding);
@@@ -1412,6 -1421,16 +1412,6 @@@ void pp_remainder(const struct pretty_p
        }
  }
  
 -char *reencode_commit_message(const struct commit *commit, const char **encoding_p)
 -{
 -      const char *encoding;
 -
 -      encoding = get_log_output_encoding();
 -      if (encoding_p)
 -              *encoding_p = encoding;
 -      return logmsg_reencode(commit, encoding);
 -}
 -
  void pretty_print_commit(const struct pretty_print_context *pp,
                         const struct commit *commit,
                         struct strbuf *sb)
                return;
        }
  
 -      reencoded = reencode_commit_message(commit, &encoding);
 +      encoding = get_log_output_encoding();
 +      reencoded = logmsg_reencode(commit, encoding);
        if (reencoded) {
                msg = reencoded;
        }
        if (pp->fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body)
                strbuf_addch(sb, '\n');
  
 -      if (pp->show_notes)
 -              format_display_notes(commit->object.sha1, sb, encoding,
 -                                   NOTES_SHOW_HEADER | NOTES_INDENT);
 -
        free(reencoded);
  }