trailer: teach find_patch_start about --no-divider
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. By
forcing callers to consider this important option, we avoid the kind of
mistake described in be3d654343
(commit: pass --no-divider to
interpret-trailers, 2023-06-17).
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
94430d03df
commit
ee8c5ee08c
10
trailer.c
10
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);
|
||||
|
||||
|
Reference in New Issue
Block a user