Message ID | 0e9ae049b8861fecf49c097e8d52e734f7a9c9b3.1713504153.git.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Commit | 3ddad1b1aabee1fdb1fcd229f18f362721a1108a |
Headers | show |
Series | Make trailer_info struct private (plus sequencer cleanup) | expand |
"Linus Arver via GitGitGadget" <gitgitgadget@gmail.com> writes: > There are a couple disadvantages: > > (A) every time the member of the struct is accessed an extra pointer > dereference must be done, and > > (B) for users of trailer_info outside trailer.c, this struct can no > longer be allocated on the stack and may only be allocated on the > heap (because its definition is hidden away in trailer.c) and > appropriately deallocated by the user. (C) without good documentation on the API, the opaque struct is hostile to programmers by going opposite to "Show me your data structures, and I won't usually need your code; it'll be obvious." mantra. The comment inside trailer.c does not count (the API users are not supposed to peek in it---that's the whole point of making the structure opaque). You'd need to compensate with a bit more doc in trailer.h to help the API users. Other than that, looks "correct".
Junio C Hamano <gitster@pobox.com> writes: > "Linus Arver via GitGitGadget" <gitgitgadget@gmail.com> writes: > >> There are a couple disadvantages: >> >> (A) every time the member of the struct is accessed an extra pointer >> dereference must be done, and >> >> (B) for users of trailer_info outside trailer.c, this struct can no >> longer be allocated on the stack and may only be allocated on the >> heap (because its definition is hidden away in trailer.c) and >> appropriately deallocated by the user. > > (C) without good documentation on the API, the opaque struct is > hostile to programmers by going opposite to "Show me your > data structures, and I won't usually need your code; it'll > be obvious." mantra. > > The comment inside trailer.c does not count (the API users are not > supposed to peek in it---that's the whole point of making the > structure opaque). You'd need to compensate with a bit more doc in > trailer.h to help the API users. SGTM. I can reroll again by the end of the week to add docs for would-be API users. Cheers
diff --git a/trailer.c b/trailer.c index 9179dd802c6..6167b707ae0 100644 --- a/trailer.c +++ b/trailer.c @@ -11,6 +11,27 @@ * Copyright (c) 2013, 2014 Christian Couder <chriscool@tuxfamily.org> */ +struct trailer_info { + /* + * True if there is a blank line before the location pointed to by + * trailer_block_start. + */ + int blank_line_before_trailer; + + /* + * Offsets to the trailer block start and end positions in the input + * string. If no trailer block is found, these are both set to the + * "true" end of the input (find_end_of_log_message()). + */ + size_t trailer_block_start, trailer_block_end; + + /* + * Array of trailers found. + */ + char **trailers; + size_t trailer_nr; +}; + struct conf_info { char *name; char *key; diff --git a/trailer.h b/trailer.h index b32213a9e23..a63e97a2663 100644 --- a/trailer.h +++ b/trailer.h @@ -4,6 +4,8 @@ #include "list.h" #include "strbuf.h" +struct trailer_info; + enum trailer_where { WHERE_DEFAULT, WHERE_END, @@ -29,27 +31,6 @@ int trailer_set_where(enum trailer_where *item, const char *value); int trailer_set_if_exists(enum trailer_if_exists *item, const char *value); int trailer_set_if_missing(enum trailer_if_missing *item, const char *value); -struct trailer_info { - /* - * True if there is a blank line before the location pointed to by - * trailer_block_start. - */ - int blank_line_before_trailer; - - /* - * Offsets to the trailer block start and end positions in the input - * string. If no trailer block is found, these are both set to the - * "true" end of the input (find_end_of_log_message()). - */ - size_t trailer_block_start, trailer_block_end; - - /* - * Array of trailers found. - */ - char **trailers; - size_t trailer_nr; -}; - /* * A list that represents newly-added trailers, such as those provided * with the --trailer command line option of git-interpret-trailers.