Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2017-08-15 13:23:56 +0300
committerJunio C Hamano <gitster@pobox.com>2017-08-15 21:13:58 +0300
commita388b10fc17c435df32c3875225a1468edad9535 (patch)
tree7c27599344e6d39edcafe1cd631ed63ea7c12b48
parent99e09dafd7b7bcac4d8189b41dc6038bf36334f5 (diff)
pretty: move trailer formatting to trailer.c
The next commit will add many features to the %(trailer) placeholder in pretty.c. We'll need to access some internal functions of trailer.c for that, so our options are either: 1. expose those functions publicly or 2. make an entry point into trailer.c to do the formatting Doing (2) ends up exposing less surface area, though do note that caveats in the docstring of the new function. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--pretty.c13
-rw-r--r--trailer.c18
-rw-r--r--trailer.h14
3 files changed, 34 insertions, 11 deletions
diff --git a/pretty.c b/pretty.c
index 6cc812c2c7..33054e22cd 100644
--- a/pretty.c
+++ b/pretty.c
@@ -870,16 +870,6 @@ const char *format_subject(struct strbuf *sb, const char *msg,
return msg;
}
-static void format_trailers(struct strbuf *sb, const char *msg)
-{
- struct trailer_info info;
-
- trailer_info_get(&info, msg);
- strbuf_add(sb, info.trailer_start,
- info.trailer_end - info.trailer_start);
- trailer_info_release(&info);
-}
-
static void parse_commit_message(struct format_commit_context *c)
{
const char *msg = c->message + c->message_off;
@@ -1273,7 +1263,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
}
if (starts_with(placeholder, "(trailers)")) {
- format_trailers(sb, msg + c->subject_off);
+ struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT;
+ format_trailers_from_commit(sb, msg + c->subject_off, &opts);
return strlen("(trailers)");
}
diff --git a/trailer.c b/trailer.c
index e63f432947..07580af9c0 100644
--- a/trailer.c
+++ b/trailer.c
@@ -1090,3 +1090,21 @@ void trailer_info_release(struct trailer_info *info)
free(info->trailers[i]);
free(info->trailers);
}
+
+static void format_trailer_info(struct strbuf *out,
+ const struct trailer_info *info,
+ const struct process_trailer_options *opts)
+{
+ strbuf_add(out, info->trailer_start,
+ info->trailer_end - info->trailer_start);
+}
+
+void format_trailers_from_commit(struct strbuf *out, const char *msg,
+ const struct process_trailer_options *opts)
+{
+ struct trailer_info info;
+
+ trailer_info_get(&info, msg);
+ format_trailer_info(out, &info, opts);
+ trailer_info_release(&info);
+}
diff --git a/trailer.h b/trailer.h
index 194f85a102..a172811022 100644
--- a/trailer.h
+++ b/trailer.h
@@ -40,4 +40,18 @@ void trailer_info_get(struct trailer_info *info, const char *str);
void trailer_info_release(struct trailer_info *info);
+/*
+ * Format the trailers from the commit msg "msg" into the strbuf "out".
+ * Note two caveats about "opts":
+ *
+ * - this is primarily a helper for pretty.c, and not
+ * all of the flags are supported.
+ *
+ * - this differs from process_trailers slightly in that we always format
+ * only the trailer block itself, even if the "only_trailers" option is not
+ * set.
+ */
+void format_trailers_from_commit(struct strbuf *out, const char *msg,
+ const struct process_trailer_options *opts);
+
#endif /* TRAILER_H */