8000 SHA256 improvements by ethomson · Pull Request #6965 · libgit2/libgit2 · GitHub
[go: up one dir, main page]

Skip to content

SHA256 improvements #6965

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 9 commits into from
Dec 18, 2024
2 changes: 1 addition & 1 deletion examples/index-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int lg2_index_pack(git_repository *repo, int argc, char **argv)
}

#ifdef GIT_EXPERIMENTAL_SHA256
error = git_indexer_new(&idx, ".", git_repository_oid_type(repo), NULL);
error = git_indexer_new(&idx, ".", NULL);
#else
error = git_indexer_new(&idx, ".", 0, NULL, NULL);
#endif
Expand Down
2 changes: 1 addition & 1 deletion examples/show-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ int lg2_show_index(git_repository *repo, int argc, char **argv)
dirlen = strlen(dir);
if (dirlen > 5 && strcmp(dir + dirlen - 5, "index") == 0) {
#ifdef GIT_EXPERIMENTAL_SHA256
check_lg2(git_index_open(&index, dir, GIT_OID_SHA1), "could not open index", dir);
check_lg2(git_index_open(&index, dir, NULL), "could not open index", dir);
#else
check_lg2(git_index_open(&index, dir), "could not open index", dir);
#endif
Expand Down
2 changes: 1 addition & 1 deletion fuzzers/packfile_fuzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
}

#ifdef GIT_EXPERIMENTAL_SHA256
error = git_indexer_new(&indexer, ".", GIT_OID_SHA1, NULL);
error = git_indexer_new(&indexer, ".", NULL);
#else
error = git_indexer_new(&indexer, ".", 0, odb, NULL);
#endif
Expand Down
52 changes: 48 additions & 4 deletions include/git2/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,25 +191,69 @@ typedef enum {

#ifdef GIT_EXPERIMENTAL_SHA256

/**
* The options for opening or creating an index.
*
* Initialize with `GIT_INDEX_OPTIONS_INIT`. Alternatively, you can
* use `git_index_options_init`.
*
* @options[version] GIT_INDEX_OPTIONS_VERSION
* @options[init_macro] GIT_INDEX_OPTIONS_INIT
* @options[init_function] git_index_options_init
*/
typedef struct git_index_options {
unsigned int version; /**< The version */

/**
* The object ID type for the object IDs that exist in the index.
*
* If this is not specified, this defaults to `GIT_OID_SHA1`.
*/
git_oid_t oid_type;
} git_index_options;

/** Current version for the `git_index_options` structure */
#define GIT_INDEX_OPTIONS_VERSION 1

/** Static constructor for `git_index_options` */
#define GIT_INDEX_OPTIONS_INIT { GIT_INDEX_OPTIONS_VERSION }

/**
* Initialize git_index_options structure
*
* Initializes a `git_index_options` with default values. Equivalent to creating
* an instance with GIT_INDEX_OPTIONS_INIT.
*
* @param opts The `git_index_options` struct to initialize.
* @param version The struct version; pass `GIT_INDEX_OPTIONS_VERSION`.
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_index_options_init(
git_index_options *opts,
unsigned int version);

/**
* Creates a new bare Git index object, without a repository to back
* it. This index object is capable of storing SHA256 objects.
*
* @param index_out the pointer for the new index
* @param index_path the path to the index file in disk
* @param oid_type the object ID type to use for the repository
* @param opts the options for opening the index, or NULL
* @return 0 or an error code
*/
GIT_EXTERN(int) git_index_open(git_index **index_out, const char *index_path, git_oid_t oid_type);
GIT_EXTERN(int) git_index_open(
git_index **index_out,
const char *index_path,
const git_index_options *opts);

/**
* Create an in-memory index object.
*
* @param index_out the pointer for the new index
* @param oid_type the object ID type to use for the repository
* @param opts the options for opening the index, or NULL
* @return 0 or an error code
*/
GIT_EXTERN(int) git_index_new(git_index **index_out, git_oid_t oid_type);
GIT_EXTERN(int) git_index_new(git_index **index_out, const git_index_options *opts);

#else

Expand Down
6 changes: 4 additions & 2 deletions include/git2/indexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ typedef struct git_indexer_options {
/** permissions to use creating packfile or 0 for defaults */
unsigned int mode;

/** the type of object ids in the packfile or 0 for SHA1 */
git_oid_t oid_type;

/**
* object database from which to read base objects when
* fixing thin packs. This can be NULL if there are no thin
Expand Down Expand Up @@ -120,13 +123,12 @@ GIT_EXTERN(int) git_indexer_options_init(
*
* @param out where to store the indexer instance
* @param path to the directory where the packfile should be stored
* @param oid_type the oid type to use for objects
* @param opts the options to create the indexer with
* @return 0 or an error code.
*/
GIT_EXTERN(int) git_indexer_new(
git_indexer **out,
const char *path,
git_oid_t oid_type,
git_indexer_options *opts);
#else
/**
Expand Down
12 changes: 1 addition & 11 deletions include/git2/repository.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "common.h"
#include "types.h"
#include "oid.h"
#include "odb.h"
#include "buffer.h"
#include "commit.h"

Expand Down Expand Up @@ -52,15 +53,6 @@ GIT_EXTERN(int) git_repository_open(git_repository **out, const char *path);
*/
GIT_EXTERN(int) git_repository_open_from_worktree(git_repository **out, git_worktree *wt);

#ifdef GIT_EXPERIMENTAL_SHA256

GIT_EXTERN(int) git_repository_wrap_odb(
git_repository **out,
git_odb *odb,
git_oid_t oid_type);

#else

/**
* Create a "fake" repository to wrap an object database
*
Expand All @@ -76,8 +68,6 @@ GIT_EXTERN(int) git_repository_wrap_odb(
git_repository **out,
git_odb *odb);

#endif

/**
* Look for a git repository and copy its path in the given buffer.
* The lookup start from base_path and walk across parent directories
Expand Down
157 changes: 97 additions & 60 deletions include/git2/sys/commit_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,45 @@
*/
GIT_BEGIN_DECL

/**
* Options structure for `git_commit_graph_open_new`.
*
* Initialize with `GIT_COMMIT_GRAPH_OPEN_OPTIONS_INIT`. Alternatively,
* you can use `git_commit_graph_open_options_init`.
*/
typedef struct {
unsigned int version;

#ifdef GIT_EXPERIMENTAL_SHA256
/** The object ID type that this commit graph contains. */
git_oid_t oid_type;
#endif
} git_commit_graph_open_options;

/** Current version for the `git_commit_graph_open_options` structure */
#define GIT_COMMIT_GRAPH_OPEN_OPTIONS_VERSION 1

/** Static constructor for `git_commit_graph_open_options` */
#define GIT_COMMIT_GRAPH_OPEN_OPTIONS_INIT { \
GIT_COMMIT_GRAPH_OPEN_OPTIONS_VERSION \
}

/**
* Initialize git_commit_graph_open_options structure
*
* Initializes a `git_commit_graph_open_options` with default values.
* Equivalent to creating an instance with
* `GIT_COMMIT_GRAPH_OPEN_OPTIONS_INIT`.
*
* @param opts The `git_commit_graph_open_options` struct to initialize.
* @param version The struct version; pass `GIT_COMMIT_GRAPH_OPEN_OPTIONS_VERSION`.
* @return Zero on success; -1 on failure.
*/
GIT_EXTERN(int) git_commit_graph_open_options_init(
git_commit_graph_open_options *opts,
unsigned int version);


/**
* Opens a `git_commit_graph` from a path to an objects directory.
*
Expand All @@ -32,7 +71,7 @@ GIT_EXTERN(int) git_commit_graph_open(
git_commit_graph **cgraph_out,
const char *objects_dir
#ifdef GIT_EXPERIMENTAL_SHA256
, git_oid_t oid_type
, const git_commit_graph_open_options *options
#endif
);

Expand All @@ -46,54 +85,6 @@ GIT_EXTERN(int) git_commit_graph_open(
*/
GIT_EXTERN(void) git_commit_graph_free(git_commit_graph *cgraph);

/**
* Create a new writer for `commit-graph` files.
*
* @param out Location to store the writer pointer.
* @param objects_info_dir The `objects/info` directory.
* The `commit-graph` file will be written in this directory.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_commit_graph_writer_new(
git_commit_graph_writer **out,
const char *objects_info_dir
#ifdef GIT_EXPERIMENTAL_SHA256
, git_oid_t oid_type
#endif
);

/**
* Free the commit-graph writer and its resources.
*
* @param w The writer to free. If NULL no action is taken.
*/
GIT_EXTERN(void) git_commit_graph_writer_free(git_commit_graph_writer *w);

/**
* Add an `.idx` file (associated to a packfile) to the writer.
*
* @param w The writer.
* @param repo The repository that owns the `.idx` file.
* @param idx_path The path of an `.idx` file.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_commit_graph_writer_add_index_file(
git_commit_graph_writer *w,
git_repository *repo,
const char *idx_path);

/**
* Add a revwalk to the writer. This will add all the commits from the revwalk
* to the commit-graph.
*
* @param w The writer.
* @param walk The git_revwalk.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_commit_graph_writer_add_revwalk(
git_commit_graph_writer *w,
git_revwalk *walk);


/**
* The strategy to use when adding a new set of commits to a pre-existing
Expand All @@ -108,15 +99,19 @@ typedef enum {
} git_commit_graph_split_strategy_t;

/**
* Options structure for
* `git_commit_graph_writer_commit`/`git_commit_graph_writer_dump`.
* Options structure for `git_commit_graph_writer_new`.
*
* Initialize with `GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT`. Alternatively, you
* can use `git_commit_graph_writer_options_init`.
* Initialize with `GIT_COMMIT_GRAPH_WRITER_OPTIONS_INIT`. Alternatively,
* you can use `git_commit_graph_writer_options_init`.
*/
typedef struct {
unsigned int version;

#ifdef GIT_EXPERIMENTAL_SHA256
/** The object ID type that this commit graph contains. */
git_oid_t oid_type;
#endif

/**
* The strategy to use when adding new commits to a pre-existing commit-graph
* chain.
Expand Down Expand Up @@ -158,29 +153,71 @@ GIT_EXTERN(int) git_commit_graph_writer_options_init(
git_commit_graph_writer_options *opts,
unsigned int version);

/**
* Create a new writer for `commit-graph` files.
*
* @param out Location to store the writer pointer.
* @param objects_info_dir The `objects/info` directory.
* The `commit-graph` file will be written in this directory.
* @param options The options for the commit graph writer.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_commit_graph_writer_new(
git_commit_graph_writer **out,
const char *objects_info_dir,
const git_commit_graph_writer_options *options);

/**
* Free the commit-graph writer and its resources.
*
* @param w The writer to free. If NULL no action is taken.
*/
GIT_EXTERN(void) git_commit_graph_writer_free(git_commit_graph_writer *w);

/**
* Add an `.idx` file (associated to a packfile) to the writer.
*
* @param w The writer.
* @param repo The repository that owns the `.idx` file.
* @param idx_path The path of an `.idx` file.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_commit_graph_writer_add_index_file(
git_commit_graph_writer *w,
git_repository *repo,
const char *idx_path);

/**
* Add a revwalk to the writer. This will add all the commits from the revwalk
* to the commit-graph.
*
* @param w The writer.
* @param walk The git_revwalk.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_commit_graph_writer_add_revwalk(
git_commit_graph_writer *w,
git_revwalk *walk);

/**
* Write a `commit-graph` file to a file.
*
* @param w The writer
* @param opts Pointer to git_commit_graph_writer_options struct.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_commit_graph_writer_commit(
git_commit_graph_writer *w,
git_commit_graph_writer_options *opts);
git_commit_graph_writer *w);

/**
* Dump the contents of the `commit-graph` to an in-memory buffer.
*
* @param buffer Buffer where to store the contents of the `commit-graph`.
* @param[out] buffer Buffer where to store the contents of the `commit-graph`.
* @param w The writer.
* @param opts Pointer to git_commit_graph_writer_options struct.
* @return 0 or an error code
*/
GIT_EXTERN(int) git_commit_graph_writer_dump(
git_buf *buffer,
git_commit_graph_writer *w,
git_commit_graph_writer_options *opts);
git_commit_graph_writer *w);

/** @} */
GIT_END_DECL
Expand Down
Loading
Loading
0