provide a helper to set the commit buffer

Right now this is just a one-liner, but abstracting it will make it easier to change later. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jun 10, 2014 at 17:40 UTC 66c2827ea4deb24ff541e30a5b6239ad5e9f6801
4 files changed +14 -3
builtin/blame.c
+1 -1
@@ -2046,7 +2046,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
2046 ident, ident, path,
2047 (!contents_from ? path :
2048 (!strcmp(contents_from, "-") ? "standard input" : contents_from)));
2049 - commit->buffer = strbuf_detach(&msg, NULL);
2049 + set_commit_buffer(commit, strbuf_detach(&msg, NULL));
2050
2051 if (!contents_from || strcmp("-", contents_from)) {
2052 struct stat st;
commit.c
+6 -1
@@ -245,6 +245,11 @@ int unregister_shallow(const unsigned char *sha1)
245 return 0;
246 }
247
248 +void set_commit_buffer(struct commit *commit, void *buffer)
249 +{
250 + commit->buffer = buffer;
251 +}
252 +
253 void free_commit_buffer(struct commit *commit)
254 {
255 free(commit->buffer);
@@ -335,7 +340,7 @@ int parse_commit(struct commit *item)
340 }
341 ret = parse_commit_buffer(item, buffer, size);
342 if (save_commit_buffer && !ret) {
338 - item->buffer = buffer;
343 + set_commit_buffer(item, buffer);
344 return 0;
345 }
346 free(buffer);
commit.h
+6
@@ -51,6 +51,12 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
51 int parse_commit(struct commit *item);
52 void parse_commit_or_die(struct commit *item);
53
54 +/*
55 + * Associate an object buffer with the commit. The ownership of the
56 + * memory is handed over to the commit, and must be free()-able.
57 + */
58 +void set_commit_buffer(struct commit *, void *buffer);
59 +
60 /*
61 * Free any cached object buffer associated with the commit.
62 */
object.c
+1 -1
@@ -198,7 +198,7 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
198 if (parse_commit_buffer(commit, buffer, size))
199 return NULL;
200 if (!commit->buffer) {
201 - commit->buffer = buffer;
201 + set_commit_buffer(commit, buffer);
202 *eaten_p = 1;
203 }
204 obj = &commit->object;