summaryrefslogtreecommitdiff
path: root/src/commit.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-12-23 14:13:34 -0500
committerGitHub <noreply@github.com>2021-12-23 14:13:34 -0500
commit3cca14b3c1182f093d7e2d9c7de8bcb8b8828163 (patch)
treec01ce062a3aebb2edbd68d92abb07eaca9d2c9f1 /src/commit.c
parentdca31d2427ef2321fab61bd5e3f3470306ba445d (diff)
parent1e015088d0878ebbf6545702688dff2d69c9eeb5 (diff)
downloadlibgit2-3cca14b3c1182f093d7e2d9c7de8bcb8b8828163.tar.gz
Merge pull request #6125 from stforek/git_commit_summary_spaces
git_commit_summary: ignore lines with spaces
Diffstat (limited to 'src/commit.c')
-rw-r--r--src/commit.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/commit.c b/src/commit.c
index ceaccb331..b137463f3 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -547,7 +547,7 @@ const char *git_commit_message(const git_commit *commit)
const char *git_commit_summary(git_commit *commit)
{
git_str summary = GIT_STR_INIT;
- const char *msg, *space;
+ const char *msg, *space, *next;
bool space_contains_newline = false;
GIT_ASSERT_ARG_WITH_RETVAL(commit, NULL);
@@ -556,10 +556,21 @@ const char *git_commit_summary(git_commit *commit)
for (msg = git_commit_message(commit), space = NULL; *msg; ++msg) {
char next_character = msg[0];
/* stop processing at the end of the first paragraph */
- if (next_character == '\n' && (!msg[1] || msg[1] == '\n'))
- break;
+ if (next_character == '\n') {
+ if (!msg[1])
+ break;
+ if (msg[1] == '\n')
+ break;
+ /* stop processing if next line contains only whitespace */
+ next = msg + 1;
+ while (*next && git__isspace_nonlf(*next)) {
+ ++next;
+ }
+ if (!*next || *next == '\n')
+ break;
+ }
/* record the beginning of contiguous whitespace runs */
- else if (git__isspace(next_character)) {
+ if (git__isspace(next_character)) {
if(space == NULL) {
space = msg;
space_contains_newline = false;