]> git.ipfire.org Git - thirdparty/git.git/blobdiff - pretty.c
Merge branch 'aw/pretty-trailers'
[thirdparty/git.git] / pretty.c
index 6d58b21affd3b7d888aa9eae124df8d1bbea0a6c..d2995b13edf4c64965321882677f28847f47e21c 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(the_repository, 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);
        }
 
        /*
@@ -1138,6 +1139,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
        struct commit_list *p;
        const char *arg;
        size_t res;
+       char **slot;
 
        /* these are independent of the commit */
        res = strbuf_expand_literal_cb(sb, placeholder, NULL);
@@ -1242,6 +1244,14 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
                load_ref_decorations(NULL, DECORATE_SHORT_REFS);
                format_decorations_extended(sb, commit, c->auto_color, "", ", ", "");
                return 1;
+       case 'S':               /* tag/branch like --source */
+               if (!(c->pretty_ctx->rev && c->pretty_ctx->rev->sources))
+                       return 0;
+               slot = revision_sources_at(c->pretty_ctx->rev->sources, commit);
+               if (!(slot && *slot))
+                       return 0;
+               strbuf_addstr(sb, *slot);
+               return 1;
        case 'g':               /* reflog info */
                switch(placeholder[1]) {
                case 'd':       /* reflog selector */
@@ -1575,6 +1585,9 @@ static size_t userformat_want_item(struct strbuf *sb, const char *placeholder,
        case 'N':
                w->notes = 1;
                break;
+       case 'S':
+               w->source = 1;
+               break;
        }
        return 0;
 }
@@ -1592,9 +1605,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;
@@ -1608,9 +1622,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);
@@ -1634,7 +1648,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,