Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Pegon <pegon.marc@gmail.com>2011-06-08 13:16:31 +0400
committerMarc Pegon <pegon.marc@gmail.com>2011-06-08 13:16:31 +0400
commit858ef372a4378652796d63c8d9af579608950f0a (patch)
tree5fb640f70892c6edcc241a1e6533edc336159331 /src/commit.c
parent3a12891f53cd5c349c0eed2ace7a9a900432aa5e (diff)
Changed commit short messages so that they match git log --oneline output.
In git, the short message of a commit is the part of the commit message before 2 consecutive line breaks. In the short message, line breaks are replaced by space characters.
Diffstat (limited to 'src/commit.c')
-rw-r--r--src/commit.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/commit.c b/src/commit.c
index bfae0592e..6857eddab 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -292,6 +292,7 @@ int commit_parse_buffer(git_commit *commit, const void *data, size_t len)
if (buffer < buffer_end) {
const char *line_end;
+ unsigned int i;
size_t message_len;
/* Long message */
@@ -301,12 +302,18 @@ int commit_parse_buffer(git_commit *commit, const void *data, size_t len)
commit->message[message_len] = 0;
/* Short message */
- if((line_end = memchr(buffer, '\n', buffer_end - buffer)) == NULL)
- line_end = buffer_end;
+ if((line_end = strstr(buffer, "\n\n")) == NULL) {
+ /* Cut the last '\n' if there is one */
+ if (message_len && buffer[message_len - 1] == '\n')
+ line_end = buffer_end - 1;
+ else
+ line_end = buffer_end;
+ }
message_len = line_end - buffer;
-
commit->message_short = git__malloc(message_len + 1);
- memcpy(commit->message_short, buffer, message_len);
+ for (i = 0; i < message_len; ++i) {
+ commit->message_short[i] = (buffer[i] == '\n') ? ' ' : buffer[i];
+ }
commit->message_short[message_len] = 0;
}