commit_tree: take a pointer/len pair rather than a const strbuf
While strbufs are pretty common throughout our code, it is more flexible for functions to take a pointer/len pair than a strbuf. It's easy to turn a strbuf into such a pair (by dereferencing its members), but less easy to go the other way (you can strbuf_attach, but that has implications about memory ownership). This patch teaches commit_tree (and its associated callers and sub-functions) to take such a pair for the commit message rather than a strbuf. This makes passing the buffer around slightly more verbose, but means we can get rid of some dangerous strbuf_attach calls in the next patch. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
bce14aa132
commit
3ffefb54c0
@ -852,8 +852,8 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads)
|
||||
parent->next->item = remoteheads->item;
|
||||
parent->next->next = NULL;
|
||||
prepare_to_commit(remoteheads);
|
||||
if (commit_tree(&merge_msg, result_tree, parent, result_commit, NULL,
|
||||
sign_commit))
|
||||
if (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parent,
|
||||
result_commit, NULL, sign_commit))
|
||||
die(_("failed to write commit object"));
|
||||
finish(head, remoteheads, result_commit, "In-index merge");
|
||||
drop_save();
|
||||
@ -877,8 +877,8 @@ static int finish_automerge(struct commit *head,
|
||||
commit_list_insert(head, &parents);
|
||||
strbuf_addch(&merge_msg, '\n');
|
||||
prepare_to_commit(remoteheads);
|
||||
if (commit_tree(&merge_msg, result_tree, parents, result_commit,
|
||||
NULL, sign_commit))
|
||||
if (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parents,
|
||||
result_commit, NULL, sign_commit))
|
||||
die(_("failed to write commit object"));
|
||||
strbuf_addf(&buf, "Merge made by the '%s' strategy.", wt_strategy);
|
||||
finish(head, remoteheads, result_commit, buf.buf);
|
||||
|
||||
Reference in New Issue
Block a user