summaryrefslogtreecommitdiff
path: root/commit.c
diff options
context:
space:
mode:
Diffstat (limited to 'commit.c')
-rw-r--r--commit.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/commit.c b/commit.c
index a5333c7ac6..8fa1883c61 100644
--- a/commit.c
+++ b/commit.c
@@ -340,15 +340,21 @@ void free_commit_buffer(struct parsed_object_pool *pool, struct commit *commit)
}
}
-struct tree *get_commit_tree(const struct commit *commit)
+static inline void set_commit_tree(struct commit *c, struct tree *t)
+{
+ c->maybe_tree = t;
+}
+
+struct tree *repo_get_commit_tree(struct repository *r,
+ const struct commit *commit)
{
if (commit->maybe_tree || !commit->object.parsed)
return commit->maybe_tree;
- if (commit->graph_pos == COMMIT_NOT_FROM_GRAPH)
- BUG("commit has NULL tree, but was not loaded from commit-graph");
+ if (commit->graph_pos != COMMIT_NOT_FROM_GRAPH)
+ return get_commit_tree_in_graph(r, commit);
- return get_commit_tree_in_graph(the_repository, commit);
+ return NULL;
}
struct object_id *get_commit_tree_oid(const struct commit *commit)
@@ -358,7 +364,7 @@ struct object_id *get_commit_tree_oid(const struct commit *commit)
void release_commit_memory(struct parsed_object_pool *pool, struct commit *c)
{
- c->maybe_tree = NULL;
+ set_commit_tree(c, NULL);
c->index = 0;
free_commit_buffer(pool, c);
free_commit_list(c->parents);
@@ -406,7 +412,7 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b
if (get_oid_hex(bufptr + 5, &parent) < 0)
return error("bad tree pointer in commit %s",
oid_to_hex(&item->object.oid));
- item->maybe_tree = lookup_tree(r, &parent);
+ set_commit_tree(item, lookup_tree(r, &parent));
bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
pptr = &item->parents;