Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
b899fda3
Commit
b899fda3
authored
Apr 10, 2023
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit graph: support sha256
parent
be484d35
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
9 deletions
+49
-9
include/git2/sys/commit_graph.h
+12
-2
src/libgit2/commit_graph.c
+0
-0
src/libgit2/commit_graph.h
+20
-4
src/libgit2/odb.c
+2
-1
tests/libgit2/graph/commitgraph.c
+15
-2
No files found.
include/git2/sys/commit_graph.h
View file @
b899fda3
...
...
@@ -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.
...
...
src/libgit2/commit_graph.c
View file @
b899fda3
This diff is collapsed.
Click to expand it.
src/libgit2/commit_graph.h
View file @
b899fda3
...
...
@@ -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
;
};
...
...
src/libgit2/odb.c
View file @
b899fda3
...
...
@@ -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
;
}
...
...
tests/libgit2/graph/commitgraph.c
View file @
b899fda3
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment