diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2021-07-26 16:27:54 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-26 16:27:54 -0400 |
commit | 2370e4910262f941a3bb0f70ce05ff7a90679fe1 (patch) | |
tree | 1d3b183d7b14ab3bf4a2d3b11ead833ef073a825 /src/commit_list.c | |
parent | 43b5075df4c543fc8801ed4b829702d7f9f2c0ad (diff) | |
parent | 25b75cd9bc01896a2b74c748ceef7110ea1b165f (diff) | |
download | libgit2-2370e4910262f941a3bb0f70ce05ff7a90679fe1.tar.gz |
Merge pull request #5765 from lhchavez/cgraph-revwalks
commit-graph: Use the commit-graph in revwalks
Diffstat (limited to 'src/commit_list.c')
-rw-r--r-- | src/commit_list.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/commit_list.c b/src/commit_list.c index 2e103ec22..11cc2e7d2 100644 --- a/src/commit_list.c +++ b/src/commit_list.c @@ -124,6 +124,7 @@ static int commit_quick_parse( return -1; } + node->generation = 0; node->time = commit->committer->when.time; node->out_degree = (uint16_t) git_array_size(commit->parent_ids); node->parents = alloc_parents(walk, node, node->out_degree); @@ -143,11 +144,38 @@ static int commit_quick_parse( int git_commit_list_parse(git_revwalk *walk, git_commit_list_node *commit) { git_odb_object *obj; + git_commit_graph_file *cgraph_file = NULL; int error; if (commit->parsed) return 0; + /* Let's try to use the commit graph first. */ + git_odb__get_commit_graph_file(&cgraph_file, walk->odb); + if (cgraph_file) { + git_commit_graph_entry e; + + error = git_commit_graph_entry_find(&e, cgraph_file, &commit->oid, GIT_OID_RAWSZ); + if (error == 0 && git__is_uint16(e.parent_count)) { + size_t i; + commit->generation = (uint32_t)e.generation; + commit->time = e.commit_time; + commit->out_degree = (uint16_t)e.parent_count; + commit->parents = alloc_parents(walk, commit, commit->out_degree); + GIT_ERROR_CHECK_ALLOC(commit->parents); + + for (i = 0; i < commit->out_degree; ++i) { + git_commit_graph_entry parent; + error = git_commit_graph_entry_parent(&parent, cgraph_file, &e, i); + if (error < 0) + return error; + commit->parents[i] = git_revwalk__commit_lookup(walk, &parent.sha1); + } + commit->parsed = 1; + return 0; + } + } + if ((error = git_odb_read(&obj, walk->odb, &commit->oid)) < 0) return error; |