Skip to content

Commit 7735612

Browse files
dschogitster
authored andcommitted
pretty: make the skip_blank_lines() function public
This function will be used also in the find_commit_subject() function. While at it, rename the function to reflect that it skips not only empty lines, but any lines consisting of only whitespace, too. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7654286 commit 7735612

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

commit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ extern const char *format_subject(struct strbuf *sb, const char *msg,
176176
const char *line_separator);
177177
extern void userformat_find_requirements(const char *fmt, struct userformat_want *w);
178178
extern int commit_format_is_empty(enum cmit_fmt);
179+
extern const char *skip_blank_lines(const char *msg);
179180
extern void format_commit_message(const struct commit *commit,
180181
const char *format, struct strbuf *sb,
181182
const struct pretty_print_context *context);

pretty.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ void pp_user_info(struct pretty_print_context *pp,
505505
}
506506
}
507507

508-
static int is_empty_line(const char *line, int *len_p)
508+
static int is_blank_line(const char *line, int *len_p)
509509
{
510510
int len = *len_p;
511511
while (len && isspace(line[len - 1]))
@@ -514,14 +514,14 @@ static int is_empty_line(const char *line, int *len_p)
514514
return !len;
515515
}
516516

517-
static const char *skip_empty_lines(const char *msg)
517+
const char *skip_blank_lines(const char *msg)
518518
{
519519
for (;;) {
520520
int linelen = get_one_line(msg);
521521
int ll = linelen;
522522
if (!linelen)
523523
break;
524-
if (!is_empty_line(msg, &ll))
524+
if (!is_blank_line(msg, &ll))
525525
break;
526526
msg += linelen;
527527
}
@@ -872,7 +872,7 @@ const char *format_subject(struct strbuf *sb, const char *msg,
872872
int linelen = get_one_line(line);
873873

874874
msg += linelen;
875-
if (!linelen || is_empty_line(line, &linelen))
875+
if (!linelen || is_blank_line(line, &linelen))
876876
break;
877877

878878
if (!sb)
@@ -891,11 +891,11 @@ static void parse_commit_message(struct format_commit_context *c)
891891
const char *msg = c->message + c->message_off;
892892
const char *start = c->message;
893893

894-
msg = skip_empty_lines(msg);
894+
msg = skip_blank_lines(msg);
895895
c->subject_off = msg - start;
896896

897897
msg = format_subject(NULL, msg, NULL);
898-
msg = skip_empty_lines(msg);
898+
msg = skip_blank_lines(msg);
899899
c->body_off = msg - start;
900900

901901
c->commit_message_parsed = 1;
@@ -1642,7 +1642,7 @@ void pp_remainder(struct pretty_print_context *pp,
16421642
if (!linelen)
16431643
break;
16441644

1645-
if (is_empty_line(line, &linelen)) {
1645+
if (is_blank_line(line, &linelen)) {
16461646
if (first)
16471647
continue;
16481648
if (pp->fmt == CMIT_FMT_SHORT)
@@ -1709,7 +1709,7 @@ void pretty_print_commit(struct pretty_print_context *pp,
17091709
}
17101710

17111711
/* Skip excess blank lines at the beginning of body, if any... */
1712-
msg = skip_empty_lines(msg);
1712+
msg = skip_blank_lines(msg);
17131713

17141714
/* These formats treat the title line specially. */
17151715
if (pp->fmt == CMIT_FMT_ONELINE || pp->fmt == CMIT_FMT_EMAIL)

0 commit comments

Comments
 (0)