Commit 4eec2c0d4a332ffb9237a0851578ec388e1f99f4

Vicent Marti 2010-12-07T03:55:46

Set short message when changing a commit's message Yes, finally. Signed-off-by: Vicent Marti <tanoku@gmail.com>

diff --git a/src/commit.c b/src/commit.c
index ef3d80b..d39fc54 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -292,7 +292,8 @@ void git_commit_set_committer(git_commit *commit, const char *name, const char *
 
 void git_commit_set_message(git_commit *commit, const char *message)
 {
-	const char *short_message;
+	const char *line_end;
+	size_t message_len;
 
 	commit->object.modified = 1;
 	CHECK_FULL_PARSE();
@@ -304,9 +305,18 @@ void git_commit_set_message(git_commit *commit, const char *message)
 		free(commit->message_short);
 
 	commit->message = git__strdup(message);
-	commit->message_short = NULL;
 
-	/* TODO: extract short message */
+	/* Short message */
+	if((line_end = strchr(message, '\n')) == NULL) {
+		commit->message_short = git__strdup(message);
+		return;
+	}
+
+	message_len = line_end - message;
+
+	commit->message_short = git__malloc(message_len + 1);
+	memcpy(commit->message_short, message, message_len);
+	commit->message_short[message_len] = 0;
 }
 
 int git_commit_add_parent(git_commit *commit, git_commit *new_parent)