From 90563aedcab92b75d4b5f6d7aa43d6a98aaccde6 Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Sat, 13 Feb 2021 01:52:41 +0000 Subject: pretty.c: refactor trailer logic to `format_set_trailers_options()` Refactored trailers formatting logic inside pretty.c to a new function `format_set_trailers_options()`. This new function returns the non-zero in case of unusual. The caller handles the non-zero by "goto trailers_out". This change will allow us to reuse the same logic in other places. Mentored-by: Christian Couder Mentored-by: Heba Waly Signed-off-by: Hariom Verma Signed-off-by: Junio C Hamano --- pretty.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'pretty.h') diff --git a/pretty.h b/pretty.h index 7ce6c0b437..7369cf7e14 100644 --- a/pretty.h +++ b/pretty.h @@ -6,6 +6,7 @@ struct commit; struct strbuf; +struct process_trailer_options; /* Commit formats */ enum cmit_fmt { @@ -142,4 +143,14 @@ int commit_format_is_empty(enum cmit_fmt); /* Make subject of commit message suitable for filename */ void format_sanitized_subject(struct strbuf *sb, const char *msg, size_t len); +/* + * Set values of fields in "struct process_trailer_options" + * according to trailers arguments. + */ +int format_set_trailers_options(struct process_trailer_options *opts, + struct string_list *filter_list, + struct strbuf *sepbuf, + struct strbuf *kvsepbuf, + const char **arg); + #endif /* PRETTY_H */ -- cgit v1.2.3 From 636a0aeedfee5f3cce2ebf1fcc174a49ab9bb0c3 Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Sat, 13 Feb 2021 01:52:42 +0000 Subject: pretty.c: capture invalid trailer argument As we would like to use this trailers logic in the ref-filter, it's nice to get an invalid trailer argument. This will allow us to print precise error message while using `format_set_trailers_options()` in ref-filter. For capturing the invalid argument, we changed the working of `format_set_trailers_options()` a little bit. Original logic does "break" and fell through in mainly 2 cases - 1. unknown/invalid argument 2. end of the arg string But now instead of "break", we capture invalid argument and return non-zero. And non-zero is handled by the caller. (We prepared the caller to handle non-zero in the previous commit). Capturing invalid arguments this way will also affects the working of current logic. As at the end of the arg string it will return non-zero. So in order to make things correct, introduced an additional conditional statement i.e if encounter ")", do 'break'. Mentored-by: Christian Couder Mentored-by: Heba Waly Signed-off-by: Hariom Verma Signed-off-by: Junio C Hamano --- pretty.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'pretty.h') diff --git a/pretty.h b/pretty.h index 7369cf7e14..d902cdd70a 100644 --- a/pretty.h +++ b/pretty.h @@ -151,6 +151,7 @@ int format_set_trailers_options(struct process_trailer_options *opts, struct string_list *filter_list, struct strbuf *sepbuf, struct strbuf *kvsepbuf, - const char **arg); + const char **arg, + char **invalid_arg); #endif /* PRETTY_H */ -- cgit v1.2.3