commit-graph: Create git_commit_graph as an abstraction for the file

This change does a medium-size refactor of the git_commit_graph_file and
the interaction with the ODB. Now instead of the ODB owning a direct
reference to the git_commit_graph_file, there will be an intermediate
git_commit_graph. The main advantage of that is that now end users can
explicitly set a git_commit_graph that is eagerly checked for errors,
while still being able to lazily use the commit-graph in a regular ODB,
if the file is present.
This commit is contained in:
lhchavez
2021-03-10 07:06:15 -08:00
parent 248606ebb0
commit 25b75cd9bc
10 changed files with 332 additions and 181 deletions

View File

@@ -31,7 +31,7 @@ int LLVMFuzzerInitialize(int *argc, char ***argv)
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
git_commit_graph_file cgraph = {{0}};
git_commit_graph_file file = {{0}};
git_commit_graph_entry e;
git_buf commit_graph_buf = GIT_BUF_INIT;
git_oid oid = {{0}};
@@ -62,19 +62,19 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
git_buf_attach_notowned(&commit_graph_buf, (char *)data, size);
}
if (git_commit_graph_parse(
&cgraph,
if (git_commit_graph_file_parse(
&file,
(const unsigned char *)git_buf_cstr(&commit_graph_buf),
git_buf_len(&commit_graph_buf))
< 0)
goto cleanup;
/* Search for any oid, just to exercise that codepath. */
if (git_commit_graph_entry_find(&e, &cgraph, &oid, GIT_OID_HEXSZ) < 0)
if (git_commit_graph_entry_find(&e, &file, &oid, GIT_OID_HEXSZ) < 0)
goto cleanup;
cleanup:
git_commit_graph_close(&cgraph);
git_commit_graph_file_close(&file);
git_buf_dispose(&commit_graph_buf);
return 0;
}