Skip to content

Commit 5bb03de

Browse files
derrickstoleegitster
authored andcommitted
commit: create get_commit_tree() method
While walking the commit graph, we load struct commit objects into the object cache. During this process, we also load struct tree objects for the root tree of each of these commits. We load these objects even if we are only computing commit reachability information, such as a merge base or ahead/behind information. Create get_commit_tree() as a first step to removing direct references to the 'maybe_tree' member of struct commit. Create get_commit_tree_oid() as a shortcut for several references to "&commit->maybe_tree->object.oid" in the codebase. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 891435d commit 5bb03de

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

commit.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,16 @@ void free_commit_buffer(struct commit *commit)
296296
}
297297
}
298298

299+
struct tree *get_commit_tree(const struct commit *commit)
300+
{
301+
return commit->maybe_tree;
302+
}
303+
304+
struct object_id *get_commit_tree_oid(const struct commit *commit)
305+
{
306+
return &get_commit_tree(commit)->object.oid;
307+
}
308+
299309
const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep)
300310
{
301311
struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);

commit.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ void unuse_commit_buffer(const struct commit *, const void *buffer);
102102
*/
103103
void free_commit_buffer(struct commit *);
104104

105+
struct tree *get_commit_tree(const struct commit *);
106+
struct object_id *get_commit_tree_oid(const struct commit *);
107+
105108
/*
106109
* Disassociate any cached object buffer from the commit, but do not free it.
107110
* The buffer (or NULL, if none) is returned.

0 commit comments

Comments
 (0)