diff options
author | Przemyslaw Ciezkowski <pc.pc3t@gmail.com> | 2021-11-25 15:19:17 +0100 |
---|---|---|
committer | Przemyslaw Ciezkowski <pc.pc3t@gmail.com> | 2021-11-25 15:19:52 +0100 |
commit | 1e015088d0878ebbf6545702688dff2d69c9eeb5 (patch) | |
tree | 2e7b84d97013e3f6e85aacdf3445d48cebbc77c2 /src/commit.c | |
parent | f9c4dc10d90732cfbe2271dd58b01dd8f4003d15 (diff) | |
download | libgit2-1e015088d0878ebbf6545702688dff2d69c9eeb5.tar.gz |
git_commit_summary: ignore lines with spaces
Fixes libgit2/libgit2#6065
Diffstat (limited to 'src/commit.c')
-rw-r--r-- | src/commit.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/commit.c b/src/commit.c index 752d98b02..81e5b02d3 100644 --- a/src/commit.c +++ b/src/commit.c @@ -546,7 +546,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); @@ -555,10 +555,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; |