git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/4] commit: create get_commit_tree() method

From
Derrick Stolee <dstolee@microsoft.com>
Date
Apr 6, 2018, 19:09 UTC
Message-ID
<20180406190919.167092-3-dstolee@microsoft.com>
In-Reply-To
<20180406190919.167092-1-dstolee@microsoft.com>

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>
---
 commit.c | 10 ++++++++++
 commit.h |  3 +++
 2 files changed, 13 insertions(+)
diff --git a/commit.c b/commit.c
index fbc092808c..aea2ca1f8b 100644
--- a/commit.c
+++ b/commit.c
@@ -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);
diff --git a/commit.h b/commit.h
index c4d6e6e064..dc4bf97d9f 100644
--- a/commit.h
+++ b/commit.h
@@ -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.
-- 
2.17.0
Previous: Derrick StoleeNext: Derrick Stolee
Message 14 of 26 in “Lazy-load trees when reading commit-graph”
  1. 0/3 Lazy-load trees when reading commit-graphDerrick Stolee, Apr 3, 2018
  2. 1/3 commit: create get_commit_tree() methodDerrick Stolee, Apr 3, 2018
  3. 3/3 commit-graph: lazy-load treesDerrick Stolee, Apr 3, 2018
  4. Stefan BellerApr 3, 2018
  5. Derrick StoleeApr 3, 2018
  6. Stefan BellerApr 3, 2018
  7. 2/3 treewide: use get_commit_tree() for tree accessDerrick Stolee, Apr 3, 2018
  8. Derrick StoleeApr 3, 2018
  9. Jeff KingApr 3, 2018
  10. Derrick StoleeApr 3, 2018
  11. Jeff KingApr 3, 2018
  12. Derrick StoleeApr 4, 2018
  13. 0/4 Lazy-load trees when reading commit-graphDerrick Stolee, Apr 6, 2018
  14. 2/4 commit: create get_commit_tree() methodDerrick Stolee, Apr 6, 2018
  15. 1/4 treewide: rename tree to maybe_treeDerrick Stolee, Apr 6, 2018
  16. 3/4 treewide: replace maybe_tree with accessor methodsDerrick Stolee, Apr 6, 2018
  17. 4/4 commit-graph: lazy-load trees for commitsDerrick Stolee, Apr 6, 2018
  18. Jeff KingApr 6, 2018
  19. Derrick StoleeApr 6, 2018
  20. Stefan BellerApr 6, 2018
  21. Junio C HamanoApr 8, 2018
  22. Derrick StoleeApr 9, 2018
  23. Stefan BellerApr 9, 2018
  24. Jakub NarebskiApr 7, 2018
  25. Derrick StoleeApr 8, 2018
  26. Jakub NarebskiApr 11, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.