[PATCH 4/5] trailer: teach find_patch_start about --no-divider
- From
- Linus Arver via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Aug 5, 2023, 05:04 UTC
- Message-ID
- <1fc060041db11b3df881cb2c7bd60630dc011a15.1691211879.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.1563.git.1691211879.gitgitgadget@gmail.com>
From: Linus Arver <linusa@google.com>
Currently, find_patch_start only finds the start of the patch part of the input (by looking at the "---" divider) for cases where the "--no-divider" flag has not been provided. If the user provides this flag, we do not rely on find_patch_start at all and just call strlen() directly on the input.
Instead, make find_patch_start aware of "--no-divider" and make it handle that case as well. This means we no longer need to call strlen at all and can just rely on the existing code in find_patch_start.
This patch will make unit testing a bit more pleasant in this area in the future when we adopt a unit testing framework, because we would not have to test multiple functions to check how finding the start of a patch part works (we would only need to test find_patch_start).
Signed-off-by: Linus Arver <linusa@google.com> --- trailer.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/trailer.c b/trailer.c index 89246a0d395..3b9ce199636 100644 --- a/trailer.c +++ b/trailer.c @@ -812,14 +812,14 @@ static ssize_t last_line(const char *buf, size_t len) * Return the position of the start of the patch or the length of str if there * is no patch in the message. */ -static size_t find_patch_start(const char *str) +static size_t find_patch_start(const char *str, int no_divider) { const char *s; for (s = str; *s; s = next_line(s)) { const char *v; - if (skip_prefix(s, "---", &v) && isspace(*v)) + if (!no_divider && skip_prefix(s, "---", &v) && isspace(*v)) return s - str; } @@ -1109,11 +1109,7 @@ void trailer_info_get(struct trailer_info *info, const char *str, ensure_configured(); - if (opts->no_divider) - patch_start = strlen(str); - else - patch_start = find_patch_start(str); - + patch_start = find_patch_start(str, opts->no_divider); trailer_end = find_trailer_end(str, patch_start); trailer_start = find_trailer_start(str, trailer_end);
-- gitgitgadget