From 8abc89800c09cda7910c2211ebbbbb95a3008b63 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 10 Aug 2017 14:03:58 -0400 Subject: trailer: put process_trailers() options into a struct We already have two options and are about to add a few more. To avoid having a huge number of boolean arguments, let's convert to an options struct which can be passed in. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- trailer.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'trailer.h') diff --git a/trailer.h b/trailer.h index 65cc5d79c6c..9da00bedecd 100644 --- a/trailer.h +++ b/trailer.h @@ -22,7 +22,15 @@ struct trailer_info { size_t trailer_nr; }; -void process_trailers(const char *file, int in_place, int trim_empty, +struct process_trailer_options { + int in_place; + int trim_empty; +}; + +#define PROCESS_TRAILER_OPTIONS_INIT {0} + +void process_trailers(const char *file, + const struct process_trailer_options *opts, struct string_list *trailers); void trailer_info_get(struct trailer_info *info, const char *str); -- cgit v1.2.3 From 56c493ed1b9c067813fb95ff7cd4f69c7c1d2e36 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 15 Aug 2017 06:23:21 -0400 Subject: interpret-trailers: add an option to show only the trailers In theory it's easy for any reader who wants to parse trailers to do so. But there are a lot of subtle corner cases around what counts as a trailer, when the trailer block begins and ends, etc. Since interpret-trailers already has our parsing logic, let's let callers ask it to just output the trailers. They still have to parse the "key: value" lines, but at least they can ignore all of the other corner cases. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- trailer.h | 1 + 1 file changed, 1 insertion(+) (limited to 'trailer.h') diff --git a/trailer.h b/trailer.h index 9da00bedecd..3cf35ced00f 100644 --- a/trailer.h +++ b/trailer.h @@ -25,6 +25,7 @@ struct trailer_info { struct process_trailer_options { int in_place; int trim_empty; + int only_trailers; }; #define PROCESS_TRAILER_OPTIONS_INIT {0} -- cgit v1.2.3 From fdbdb64f49959f9c83329554080934895f02ae59 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 15 Aug 2017 06:23:25 -0400 Subject: interpret-trailers: add an option to show only existing trailers It can be useful to invoke interpret-trailers for the primary purpose of parsing existing trailers. But in that case, we don't want to apply existing ifMissing or ifExists rules from the config. Let's add a special mode where we avoid applying those rules. Coupled with --only-trailers, this gives us a reasonable parsing tool. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- trailer.h | 1 + 1 file changed, 1 insertion(+) (limited to 'trailer.h') diff --git a/trailer.h b/trailer.h index 3cf35ced00f..76c3b571bf6 100644 --- a/trailer.h +++ b/trailer.h @@ -26,6 +26,7 @@ struct process_trailer_options { int in_place; int trim_empty; int only_trailers; + int only_input; }; #define PROCESS_TRAILER_OPTIONS_INIT {0} -- cgit v1.2.3 From 000023961a0c02d6e21dc51ea3484ff71abf1c74 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 15 Aug 2017 06:23:29 -0400 Subject: interpret-trailers: add an option to unfold values The point of "--only-trailers" is to give a caller an output that's easy for them to parse. Getting rid of the non-trailer material helps, but we still may see more complicated syntax like whitespace continuation. Let's add an option to unfold any continuation, giving the output as a single "key: value" line per trailer. As a bonus, this could be used even without --only-trailers to clean up unusual formatting in the incoming data. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- trailer.h | 1 + 1 file changed, 1 insertion(+) (limited to 'trailer.h') diff --git a/trailer.h b/trailer.h index 76c3b571bf6..194f85a1023 100644 --- a/trailer.h +++ b/trailer.h @@ -27,6 +27,7 @@ struct process_trailer_options { int trim_empty; int only_trailers; int only_input; + int unfold; }; #define PROCESS_TRAILER_OPTIONS_INIT {0} -- cgit v1.2.3 From a388b10fc17c435df32c3875225a1468edad9535 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 15 Aug 2017 06:23:56 -0400 Subject: 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 Signed-off-by: Junio C Hamano --- trailer.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'trailer.h') diff --git a/trailer.h b/trailer.h index 194f85a1023..a172811022f 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 */ -- cgit v1.2.3