]> git.ipfire.org Git - thirdparty/git.git/commitdiff
interpret-trailers: access trailer_info with new helpers
authorLinus Arver <linus@ucla.edu>
Thu, 2 May 2024 04:54:22 +0000 (04:54 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 2 May 2024 16:57:08 +0000 (09:57 -0700)
Instead of directly accessing trailer_info members, access them
indirectly through new helper functions exposed by the trailer API.

This is the first of two preparatory commits which will allow us to
use the so-called "pimpl" (pointer to implementation) idiom for the
trailer API, by making the trailer_info struct private to the trailer
implementation (and thus hidden from the API).

Helped-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Linus Arver <linus@ucla.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/interpret-trailers.c
trailer.c
trailer.h

index 11f4ce9e4a274c666fe4127a904872653d35010d..f3240682e352297f6a78efbffc26e80061f18bce 100644 (file)
@@ -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;
+       struct trailer_info *info = trailer_info_new();
        FILE *outfile = stdout;
 
        trailer_config_init();
@@ -151,13 +151,13 @@ 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);
+       parse_trailers(opts, info, sb.buf, &head);
 
        /* Print the lines before the trailers */
        if (!opts->only_trailers)
-               fwrite(sb.buf, 1, info.trailer_block_start, outfile);
+               fwrite(sb.buf, 1, trailer_block_start(info), outfile);
 
-       if (!opts->only_trailers && !info.blank_line_before_trailer)
+       if (!opts->only_trailers && !blank_line_before_trailer_block(info))
                fprintf(outfile, "\n");
 
 
@@ -178,8 +178,8 @@ static void interpret_trailers(const struct process_trailer_options *opts,
 
        /* Print the lines after the trailers as is */
        if (!opts->only_trailers)
-               fwrite(sb.buf + info.trailer_block_end, 1, sb.len - info.trailer_block_end, outfile);
-       trailer_info_release(&info);
+               fwrite(sb.buf + trailer_block_end(info), 1, sb.len - trailer_block_end(info), outfile);
+       trailer_info_release(info);
 
        if (opts->in_place)
                if (rename_tempfile(&trailers_tempfile, file))
index 4700c4414427a1aa621f31478554c2c0620fe355..95b4c9b8f1949cfbb523aa654f4a70db60384418 100644 (file)
--- a/trailer.c
+++ b/trailer.c
@@ -952,6 +952,12 @@ static void unfold_value(struct strbuf *val)
        strbuf_release(&out);
 }
 
+struct trailer_info *trailer_info_new(void)
+{
+       struct trailer_info *info = xcalloc(1, sizeof(*info));
+       return info;
+}
+
 /*
  * Parse trailers in "str", populating the trailer info and "head"
  * linked list structure.
@@ -1000,6 +1006,21 @@ void free_trailers(struct list_head *trailers)
        }
 }
 
+size_t trailer_block_start(struct trailer_info *info)
+{
+       return info->trailer_block_start;
+}
+
+size_t trailer_block_end(struct trailer_info *info)
+{
+       return info->trailer_block_end;
+}
+
+int blank_line_before_trailer_block(struct trailer_info *info)
+{
+       return info->blank_line_before_trailer;
+}
+
 void trailer_info_get(const struct process_trailer_options *opts,
                      const char *str,
                      struct trailer_info *info)
index 7e36da7d13c068e0ba4b52637a543868d5da7db5..9ba967213985916a71154980ca14a2010522741c 100644 (file)
--- a/trailer.h
+++ b/trailer.h
@@ -97,6 +97,10 @@ void parse_trailers(const struct process_trailer_options *,
 void trailer_info_get(const struct process_trailer_options *,
                      const char *str,
                      struct trailer_info *);
+size_t trailer_block_start(struct trailer_info *);
+size_t trailer_block_end(struct trailer_info *);
+int blank_line_before_trailer_block(struct trailer_info *);
+struct trailer_info *trailer_info_new(void);
 
 void trailer_info_release(struct trailer_info *info);