Skip to content

Commit

Permalink
commit: create get_commit_tree() method
Browse files Browse the repository at this point in the history
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 <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
derrickstolee authored and gitster committed Apr 11, 2018
1 parent 891435d commit 5bb03de
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions commit.c
Expand Up @@ -296,6 +296,16 @@ void free_commit_buffer(struct commit *commit)
}
}

struct tree *get_commit_tree(const struct commit *commit)
{
return commit->maybe_tree;
}

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);
Expand Down
3 changes: 3 additions & 0 deletions commit.h
Expand Up @@ -102,6 +102,9 @@ void unuse_commit_buffer(const struct commit *, const void *buffer);
*/
void free_commit_buffer(struct commit *);

struct tree *get_commit_tree(const struct commit *);
struct object_id *get_commit_tree_oid(const struct commit *);

/*
* Disassociate any cached object buffer from the commit, but do not free it.
* The buffer (or NULL, if none) is returned.
Expand Down

0 comments on commit 5bb03de

Please sign in to comment.