Thanks to visit codestin.com
Credit goes to github.com

Skip to content

commit-graph: Use the commit-graph in revwalks #5765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions fuzzers/commit_graph_fuzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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}};
Expand Down Expand Up @@ -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;
}
15 changes: 15 additions & 0 deletions include/git2/odb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
45 changes: 45 additions & 0 deletions include/git2/sys/commit_graph.h
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions include/git2/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading