Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
1e015088
Commit
1e015088
authored
Nov 25, 2021
by
Przemyslaw Ciezkowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
git_commit_summary: ignore lines with spaces
Fixes libgit2/libgit2#6065
parent
f9c4dc10
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
4 deletions
+18
-4
src/commit.c
+15
-4
tests/commit/commit.c
+3
-0
No files found.
src/commit.c
View file @
1e015088
...
...
@@ -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
;
...
...
tests/commit/commit.c
View file @
1e015088
...
...
@@ -139,8 +139,11 @@ void test_commit_commit__summary(void)
{
assert_commit_summary
(
"One-liner with no trailing newline"
,
"One-liner with no trailing newline"
);
assert_commit_summary
(
"One-liner with trailing newline"
,
"One-liner with trailing newline
\n
"
);
assert_commit_summary
(
"One-liner with trailing newline and space"
,
"One-liner with trailing newline and space
\n
"
);
assert_commit_summary
(
"Trimmed leading&trailing newlines"
,
"
\n\n
Trimmed leading&trailing newlines
\n\n
"
);
assert_commit_summary
(
"First paragraph only"
,
"
\n
First paragraph only
\n\n
(There are more!)"
);
assert_commit_summary
(
"First paragraph only with space in the next line"
,
"
\n
First paragraph only with space in the next line
\n
\n
(There are more!)"
);
assert_commit_summary
(
"First paragraph only with spaces in the next line"
,
"
\n
First paragraph only with spaces in the next line
\n
\n
(There are more!)"
);
assert_commit_summary
(
"First paragraph with unwrapped trailing
\t
lines"
,
"
\n
First paragraph
\n
with unwrapped
\n
trailing
\t
lines
\n\n
(Yes, unwrapped!)"
);
assert_commit_summary
(
"
\t
Leading tabs"
,
"
\t
Leading
\n\t
tabs
\n\n
are preserved"
);
/* tabs around newlines are collapsed down to a single space */
assert_commit_summary
(
" Leading Spaces"
,
" Leading
\n
Spaces
\n\n
are preserved"
);
/* spaces around newlines are collapsed down to a single space */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment