trailer: make parse_trailers() return trailer_info pointer
This is the second and final preparatory commit for making the trailer_info struct private to the trailer implementation. Make trailer_info_get() do the actual work of allocating a new trailer_info struct, and return a pointer to it. Because parse_trailers() wraps around trailer_info_get(), it too can return this pointer to the caller. From the trailer API user's perspective, the call to trailer_info_new() can be replaced with parse_trailers(); do so in interpret-trailers. Because trailer_info_new() is no longer called by interpret-trailers, remove this function from the trailer API. With this change, we no longer allocate trailer_info on the stack --- all uses of it are via a pointer where the actual data is always allocated at runtime through trailer_info_new(). Make trailer_info_release() free this dynamically allocated memory. Finally, due to the way the function signatures of parse_trailers() and trailer_info_get() have changed, update the callsites in format_trailers_from_commit() and trailer_iterator_init() accordingly. Helped-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Linus Arver <linus@ucla.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
655eb65d48
commit
24a25c630c
@ -141,7 +141,7 @@ static void interpret_trailers(const struct process_trailer_options *opts,
|
||||
LIST_HEAD(head);
|
||||
struct strbuf sb = STRBUF_INIT;
|
||||
struct strbuf trailer_block = STRBUF_INIT;
|
||||
struct trailer_info *info = trailer_info_new();
|
||||
struct trailer_info *info;
|
||||
FILE *outfile = stdout;
|
||||
|
||||
trailer_config_init();
|
||||
@ -151,7 +151,7 @@ static void interpret_trailers(const struct process_trailer_options *opts,
|
||||
if (opts->in_place)
|
||||
outfile = create_in_place_tempfile(file);
|
||||
|
||||
parse_trailers(opts, info, sb.buf, &head);
|
||||
info = parse_trailers(opts, sb.buf, &head);
|
||||
|
||||
/* Print the lines before the trailers */
|
||||
if (!opts->only_trailers)
|
||||
|
Reference in New Issue
Block a user