fast-import: Improve robustness when D->F changes provided in wrong order
[gitweb.git] / pretty.c
index 9001379a9dd93818e962ae73cdf85dc178804256..7cb3a2af508bb5667cd74304f72b50766c749990 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -775,9 +775,13 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
                }
                return 0;       /* unknown %g placeholder */
        case 'N':
-               get_commit_notes(commit, sb, git_log_output_encoding ?
-                            git_log_output_encoding : git_commit_encoding, 0);
-               return 1;
+               if (c->pretty_ctx->show_notes) {
+                       format_display_notes(commit->object.sha1, sb,
+                                   git_log_output_encoding ? git_log_output_encoding
+                                                           : git_commit_encoding, 0);
+                       return 1;
+               }
+               return 0;
        }
 
        /* For the rest we have to parse the commit header. */
@@ -854,6 +858,35 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
        return consumed + 1;
 }
 
+static size_t userformat_want_item(struct strbuf *sb, const char *placeholder,
+                                  void *context)
+{
+       struct userformat_want *w = context;
+
+       if (*placeholder == '+' || *placeholder == '-')
+               placeholder++;
+
+       switch (*placeholder) {
+       case 'N':
+               w->notes = 1;
+               break;
+       }
+       return 0;
+}
+
+void userformat_find_requirements(const char *fmt, struct userformat_want *w)
+{
+       struct strbuf dummy = STRBUF_INIT;
+
+       if (!fmt) {
+               if (!user_format)
+                       return;
+               fmt = user_format;
+       }
+       strbuf_expand(&dummy, user_format, userformat_want_item, w);
+       strbuf_release(&dummy);
+}
+
 void format_commit_message(const struct commit *commit,
                           const char *format, struct strbuf *sb,
                           const struct pretty_print_context *pretty_ctx)
@@ -1094,9 +1127,9 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
        if (fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body)
                strbuf_addch(sb, '\n');
 
-       if (fmt != CMIT_FMT_ONELINE)
-               get_commit_notes(commit, sb, encoding,
-                                NOTES_SHOW_HEADER | NOTES_INDENT);
+       if (context->show_notes)
+               format_display_notes(commit->object.sha1, sb, encoding,
+                                    NOTES_SHOW_HEADER | NOTES_INDENT);
 
        free(reencoded);
 }