summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6b3c4c0)
raw | patch | inline | side by side (parent: 6b3c4c0)
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | |
Thu, 15 Dec 2011 13:47:22 +0000 (20:47 +0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Thu, 15 Dec 2011 18:46:42 +0000 (10:46 -0800) |
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 <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
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 <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/commit-tree.c | patch | blob | history | |
builtin/commit.c | patch | blob | history | |
builtin/merge.c | patch | blob | history | |
builtin/notes.c | patch | blob | history | |
commit.c | patch | blob | history | |
commit.h | patch | blob | history | |
notes-cache.c | patch | blob | history | |
notes-merge.c | patch | blob | history | |
notes-merge.h | patch | blob | history |
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index d083795e26e7893c6b7d466f9bcf2be1311cfeb2..0895861457a2c90a0ddff9ab0864ef258e91cce5 100644 (file)
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
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 8f2bebecf313a0e4b742f9327ec178c7e3547dd2..849151e9517818203b9d7ba4368c87d26dd61ebf 100644 (file)
--- a/builtin/commit.c
+++ b/builtin/commit.c
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 27576c0f7fa3bf370437f3ba1cd4e7ff36fadfdb..e066bf1b0bbaca7820d32276e9c3c522ee23c991 100644 (file)
--- a/builtin/merge.c
+++ b/builtin/merge.c
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();
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 f8e437db0156043f1586e66adf343e34ef6cf4dc..5e32548cdd89fa6a45f731dc9cae1bfca4955a0e 100644 (file)
--- a/builtin/notes.c
+++ b/builtin/notes.c
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);
diff --git a/commit.c b/commit.c
index 73b7e00292ba2de33fa43b5f028fd807a460af34..0a214a649e1b3d5011e14a3dc227753f2bd2be05 100644 (file)
--- a/commit.c
+++ b/commit.c
"You may want to amend it after fixing the message, or set the config\n"
"variable i18n.commitencoding to the encoding your project uses.\n";
-int commit_tree(const char *msg, unsigned char *tree,
+int commit_tree(const struct strbuf *msg, unsigned char *tree,
struct commit_list *parents, unsigned char *ret,
const char *author)
{
strbuf_addch(&buffer, '\n');
/* And add the comment */
- strbuf_addstr(&buffer, msg);
+ strbuf_addbuf(&buffer, msg);
/* And check the encoding */
if (encoding_is_utf8 && !is_utf8(buffer.buf))
diff --git a/commit.h b/commit.h
index 009b113e5bb5d04bdfb116897cc17dc5f5a2fa9c..5cf46b2e0a5485757a23c86ed38b4d2de6c1342a 100644 (file)
--- a/commit.h
+++ b/commit.h
struct commit_list *reduce_heads(struct commit_list *heads);
-extern int commit_tree(const char *msg, unsigned char *tree,
+extern int commit_tree(const struct strbuf *msg, unsigned char *tree,
struct commit_list *parents, unsigned char *ret,
const char *author);
diff --git a/notes-cache.c b/notes-cache.c
index 4c8984ede1e218d3e0aaadb6d8c72bfcafddeee9..bea013eeae70f360e12af01345058b1b217848c4 100644 (file)
--- a/notes-cache.c
+++ b/notes-cache.c
{
unsigned char tree_sha1[20];
unsigned char commit_sha1[20];
+ struct strbuf msg = STRBUF_INIT;
if (!c || !c->tree.initialized || !c->tree.ref || !*c->tree.ref)
return -1;
if (write_notes_tree(&c->tree, tree_sha1))
return -1;
- if (commit_tree(c->validity, tree_sha1, NULL, commit_sha1, NULL) < 0)
+ strbuf_attach(&msg, c->validity,
+ strlen(c->validity), strlen(c->validity) + 1);
+ if (commit_tree(&msg, tree_sha1, NULL, commit_sha1, NULL) < 0)
return -1;
if (update_ref("update notes cache", c->tree.ref, commit_sha1, NULL,
0, QUIET_ON_ERR) < 0)
diff --git a/notes-merge.c b/notes-merge.c
index ce10aacf2978024eda0234482964577e9235f2d2..b5a36ac1587f00c21001840c5bc001b011aed554 100644 (file)
--- a/notes-merge.c
+++ b/notes-merge.c
}
void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
- const char *msg, unsigned char *result_sha1)
+ const struct strbuf *msg, unsigned char *result_sha1)
{
unsigned char tree_sha1[20];
struct commit_list *parents = NULL;
commit_list_insert(remote, &parents); /* LIFO order */
commit_list_insert(local, &parents);
- create_notes_commit(local_tree, parents, o->commit_msg.buf,
+ create_notes_commit(local_tree, parents, &o->commit_msg,
result_sha1);
}
struct dir_struct dir;
char *path = xstrdup(git_path(NOTES_MERGE_WORKTREE "/"));
int path_len = strlen(path), i;
- const char *msg = strstr(partial_commit->buffer, "\n\n");
+ char *msg = strstr(partial_commit->buffer, "\n\n");
+ struct strbuf sb_msg = STRBUF_INIT;
if (o->verbosity >= 3)
printf("Committing notes in notes merge worktree at %.*s\n",
sha1_to_hex(obj_sha1), sha1_to_hex(blob_sha1));
}
- create_notes_commit(partial_tree, partial_commit->parents, msg,
+ strbuf_attach(&sb_msg, msg, strlen(msg), strlen(msg) + 1);
+ create_notes_commit(partial_tree, partial_commit->parents, &sb_msg,
result_sha1);
if (o->verbosity >= 4)
printf("Finalized notes merge commit: %s\n",
diff --git a/notes-merge.h b/notes-merge.h
index 168a6724cd873602e3da1ff3b7e2cc67a5b240ae..0c11b173a1e38ddeb702e022ebdd571ed2ad12f3 100644 (file)
--- a/notes-merge.h
+++ b/notes-merge.h
* The resulting commit SHA1 is stored in result_sha1.
*/
void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
- const char *msg, unsigned char *result_sha1);
+ const struct strbuf *msg, unsigned char *result_sha1);
/*
* Merge notes from o->remote_ref into o->local_ref