summaryrefslogtreecommitdiff
path: root/commit.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-05-23 05:38:13 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-05-23 05:38:13 (GMT)
commitc89b6e136e421f1e9108b3c5bc050b19b0243844 (patch)
tree8d81e022f855aad5d29853b56b886d3c6b382c45 /commit.c
parent05682ee270199fdfbc11883458b3639b2b1577df (diff)
parent279ffad17dcc3b72aa7cb5c73fb7aa8eddeed9da (diff)
downloadgit-c89b6e136e421f1e9108b3c5bc050b19b0243844.zip
git-c89b6e136e421f1e9108b3c5bc050b19b0243844.tar.gz
git-c89b6e136e421f1e9108b3c5bc050b19b0243844.tar.bz2
Merge branch 'ds/lazy-load-trees'
The code has been taught to use the duplicated information stored in the commit-graph file to learn the tree object name for a commit to avoid opening and parsing the commit object when it makes sense to do so. * ds/lazy-load-trees: coccinelle: avoid wrong transformation suggestions from commit.cocci commit-graph: lazy-load trees for commits treewide: replace maybe_tree with accessor methods commit: create get_commit_tree() method treewide: rename tree to maybe_tree
Diffstat (limited to 'commit.c')
-rw-r--r--commit.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/commit.c b/commit.c
index 5704911..1d7622b 100644
--- a/commit.c
+++ b/commit.c
@@ -296,6 +296,22 @@ void free_commit_buffer(struct commit *commit)
}
}
+struct tree *get_commit_tree(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");
+
+ return get_commit_tree_in_graph(commit);
+}
+
+struct object_id *get_commit_tree_oid(const struct commit *commit)
+{
+ return &get_commit_tree(commit)->object.oid;
+}
+
const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep)
{
struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
@@ -335,7 +351,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
if (get_sha1_hex(bufptr + 5, parent.hash) < 0)
return error("bad tree pointer in commit %s",
oid_to_hex(&item->object.oid));
- item->tree = lookup_tree(&parent);
+ item->maybe_tree = lookup_tree(&parent);
bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
pptr = &item->parents;