From 13f8b72d8c8e24215a3dd7771592b30083f1c740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 15 Dec 2011 20:47:22 +0700 Subject: Convert commit_tree() to take strbuf as message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There wan't a way for commit_tree() to notice if the message the caller prepared contained a NUL byte, as it did not take the length of the message as a parameter. Use a pointer to a strbuf instead, so that we can either choose to allow low-level plumbing commands to make commits that contain NUL byte in its message, or forbid NUL everywhere by adding the check in commit_tree(), in later patches. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/commit-tree.c | 2 +- builtin/commit.c | 2 +- builtin/merge.c | 4 ++-- builtin/notes.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'builtin') diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c index d083795e26..0895861457 100644 --- a/builtin/commit-tree.c +++ b/builtin/commit-tree.c @@ -56,7 +56,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix) if (strbuf_read(&buffer, 0, 0) < 0) die_errno("git commit-tree: failed to read"); - if (commit_tree(buffer.buf, tree_sha1, parents, commit_sha1, NULL)) { + if (commit_tree(&buffer, tree_sha1, parents, commit_sha1, NULL)) { strbuf_release(&buffer); return 1; } diff --git a/builtin/commit.c b/builtin/commit.c index 8f2bebecf3..849151e951 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1483,7 +1483,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) exit(1); } - if (commit_tree(sb.buf, active_cache_tree->sha1, parents, sha1, + if (commit_tree(&sb, active_cache_tree->sha1, parents, sha1, author_ident.buf)) { rollback_index_files(); die(_("failed to write commit object")); diff --git a/builtin/merge.c b/builtin/merge.c index 27576c0f7f..e066bf1b0b 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -913,7 +913,7 @@ static int merge_trivial(struct commit *head) parent->next->item = remoteheads->item; parent->next->next = NULL; prepare_to_commit(); - if (commit_tree(merge_msg.buf, result_tree, parent, result_commit, NULL)) + if (commit_tree(&merge_msg, result_tree, parent, result_commit, NULL)) die(_("failed to write commit object")); finish(head, result_commit, "In-index merge"); drop_save(); @@ -945,7 +945,7 @@ static int finish_automerge(struct commit *head, strbuf_addch(&merge_msg, '\n'); prepare_to_commit(); free_commit_list(remoteheads); - if (commit_tree(merge_msg.buf, result_tree, parents, result_commit, NULL)) + if (commit_tree(&merge_msg, result_tree, parents, result_commit, NULL)) die(_("failed to write commit object")); strbuf_addf(&buf, "Merge made by the '%s' strategy.", wt_strategy); finish(head, result_commit, buf.buf); diff --git a/builtin/notes.c b/builtin/notes.c index f8e437db01..5e32548cdd 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -301,12 +301,12 @@ void commit_notes(struct notes_tree *t, const char *msg) return; /* don't have to commit an unchanged tree */ /* Prepare commit message and reflog message */ - strbuf_addstr(&buf, "notes: "); /* commit message starts at index 7 */ strbuf_addstr(&buf, msg); if (buf.buf[buf.len - 1] != '\n') strbuf_addch(&buf, '\n'); /* Make sure msg ends with newline */ - create_notes_commit(t, NULL, buf.buf + 7, commit_sha1); + create_notes_commit(t, NULL, &buf, commit_sha1); + strbuf_insert(&buf, 0, "notes: ", 7); /* commit message starts at index 7 */ update_ref(buf.buf, t->ref, commit_sha1, NULL, 0, DIE_ON_ERR); strbuf_release(&buf); -- cgit v1.2.1