ident, ident, path,
                    (!contents_from ? path :
                     (!strcmp(contents_from, "-") ? "standard input" : contents_from)));
-       commit->buffer = strbuf_detach(&msg, NULL);
+       set_commit_buffer(commit, strbuf_detach(&msg, NULL));
 
        if (!contents_from || strcmp("-", contents_from)) {
                struct stat st;
 
        return 0;
 }
 
+void set_commit_buffer(struct commit *commit, void *buffer)
+{
+       commit->buffer = buffer;
+}
+
 void free_commit_buffer(struct commit *commit)
 {
        free(commit->buffer);
        }
        ret = parse_commit_buffer(item, buffer, size);
        if (save_commit_buffer && !ret) {
-               item->buffer = buffer;
+               set_commit_buffer(item, buffer);
                return 0;
        }
        free(buffer);
 
 int parse_commit(struct commit *item);
 void parse_commit_or_die(struct commit *item);
 
+/*
+ * Associate an object buffer with the commit. The ownership of the
+ * memory is handed over to the commit, and must be free()-able.
+ */
+void set_commit_buffer(struct commit *, void *buffer);
+
 /*
  * Free any cached object buffer associated with the commit.
  */
 
                        if (parse_commit_buffer(commit, buffer, size))
                                return NULL;
                        if (!commit->buffer) {
-                               commit->buffer = buffer;
+                               set_commit_buffer(commit, buffer);
                                *eaten_p = 1;
                        }
                        obj = &commit->object;