sequencer: export and rename subject_length()

This function can be used in other parts of git. Let's move the function to commit.c and also rename it to make the name of the function more generic. Mentored-by: Christian Couder <chriscool@tuxfamily.org> Mentored-by: Phillip Wood <phillip.wood@dunelm.org.uk> Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Charvi Mendiratta <charvi077@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Charvi Mendiratta committed Mar 15, 2021 at 13:24 UTC 6e0e28877988f8b98eb1e5cf4d4c5d29cc0b7f77
3 files changed +18 -15
commit.c
+14
@@ -535,6 +535,20 @@ int find_commit_subject(const char *commit_buffer, const char **subject)
535 return eol - p;
536 }
537
538 +size_t commit_subject_length(const char *body)
539 +{
540 + const char *p = body;
541 + while (*p) {
542 + const char *next = skip_blank_lines(p);
543 + if (next != p)
544 + break;
545 + p = strchrnul(p, '\n');
546 + if (*p)
547 + p++;
548 + }
549 + return p - body;
550 +}
551 +
552 struct commit_list *commit_list_insert(struct commit *item, struct commit_list **list_p)
553 {
554 struct commit_list *new_list = xmalloc(sizeof(struct commit_list));
commit.h
+3
@@ -165,6 +165,9 @@ const void *detach_commit_buffer(struct commit *, unsigned long *sizep);
165 /* Find beginning and length of commit subject. */
166 int find_commit_subject(const char *commit_buffer, const char **subject);
167
168 +/* Return length of the commit subject from commit log message. */
169 +size_t commit_subject_length(const char *body);
170 +
171 struct commit_list *commit_list_insert(struct commit *item,
172 struct commit_list **list);
173 int commit_list_contains(struct commit *item,
sequencer.c
+1 -15
@@ -1724,20 +1724,6 @@ enum todo_item_flags {
1724 TODO_EDIT_FIXUP_MSG = (1 << 2),
1725 };
1726
1727 -static size_t subject_length(const char *body)
1728 -{
1729 - const char *p = body;
1730 - while (*p) {
1731 - const char *next = skip_blank_lines(p);
1732 - if (next != p)
1733 - break;
1734 - p = strchrnul(p, '\n');
1735 - if (*p)
1736 - p++;
1737 - }
1738 - return p - body;
1739 -}
1740 -
1727 static const char first_commit_msg_str[] = N_("This is the 1st commit message:");
1728 static const char nth_commit_msg_fmt[] = N_("This is the commit message #%d:");
1729 static const char skip_first_commit_msg_str[] = N_("The 1st commit message will be skipped:");
@@ -1861,7 +1847,7 @@ static int append_squash_message(struct strbuf *buf, const char *body,
1847 if (starts_with(body, "amend!") ||
1848 ((command == TODO_SQUASH || seen_squash(opts)) &&
1849 (starts_with(body, "squash!") || starts_with(body, "fixup!"))))
1864 - commented_len = subject_length(body);
1850 + commented_len = commit_subject_length(body);
1851
1852 strbuf_addf(buf, "\n%c ", comment_line_char);
1853 strbuf_addf(buf, _(nth_commit_msg_fmt),