git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 1/2] Make the skip_blank_lines() function public

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jun 22, 2016, 20:20 UTC
Message-ID
<293bdb45f4a7c8b635ec246763346710ff4e3111.1466626795.git.johannes.schindelin@gmx.de>
In-Reply-To
<cover.1466626795.git.johannes.schindelin@gmx.de>
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 <johannes.schindelin@gmx.de>
---
 commit.h |  1 +
 pretty.c | 16 ++++++++--------
 2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/commit.h b/commit.h
index b06db4d..5b78f83 100644
--- a/commit.h
+++ b/commit.h
@@ -177,6 +177,7 @@ extern const char *format_subject(struct strbuf *sb, const char *msg,
 				  const char *line_separator);
 extern void userformat_find_requirements(const char *fmt, struct userformat_want *w);
 extern int commit_format_is_empty(enum cmit_fmt);
+extern const char *skip_blank_lines(const char *msg);
 extern void format_commit_message(const struct commit *commit,
 				  const char *format, struct strbuf *sb,
 				  const struct pretty_print_context *context);
diff --git a/pretty.c b/pretty.c
index c3ec430..3b6bff7 100644
--- a/pretty.c
+++ b/pretty.c
@@ -507,7 +507,7 @@ void pp_user_info(struct pretty_print_context *pp,
 	}
 }
 
-static int is_empty_line(const char *line, int *len_p)
+static int is_blank_line(const char *line, int *len_p)
 {
 	int len = *len_p;
 	while (len && isspace(line[len - 1]))
@@ -516,14 +516,14 @@ static int is_empty_line(const char *line, int *len_p)
 	return !len;
 }
 
-static const char *skip_empty_lines(const char *msg)
+const char *skip_blank_lines(const char *msg)
 {
 	for (;;) {
 		int linelen = get_one_line(msg);
 		int ll = linelen;
 		if (!linelen)
 			break;
-		if (!is_empty_line(msg, &ll))
+		if (!is_blank_line(msg, &ll))
 			break;
 		msg += linelen;
 	}
@@ -875,7 +875,7 @@ const char *format_subject(struct strbuf *sb, const char *msg,
 		int linelen = get_one_line(line);
 
 		msg += linelen;
-		if (!linelen || is_empty_line(line, &linelen))
+		if (!linelen || is_blank_line(line, &linelen))
 			break;
 
 		if (!sb)
@@ -894,11 +894,11 @@ static void parse_commit_message(struct format_commit_context *c)
 	const char *msg = c->message + c->message_off;
 	const char *start = c->message;
 
-	msg = skip_empty_lines(msg);
+	msg = skip_blank_lines(msg);
 	c->subject_off = msg - start;
 
 	msg = format_subject(NULL, msg, NULL);
-	msg = skip_empty_lines(msg);
+	msg = skip_blank_lines(msg);
 	c->body_off = msg - start;
 
 	c->commit_message_parsed = 1;
@@ -1711,7 +1711,7 @@ void pp_remainder(struct pretty_print_context *pp,
 		if (!linelen)
 			break;
 
-		if (is_empty_line(line, &linelen)) {
+		if (is_blank_line(line, &linelen)) {
 			if (first)
 				continue;
 			if (pp->fmt == CMIT_FMT_SHORT)
@@ -1782,7 +1782,7 @@ void pretty_print_commit(struct pretty_print_context *pp,
 	}
 
 	/* Skip excess blank lines at the beginning of body, if any... */
-	msg = skip_empty_lines(msg);
+	msg = skip_blank_lines(msg);
 
 	/* These formats treat the title line specially. */
 	if (pp->fmt == CMIT_FMT_ONELINE || pp->fmt == CMIT_FMT_EMAIL)
-- 
2.9.0.118.g0e1a633
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 14 of 15 in “Make find_commit_subject() more robust”
  1. Make find_commit_subject() more robustJohannes Schindelin, Jun 18, 2016
  2. Junio C HamanoJun 20, 2016
  3. Johannes SchindelinJun 21, 2016
  4. Junio C HamanoJun 21, 2016
  5. Johannes SchindelinJun 22, 2016
  6. Make find_commit_subject() more robustJohannes Schindelin, Jun 21, 2016
  7. Junio C HamanoJun 21, 2016
  8. 0/2 Make find_commit_subject() consistent with --format=%sJohannes Schindelin, Jun 22, 2016
  9. 2/2 Make find_commit_subject() more robustJohannes Schindelin, Jun 22, 2016
  10. 1/2 Make the skip_empty_lines() function publicJohannes Schindelin, Jun 22, 2016
  11. Junio C HamanoJun 22, 2016
  12. Johannes SchindelinJun 22, 2016
  13. 0/2 Make find_commit_subject() consistent with --format=%sJohannes Schindelin, Jun 22, 2016
  14. 1/2 Make the skip_blank_lines() function publicJohannes Schindelin, Jun 22, 2016
  15. 2/2 Make find_commit_subject() more robustJohannes Schindelin, Jun 22, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.