filter-options: expand scaled numbers
[gitweb.git] / pretty.c
index 703fa6ff7bf297e9d0dd91586f951f715032e06a..e89b89248e823f8c86bfd29ad82eb8c05b3cb840 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -595,14 +595,15 @@ static char *replace_encoding_header(char *buf, const char *encoding)
        return strbuf_detach(&tmp, NULL);
 }
 
-const char *logmsg_reencode(const struct commit *commit,
-                           char **commit_encoding,
-                           const char *output_encoding)
+const char *repo_logmsg_reencode(struct repository *r,
+                                const struct commit *commit,
+                                char **commit_encoding,
+                                const char *output_encoding)
 {
        static const char *utf8 = "UTF-8";
        const char *use_encoding;
        char *encoding;
-       const char *msg = get_commit_buffer(commit, NULL);
+       const char *msg = repo_get_commit_buffer(r, commit, NULL);
        char *out;
 
        if (!output_encoding || !*output_encoding) {
@@ -630,7 +631,7 @@ const char *logmsg_reencode(const struct commit *commit,
                 * the cached copy from get_commit_buffer, we need to duplicate it
                 * to avoid munging the cached copy.
                 */
-               if (msg == get_cached_commit_buffer(commit, NULL))
+               if (msg == get_cached_commit_buffer(r, commit, NULL))
                        out = xstrdup(msg);
                else
                        out = (char *)msg;
@@ -644,7 +645,7 @@ const char *logmsg_reencode(const struct commit *commit,
                 */
                out = reencode_string(msg, output_encoding, use_encoding);
                if (out)
-                       unuse_commit_buffer(commit, msg);
+                       repo_unuse_commit_buffer(r, commit, msg);
        }
 
        /*
@@ -1146,7 +1147,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
 
        /* these depend on the commit */
        if (!commit->object.parsed)
-               parse_object(&commit->object.oid);
+               parse_object(the_repository, &commit->object.oid);
 
        switch (placeholder[0]) {
        case 'H':               /* commit hash */
@@ -1256,6 +1257,14 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
                        if (c->signature_check.key)
                                strbuf_addstr(sb, c->signature_check.key);
                        break;
+               case 'F':
+                       if (c->signature_check.fingerprint)
+                               strbuf_addstr(sb, c->signature_check.fingerprint);
+                       break;
+               case 'P':
+                       if (c->signature_check.primary_key_fingerprint)
+                               strbuf_addstr(sb, c->signature_check.primary_key_fingerprint);
+                       break;
                default:
                        return 0;
                }
@@ -1304,6 +1313,9 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
 
        if (skip_prefix(placeholder, "(trailers", &arg)) {
                struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT;
+
+               opts.no_divider = 1;
+
                if (*arg == ':') {
                        arg++;
                        for (;;) {
@@ -1504,9 +1516,10 @@ void userformat_find_requirements(const char *fmt, struct userformat_want *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)
+void repo_format_commit_message(struct repository *r,
+                               const struct commit *commit,
+                               const char *format, struct strbuf *sb,
+                               const struct pretty_print_context *pretty_ctx)
 {
        struct format_commit_context context;
        const char *output_enc = pretty_ctx->output_encoding;
@@ -1520,9 +1533,9 @@ void format_commit_message(const struct commit *commit,
         * convert a commit message to UTF-8 first
         * as far as 'format_commit_item' assumes it in UTF-8
         */
-       context.message = logmsg_reencode(commit,
-                                         &context.commit_encoding,
-                                         utf8);
+       context.message = repo_logmsg_reencode(r, commit,
+                                              &context.commit_encoding,
+                                              utf8);
 
        strbuf_expand(sb, format, format_commit_item, &context);
        rewrap_message_tail(sb, &context, 0, 0, 0);
@@ -1538,7 +1551,7 @@ void format_commit_message(const struct commit *commit,
        }
 
        if (output_enc) {
-               int outsz;
+               size_t outsz;
                char *out = reencode_string_len(sb->buf, sb->len,
                                                output_enc, utf8, &outsz);
                if (out)
@@ -1546,7 +1559,7 @@ void format_commit_message(const struct commit *commit,
        }
 
        free(context.commit_encoding);
-       unuse_commit_buffer(commit, context.message);
+       repo_unuse_commit_buffer(r, commit, context.message);
 }
 
 static void pp_header(struct pretty_print_context *pp,
@@ -1575,7 +1588,7 @@ static void pp_header(struct pretty_print_context *pp,
                }
 
                if (starts_with(line, "parent ")) {
-                       if (linelen != 48)
+                       if (linelen != the_hash_algo->hexsz + 8)
                                die("bad parent line in commit");
                        continue;
                }
@@ -1583,7 +1596,7 @@ static void pp_header(struct pretty_print_context *pp,
                if (!parents_shown) {
                        unsigned num = commit_list_count(commit->parents);
                        /* with enough slop */
-                       strbuf_grow(sb, num * 50 + 20);
+                       strbuf_grow(sb, num * (GIT_MAX_HEXSZ + 10) + 20);
                        add_merge_info(pp, sb, commit);
                        parents_shown = 1;
                }