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
ab136876
Commit
ab136876
authored
Oct 03, 2013
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1887 from libgit2/ntk/topic/git_message_raw
commit: Introduce git_commit_message_raw()
parents
c8f2ba99
598f069b
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
7 deletions
+37
-7
include/git2/commit.h
+11
-0
src/commit.c
+18
-5
src/commit.h
+1
-1
tests-clar/commit/parse.c
+7
-1
No files found.
include/git2/commit.h
View file @
ab136876
...
...
@@ -100,12 +100,23 @@ GIT_EXTERN(const char *) git_commit_message_encoding(const git_commit *commit);
/**
* Get the full message of a commit.
*
* The returned message will be slightly prettified by removing any
* potential leading newlines.
*
* @param commit a previously loaded commit.
* @return the message of a commit
*/
GIT_EXTERN
(
const
char
*
)
git_commit_message
(
const
git_commit
*
commit
);
/**
* Get the full raw message of a commit.
*
* @param commit a previously loaded commit.
* @return the raw message of a commit
*/
GIT_EXTERN
(
const
char
*
)
git_commit_message_raw
(
const
git_commit
*
commit
);
/**
* Get the commit time (i.e. committer time) of a commit.
*
* @param commit a previously loaded commit.
...
...
src/commit.c
View file @
ab136876
...
...
@@ -29,7 +29,7 @@ void git_commit__free(void *_commit)
git_signature_free
(
commit
->
committer
);
git__free
(
commit
->
raw_header
);
git__free
(
commit
->
message
);
git__free
(
commit
->
raw_
message
);
git__free
(
commit
->
message_encoding
);
git__free
(
commit
);
...
...
@@ -240,13 +240,13 @@ int git_commit__parse(void *_commit, git_odb_object *odb_obj)
buffer_end
=
buffer
+
git_odb_object_size
(
odb_obj
);
buffer
+=
header_len
;
while
(
buffer
<
buffer_end
&&
*
buffer
==
'\n'
)
if
(
*
buffer
==
'\n'
)
++
buffer
;
/* extract commit message */
if
(
buffer
<=
buffer_end
)
{
commit
->
message
=
git__strndup
(
buffer
,
buffer_end
-
buffer
);
GITERR_CHECK_ALLOC
(
commit
->
message
);
commit
->
raw_
message
=
git__strndup
(
buffer
,
buffer_end
-
buffer
);
GITERR_CHECK_ALLOC
(
commit
->
raw_
message
);
}
return
0
;
...
...
@@ -265,7 +265,7 @@ bad_buffer:
GIT_COMMIT_GETTER
(
const
git_signature
*
,
author
,
commit
->
author
)
GIT_COMMIT_GETTER
(
const
git_signature
*
,
committer
,
commit
->
committer
)
GIT_COMMIT_GETTER
(
const
char
*
,
message
,
commit
->
message
)
GIT_COMMIT_GETTER
(
const
char
*
,
message
_raw
,
commit
->
raw_
message
)
GIT_COMMIT_GETTER
(
const
char
*
,
message_encoding
,
commit
->
message_encoding
)
GIT_COMMIT_GETTER
(
const
char
*
,
raw_header
,
commit
->
raw_header
)
GIT_COMMIT_GETTER
(
git_time_t
,
time
,
commit
->
committer
->
when
.
time
)
...
...
@@ -273,6 +273,19 @@ GIT_COMMIT_GETTER(int, time_offset, commit->committer->when.offset)
GIT_COMMIT_GETTER
(
unsigned
int
,
parentcount
,
(
unsigned
int
)
git_array_size
(
commit
->
parent_ids
))
GIT_COMMIT_GETTER
(
const
git_oid
*
,
tree_id
,
&
commit
->
tree_id
);
const
char
*
git_commit_message
(
const
git_commit
*
commit
)
{
const
char
*
message
=
commit
->
raw_message
;
assert
(
commit
);
/* trim leading newlines from raw message */
while
(
*
message
&&
*
message
==
'\n'
)
++
message
;
return
message
;
}
int
git_commit_tree
(
git_tree
**
tree_out
,
const
git_commit
*
commit
)
{
assert
(
commit
);
...
...
src/commit.h
View file @
ab136876
...
...
@@ -24,7 +24,7 @@ struct git_commit {
git_signature
*
committer
;
char
*
message_encoding
;
char
*
message
;
char
*
raw_
message
;
char
*
raw_header
;
};
...
...
tests-clar/commit/parse.c
View file @
ab136876
...
...
@@ -382,9 +382,13 @@ committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
This commit has a few LF at the start of the commit message"
;
const
char
*
message
=
"This commit has a few LF at the start of the commit message"
;
const
char
*
raw_message
=
"
\n
\
\n
\
This commit has a few LF at the start of the commit message"
;
cl_git_pass
(
parse_commit
(
&
commit
,
buffer
));
cl_assert_equal_s
(
message
,
git_commit_message
(
commit
));
cl_assert_equal_s
(
raw_message
,
git_commit_message_raw
(
commit
));
git_commit__free
(
commit
);
}
...
...
@@ -400,8 +404,10 @@ committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
\n
\
\n
"
;
const
char
*
message
=
""
;
const
char
*
raw_message
=
"
\n\n
"
;
cl_git_pass
(
parse_commit
(
&
commit
,
buffer
));
cl_assert_equal_s
(
message
,
git_commit_message
(
commit
));
cl_assert_equal_s
(
raw_message
,
git_commit_message_raw
(
commit
));
git_commit__free
(
commit
);
}
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