commit: remove find_header_mem()

cfc5cf428b (receive-pack.c: consolidate find header logic, 2022-01-06) introduced find_header_mem() and turned find_commit_header() into a thin wrapper. Since then, the latter has become the last remaining caller of the former. Remove it to restore find_commit_header() to the state before cfc5cf428b, get rid of a strlen(3) call and resolve a NEEDSWORK note in the process. Signed-off-by: René Scharfe <l.s.r@web.de> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jun 19, 2024 at 19:13 UTC 28dc26dc337932d9e4df8f83f1e454ea6bbc0897
2 files changed +2 -19
commit.c
+2 -14
@@ -1737,20 +1737,12 @@ struct commit_list **commit_list_append(struct commit *commit,
1737 return &new_commit->next;
1738 }
1739
1740 -const char *find_header_mem(const char *msg, size_t len,
1741 - const char *key, size_t *out_len)
1740 +const char *find_commit_header(const char *msg, const char *key, size_t *out_len)
1741 {
1742 int key_len = strlen(key);
1743 const char *line = msg;
1744
1746 - /*
1747 - * NEEDSWORK: It's possible for strchrnul() to scan beyond the range
1748 - * given by len. However, current callers are safe because they compute
1749 - * len by scanning a NUL-terminated block of memory starting at msg.
1750 - * Nonetheless, it would be better to ensure the function does not look
1751 - * at msg beyond the len provided by the caller.
1752 - */
1753 - while (line && line < msg + len) {
1745 + while (line) {
1746 const char *eol = strchrnul(line, '\n');
1747
1748 if (line == eol)
@@ -1767,10 +1759,6 @@ const char *find_header_mem(const char *msg, size_t len,
1759 return NULL;
1760 }
1761
1770 -const char *find_commit_header(const char *msg, const char *key, size_t *out_len)
1771 -{
1772 - return find_header_mem(msg, strlen(msg), key, out_len);
1773 -}
1762 /*
1763 * Inspect the given string and determine the true "end" of the log message, in
1764 * order to find where to put a new Signed-off-by trailer. Ignored are
commit.h
-5
@@ -280,17 +280,12 @@ void free_commit_extra_headers(struct commit_extra_header *extra);
280
281 /*
282 * Search the commit object contents given by "msg" for the header "key".
283 - * Reads up to "len" bytes of "msg".
283 * Returns a pointer to the start of the header contents, or NULL. The length
284 * of the header, up to the first newline, is returned via out_len.
285 *
286 * Note that some headers (like mergetag) may be multi-line. It is the caller's
287 * responsibility to parse further in this case!
288 */
290 -const char *find_header_mem(const char *msg, size_t len,
291 - const char *key,
292 - size_t *out_len);
293 -
289 const char *find_commit_header(const char *msg, const char *key,
290 size_t *out_len);
291