Commit b899fda3 by Edward Thomson

commit graph: support sha256

parent be484d35
......@@ -28,7 +28,13 @@ GIT_BEGIN_DECL
* @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);
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
#endif
);
/**
* Frees commit-graph data. This should only be called when memory allocated
......@@ -50,7 +56,11 @@ GIT_EXTERN(void) git_commit_graph_free(git_commit_graph *cgraph);
*/
GIT_EXTERN(int) git_commit_graph_writer_new(
git_commit_graph_writer **out,
const char *objects_info_dir);
const char *objects_info_dir
#ifdef GIT_EXPERIMENTAL_SHA256
, git_oid_t oid_type
#endif
);
/**
* Free the commit-graph writer and its resources.
......
......@@ -30,6 +30,9 @@
typedef struct git_commit_graph_file {
git_map graph_map;
/* The type of object IDs in the commit graph file. */
git_oid_t oid_type;
/* The OID Fanout table. */
const uint32_t *oid_fanout;
/* The total number of commits in the graph. */
......@@ -84,10 +87,10 @@ typedef struct git_commit_graph_entry {
/* The index within the Extra Edge List of any parent after the first two. */
size_t extra_parents_index;
/* The SHA-1 hash of the root tree of the commit. */
/* The object ID of the root tree of the commit. */
git_oid tree_oid;
/* The SHA-1 hash of the requested commit. */
/* The object ID hash of the requested commit. */
git_oid sha1;
} git_commit_graph_entry;
......@@ -99,18 +102,28 @@ struct git_commit_graph {
/* The underlying commit-graph file. */
git_commit_graph_file *file;
/* The object ID types in the commit graph. */
git_oid_t oid_type;
/* Whether the commit-graph file was already checked for validity. */
bool checked;
};
/** Create a new commit-graph, optionally opening the underlying file. */
int git_commit_graph_new(git_commit_graph **cgraph_out, const char *objects_dir, bool open_file);
int git_commit_graph_new(
git_commit_graph **cgraph_out,
const char *objects_dir,
bool open_file,
git_oid_t oid_type);
/** Validate the checksum of a commit graph */
int git_commit_graph_validate(git_commit_graph *cgraph);
/** Open and validate a commit-graph file. */
int git_commit_graph_file_open(git_commit_graph_file **file_out, const char *path);
int git_commit_graph_file_open(
git_commit_graph_file **file_out,
const char *path,
git_oid_t oid_type);
/*
* Attempt to get the git_commit_graph's commit-graph file. This object is
......@@ -134,6 +147,9 @@ struct git_commit_graph_writer {
*/
git_str objects_info_dir;
/* The object ID type of the commit graph. */
git_oid_t oid_type;
/* The list of packed commits. */
git_vector commits;
};
......
......@@ -748,7 +748,8 @@ int git_odb__add_default_backends(
git_error_set(GIT_ERROR_ODB, "failed to acquire the odb lock");
return -1;
}
if (!db->cgraph && git_commit_graph_new(&db->cgraph, objects_dir, false) < 0) {
if (!db->cgraph &&
git_commit_graph_new(&db->cgraph, objects_dir, false, db->options.oid_type) < 0) {
git_mutex_unlock(&db->lock);
return -1;
}
......
......@@ -16,7 +16,7 @@ void test_graph_commitgraph__parse(void)
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
cl_git_pass(git_str_joinpath(&commit_graph_path, git_repository_path(repo), "objects/info/commit-graph"));
cl_git_pass(git_commit_graph_file_open(&file, git_str_cstr(&commit_graph_path)));
cl_git_pass(git_commit_graph_file_open(&file, git_str_cstr(&commit_graph_path), GIT_OID_SHA1));
cl_assert_equal_i(git_commit_graph_file_needs_refresh(file, git_str_cstr(&commit_graph_path)), 0);
cl_git_pass(git_oid__fromstr(&id, "5001298e0c09ad9c34e4249bc5801c75e9754fa5", GIT_OID_SHA1));
......@@ -60,7 +60,7 @@ void test_graph_commitgraph__parse_octopus_merge(void)
cl_git_pass(git_repository_open(&repo, cl_fixture("merge-recursive/.gitted")));
cl_git_pass(git_str_joinpath(&commit_graph_path, git_repository_path(repo), "objects/info/commit-graph"));
cl_git_pass(git_commit_graph_file_open(&file, git_str_cstr(&commit_graph_path)));
cl_git_pass(git_commit_graph_file_open(&file, git_str_cstr(&commit_graph_path), GIT_OID_SHA1));
cl_git_pass(git_oid__fromstr(&id, "d71c24b3b113fd1d1909998c5bfe33b86a65ee03", GIT_OID_SHA1));
cl_git_pass(git_commit_graph_entry_find(&e, file, &id, GIT_OID_SHA1_HEXSIZE));
......@@ -103,7 +103,12 @@ void test_graph_commitgraph__writer(void)
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
cl_git_pass(git_str_joinpath(&path, git_repository_path(repo), "objects/info"));
#ifdef GIT_EXPERIMENTAL_SHA256
cl_git_pass(git_commit_graph_writer_new(&w, git_str_cstr(&path), GIT_OID_SHA1));
#else
cl_git_pass(git_commit_graph_writer_new(&w, git_str_cstr(&path)));
#endif
/* This is equivalent to `git commit-graph write --reachable`. */
cl_git_pass(git_revwalk_new(&walk, repo));
......@@ -135,7 +140,11 @@ void test_graph_commitgraph__validate(void)
cl_git_pass(git_str_joinpath(&objects_dir, git_repository_path(repo), "objects"));
/* git_commit_graph_open() calls git_commit_graph_validate() */
#ifdef GIT_EXPERIMENTAL_SHA256
cl_git_pass(git_commit_graph_open(&cgraph, git_str_cstr(&objects_dir), GIT_OID_SHA1));
#else
cl_git_pass(git_commit_graph_open(&cgraph, git_str_cstr(&objects_dir)));
#endif
git_commit_graph_free(cgraph);
git_str_dispose(&objects_dir);
......@@ -158,7 +167,11 @@ void test_graph_commitgraph__validate_corrupt(void)
cl_must_pass(p_close(fd));
/* git_commit_graph_open() calls git_commit_graph_validate() */
#ifdef GIT_EXPERIMENTAL_SHA256
cl_git_fail(git_commit_graph_open(&cgraph, cl_git_sandbox_path(1, "testrepo.git", "objects", NULL), GIT_OID_SHA1));
#else
cl_git_fail(git_commit_graph_open(&cgraph, cl_git_sandbox_path(1, "testrepo.git", "objects", NULL)));
#endif
git_commit_graph_free(cgraph);
git_repository_free(repo);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment