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
52b597b6
Commit
52b597b6
authored
May 19, 2014
by
Vicent Marti
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2364 from libgit2/cmn/comment-char
message: don't assume the comment char
parents
138af337
49e369b2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
13 deletions
+15
-13
include/git2/message.h
+5
-3
src/message.c
+2
-2
tests/object/commit/commitstagedfile.c
+1
-1
tests/object/message.c
+7
-7
No files found.
include/git2/message.h
View file @
52b597b6
...
...
@@ -29,12 +29,14 @@ GIT_BEGIN_DECL
*
* @param message The message to be prettified.
*
* @param strip_comments Non-zero to remove lines starting with "#", 0 to
* leave them in.
* @param strip_comments Non-zero to remove comment lines, 0 to leave them in.
*
* @param comment_char Comment character. Lines starting with this character
* are considered to be comments and removed if `strip_comments` is non-zero.
*
* @return 0 or an error code.
*/
GIT_EXTERN
(
int
)
git_message_prettify
(
git_buf
*
out
,
const
char
*
message
,
int
strip_comments
);
GIT_EXTERN
(
int
)
git_message_prettify
(
git_buf
*
out
,
const
char
*
message
,
int
strip_comments
,
char
comment_char
);
/** @} */
GIT_END_DECL
...
...
src/message.c
View file @
52b597b6
...
...
@@ -21,7 +21,7 @@ static size_t line_length_without_trailing_spaces(const char *line, size_t len)
/* Greatly inspired from git.git "stripspace" */
/* see https://github.com/git/git/blob/497215d8811ac7b8955693ceaad0899ecd894ed2/builtin/stripspace.c#L4-67 */
int
git_message_prettify
(
git_buf
*
message_out
,
const
char
*
message
,
int
strip_comments
)
int
git_message_prettify
(
git_buf
*
message_out
,
const
char
*
message
,
int
strip_comments
,
char
comment_char
)
{
const
size_t
message_len
=
strlen
(
message
);
...
...
@@ -40,7 +40,7 @@ int git_message_prettify(git_buf *message_out, const char *message, int strip_co
line_length
=
message_len
-
i
;
}
if
(
strip_comments
&&
line_length
&&
message
[
i
]
==
'#'
)
if
(
strip_comments
&&
line_length
&&
message
[
i
]
==
comment_char
)
continue
;
rtrimmed_line_length
=
line_length_without_trailing_spaces
(
message
+
i
,
line_length
);
...
...
tests/object/commit/commitstagedfile.c
View file @
52b597b6
...
...
@@ -112,7 +112,7 @@ void test_object_commit_commitstagedfile__generate_predictable_object_ids(void)
cl_git_pass
(
git_tree_lookup
(
&
tree
,
repo
,
&
tree_oid
));
memset
(
&
buffer
,
0
,
sizeof
(
git_buf
));
cl_git_pass
(
git_message_prettify
(
&
buffer
,
"Initial commit"
,
0
));
cl_git_pass
(
git_message_prettify
(
&
buffer
,
"Initial commit"
,
0
,
'#'
));
cl_git_pass
(
git_commit_create_v
(
&
commit_oid
,
...
...
tests/object/message.c
View file @
52b597b6
...
...
@@ -6,7 +6,7 @@ static void assert_message_prettifying(char *expected_output, char *input, int s
{
git_buf
prettified_message
=
GIT_BUF_INIT
;
git_message_prettify
(
&
prettified_message
,
input
,
strip_comments
);
git_message_prettify
(
&
prettified_message
,
input
,
strip_comments
,
'#'
);
cl_assert_equal_s
(
expected_output
,
git_buf_cstr
(
&
prettified_message
));
git_buf_free
(
&
prettified_message
);
...
...
@@ -175,25 +175,25 @@ void test_object_message__message_prettify(void)
git_buf
buffer
;
memset
(
&
buffer
,
0
,
sizeof
(
buffer
));
cl_git_pass
(
git_message_prettify
(
&
buffer
,
""
,
0
));
cl_git_pass
(
git_message_prettify
(
&
buffer
,
""
,
0
,
'#'
));
cl_assert_equal_s
(
buffer
.
ptr
,
""
);
git_buf_free
(
&
buffer
);
cl_git_pass
(
git_message_prettify
(
&
buffer
,
""
,
1
));
cl_git_pass
(
git_message_prettify
(
&
buffer
,
""
,
1
,
'#'
));
cl_assert_equal_s
(
buffer
.
ptr
,
""
);
git_buf_free
(
&
buffer
);
cl_git_pass
(
git_message_prettify
(
&
buffer
,
"Short"
,
0
));
cl_git_pass
(
git_message_prettify
(
&
buffer
,
"Short"
,
0
,
'#'
));
cl_assert_equal_s
(
"Short
\n
"
,
buffer
.
ptr
);
git_buf_free
(
&
buffer
);
cl_git_pass
(
git_message_prettify
(
&
buffer
,
"Short"
,
1
));
cl_git_pass
(
git_message_prettify
(
&
buffer
,
"Short"
,
1
,
'#'
));
cl_assert_equal_s
(
"Short
\n
"
,
buffer
.
ptr
);
git_buf_free
(
&
buffer
);
cl_git_pass
(
git_message_prettify
(
&
buffer
,
"This is longer
\n
And multiline
\n
# with some comments still in
\n
"
,
0
));
cl_git_pass
(
git_message_prettify
(
&
buffer
,
"This is longer
\n
And multiline
\n
# with some comments still in
\n
"
,
0
,
'#'
));
cl_assert_equal_s
(
buffer
.
ptr
,
"This is longer
\n
And multiline
\n
# with some comments still in
\n
"
);
git_buf_free
(
&
buffer
);
cl_git_pass
(
git_message_prettify
(
&
buffer
,
"This is longer
\n
And multiline
\n
# with some comments still in
\n
"
,
1
));
cl_git_pass
(
git_message_prettify
(
&
buffer
,
"This is longer
\n
And multiline
\n
# with some comments still in
\n
"
,
1
,
'#'
));
cl_assert_equal_s
(
buffer
.
ptr
,
"This is longer
\n
And multiline
\n
"
);
git_buf_free
(
&
buffer
);
}
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