git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Schindelin <johannes.schindelin@gmx.de>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v4 0/2] Make find_commit_subject() consistent with --format=%s
Date: Wed, 22 Jun 2016 22:20:11 +0200 (CEST)	[thread overview]
Message-ID: <cover.1466626795.git.johannes.schindelin@gmx.de> (raw)
In-Reply-To: <cover.1466587806.git.johannes.schindelin@gmx.de>

In an intermediate iteration of my rebase--helper patches, I
accidentally generated commits with more than one empty line
between the header and the commit message. When using
find_commit_subject() to show the oneline, it turned up empty, even
if the output of `git show --format=%s` looked fine.

Turned out that the pretty-printing machinery helpfully skipped any
blank lines before the commit message.

I simply make pretty.c's skip_empty_lines() public (now appropriately
named skip_blank_lines()) to make things consistent.


Johannes Schindelin (2):
  Make the skip_blank_lines() function public
  Make find_commit_subject() more robust

 commit.c                 |  2 +-
 commit.h                 |  1 +
 pretty.c                 | 16 ++++++++--------
 t/t8008-blame-formats.sh | 17 +++++++++++++++++
 4 files changed, 27 insertions(+), 9 deletions(-)

Published-As: https://github.com/dscho/git/releases/tag/leading-empty-lines-v4
Interdiff vs v3:

 diff --git a/commit.c b/commit.c
 index 0bf868f..24d4715 100644
 --- a/commit.c
 +++ b/commit.c
 @@ -414,7 +414,7 @@ int find_commit_subject(const char *commit_buffer, const char **subject)
  	while (*p && (*p != '\n' || p[1] != '\n'))
  		p++;
  	if (*p) {
 -		p = skip_empty_lines(p + 2);
 +		p = skip_blank_lines(p + 2);
  		for (eol = p; *eol && *eol != '\n'; eol++)
  			; /* do nothing */
  	} else
 diff --git a/commit.h b/commit.h
 index fbdd18d..5b78f83 100644
 --- a/commit.h
 +++ b/commit.h
 @@ -177,7 +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_empty_lines(const char *msg);
 +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 1b807b4..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;
  }
  
 -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)
 diff --git a/t/t8008-blame-formats.sh b/t/t8008-blame-formats.sh
 index b98f9a4..92c8e79 100755
 --- a/t/t8008-blame-formats.sh
 +++ b/t/t8008-blame-formats.sh
 @@ -87,7 +87,7 @@ test_expect_success 'blame --line-porcelain output' '
  	test_cmp expect actual
  '
  
 -test_expect_success '--porcelain detects first non-empty line as subject' '
 +test_expect_success '--porcelain detects first non-blank line as subject' '
  	(
  		GIT_INDEX_FILE=.git/tmp-index &&
  		export GIT_INDEX_FILE &&

-- 
2.9.0.118.g0e1a633

base-commit: ab7797dbe95fff38d9265869ea367020046db118

  parent reply	other threads:[~2016-06-22 20:20 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-18 13:12 [PATCH] Make find_commit_subject() more robust Johannes Schindelin
2016-06-20 19:35 ` Junio C Hamano
2016-06-21 12:03   ` Johannes Schindelin
2016-06-21 21:15     ` Junio C Hamano
2016-06-22  9:03       ` Johannes Schindelin
2016-06-21 12:43 ` [PATCH v2] " Johannes Schindelin
2016-06-21 20:34   ` Junio C Hamano
2016-06-22  9:34   ` [PATCH v3 0/2] Make find_commit_subject() consistent with --format=%s Johannes Schindelin
2016-06-22  9:34     ` [PATCH v3 1/2] Make the skip_empty_lines() function public Johannes Schindelin
2016-06-22  9:34     ` [PATCH v3 2/2] Make find_commit_subject() more robust Johannes Schindelin
2016-06-22 17:21     ` [PATCH v3 0/2] Make find_commit_subject() consistent with --format=%s Junio C Hamano
2016-06-22 20:20       ` Johannes Schindelin
2016-06-22 20:20     ` Johannes Schindelin [this message]
2016-06-22 20:20       ` [PATCH v4 1/2] Make the skip_blank_lines() function public Johannes Schindelin
2016-06-22 20:20       ` [PATCH v4 2/2] Make find_commit_subject() more robust Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1466626795.git.johannes.schindelin@gmx.de \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).