Skip to content

Commit 6e0e288

Browse files
charvi-077gitster
authored andcommitted
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 <[email protected]> Mentored-by: Phillip Wood <[email protected]> Helped-by: Eric Sunshine <[email protected]> Signed-off-by: Charvi Mendiratta <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fa153c1 commit 6e0e288

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

commit.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,20 @@ int find_commit_subject(const char *commit_buffer, const char **subject)
535535
return eol - p;
536536
}
537537

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+
538552
struct commit_list *commit_list_insert(struct commit *item, struct commit_list **list_p)
539553
{
540554
struct commit_list *new_list = xmalloc(sizeof(struct commit_list));

commit.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ const void *detach_commit_buffer(struct commit *, unsigned long *sizep);
165165
/* Find beginning and length of commit subject. */
166166
int find_commit_subject(const char *commit_buffer, const char **subject);
167167

168+
/* Return length of the commit subject from commit log message. */
169+
size_t commit_subject_length(const char *body);
170+
168171
struct commit_list *commit_list_insert(struct commit *item,
169172
struct commit_list **list);
170173
int commit_list_contains(struct commit *item,

sequencer.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,20 +1724,6 @@ enum todo_item_flags {
17241724
TODO_EDIT_FIXUP_MSG = (1 << 2),
17251725
};
17261726

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-
17411727
static const char first_commit_msg_str[] = N_("This is the 1st commit message:");
17421728
static const char nth_commit_msg_fmt[] = N_("This is the commit message #%d:");
17431729
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,
18611847
if (starts_with(body, "amend!") ||
18621848
((command == TODO_SQUASH || seen_squash(opts)) &&
18631849
(starts_with(body, "squash!") || starts_with(body, "fixup!"))))
1864-
commented_len = subject_length(body);
1850+
commented_len = commit_subject_length(body);
18651851

18661852
strbuf_addf(buf, "\n%c ", comment_line_char);
18671853
strbuf_addf(buf, _(nth_commit_msg_fmt),

0 commit comments

Comments
 (0)