summaryrefslogtreecommitdiff
path: root/commit.c
diff options
context:
space:
mode:
Diffstat (limited to 'commit.c')
-rw-r--r--commit.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/commit.c b/commit.c
index fc8b4e287d..b6b0e0d6fb 100644
--- a/commit.c
+++ b/commit.c
@@ -250,6 +250,34 @@ void set_commit_buffer(struct commit *commit, void *buffer)
commit->buffer = buffer;
}
+const void *get_cached_commit_buffer(const struct commit *commit)
+{
+ return commit->buffer;
+}
+
+const void *get_commit_buffer(const struct commit *commit)
+{
+ const void *ret = get_cached_commit_buffer(commit);
+ if (!ret) {
+ enum object_type type;
+ unsigned long size;
+ ret = read_sha1_file(commit->object.sha1, &type, &size);
+ if (!ret)
+ die("cannot read commit object %s",
+ sha1_to_hex(commit->object.sha1));
+ if (type != OBJ_COMMIT)
+ die("expected commit for %s, got %s",
+ sha1_to_hex(commit->object.sha1), typename(type));
+ }
+ return ret;
+}
+
+void unuse_commit_buffer(const struct commit *commit, const void *buffer)
+{
+ if (commit->buffer != buffer)
+ free((void *)buffer);
+}
+
void free_commit_buffer(struct commit *commit)
{
free(commit->buffer);