diff options
| author | lhchavez <lhchavez@lhchavez.com> | 2021-03-10 07:06:15 -0800 |
|---|---|---|
| committer | lhchavez <lhchavez@lhchavez.com> | 2021-03-10 07:09:47 -0800 |
| commit | 25b75cd9bc01896a2b74c748ceef7110ea1b165f (patch) | |
| tree | 7f0adda00ff69e2a597dbcb0118ab737e47ec0fe /include/git2 | |
| parent | 248606ebb0906076367fcfce9574f522f818c26f (diff) | |
| download | libgit2-25b75cd9bc01896a2b74c748ceef7110ea1b165f.tar.gz | |
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.
Diffstat (limited to 'include/git2')
| -rw-r--r-- | include/git2/odb.h | 15 | ||||
| -rw-r--r-- | include/git2/sys/commit_graph.h | 45 | ||||
| -rw-r--r-- | include/git2/types.h | 3 |
3 files changed, 63 insertions, 0 deletions
diff --git a/include/git2/odb.h b/include/git2/odb.h index c4bfa5290..dd481e950 100644 --- a/include/git2/odb.h +++ b/include/git2/odb.h @@ -544,6 +544,21 @@ GIT_EXTERN(size_t) git_odb_num_backends(git_odb *odb); */ GIT_EXTERN(int) git_odb_get_backend(git_odb_backend **out, git_odb *odb, size_t pos); +/** + * Set the git commit-graph for the ODB. + * + * After a successfull call, the ownership of the cgraph parameter will be + * transferred to libgit2, and the caller should not free it. + * + * The commit-graph can also be unset by explicitly passing NULL as the cgraph + * parameter. + * + * @param odb object database + * @param cgraph the git commit-graph + * @return 0 on success; error code otherwise + */ +GIT_EXTERN(int) git_odb_set_commit_graph(git_odb *odb, git_commit_graph *cgraph); + /** @} */ GIT_END_DECL #endif diff --git a/include/git2/sys/commit_graph.h b/include/git2/sys/commit_graph.h new file mode 100644 index 000000000..038c9b739 --- /dev/null +++ b/include/git2/sys/commit_graph.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) the libgit2 contributors. All rights reserved. + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ +#ifndef INCLUDE_sys_git_commit_graph_h__ +#define INCLUDE_sys_git_commit_graph_h__ + +#include "git2/common.h" +#include "git2/types.h" + +/** + * @file git2/sys/commit_graph.h + * @brief Git commit-graph + * @defgroup git_commit_graph Git commit-graph APIs + * @ingroup Git + * @{ + */ +GIT_BEGIN_DECL + +/** + * Opens a `git_commit_graph` from a path to an objects directory. + * + * This finds, opens, and validates the `commit-graph` file. + * + * @param cgraph_out the `git_commit_graph` struct to initialize. + * @param objects_dir the path to a git objects directory. + * @return Zero on success; -1 on failure. + */ +GIT_EXTERN(int) git_commit_graph_open(git_commit_graph **cgraph_out, const char *objects_dir); + +/** + * Frees commit-graph data. This should only be called when memory allocated + * using `git_commit_graph_open` is not returned to libgit2 because it was not + * associated with the ODB through a successful call to + * `git_odb_set_commit_graph`. + * + * @param cgraph the commit-graph object to free. If NULL, no action is taken. + */ +GIT_EXTERN(void) git_commit_graph_free(git_commit_graph *cgraph); + +GIT_END_DECL + +#endif diff --git a/include/git2/types.h b/include/git2/types.h index ade0c7d32..562eb8e5f 100644 --- a/include/git2/types.h +++ b/include/git2/types.h @@ -102,6 +102,9 @@ typedef struct git_refdb git_refdb; /** A custom backend for refs */ typedef struct git_refdb_backend git_refdb_backend; +/** A git commit-graph */ +typedef struct git_commit_graph git_commit_graph; + /** * Representation of an existing git repository, * including all its object contents |
