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
d7e65096
Unverified
Commit
d7e65096
authored
Mar 04, 2021
by
Edward Thomson
Committed by
GitHub
Mar 04, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5764 from lhchavez/cgraph-needs-refresh
commit-graph: Introduce `git_commit_graph_needs_refresh()`
parents
b99b5a81
1a2f9609
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
0 deletions
+43
-0
src/commit_graph.c
+34
-0
src/commit_graph.h
+8
-0
tests/graph/commit_graph.c
+1
-0
No files found.
src/commit_graph.c
View file @
d7e65096
...
...
@@ -333,6 +333,40 @@ static int git_commit_graph_entry_get_byindex(
return
0
;
}
bool
git_commit_graph_needs_refresh
(
const
git_commit_graph_file
*
cgraph
,
const
char
*
path
)
{
git_file
fd
=
-
1
;
struct
stat
st
;
ssize_t
bytes_read
;
git_oid
cgraph_checksum
=
{{
0
}};
if
(
path
==
NULL
)
path
=
git_buf_cstr
(
&
cgraph
->
filename
);
/* TODO: properly open the file without access time using O_NOATIME */
fd
=
git_futils_open_ro
(
path
);
if
(
fd
<
0
)
return
true
;
if
(
p_fstat
(
fd
,
&
st
)
<
0
)
{
p_close
(
fd
);
return
true
;
}
if
(
!
S_ISREG
(
st
.
st_mode
)
||
!
git__is_sizet
(
st
.
st_size
)
||
(
size_t
)
st
.
st_size
!=
cgraph
->
graph_map
.
len
)
{
p_close
(
fd
);
return
true
;
}
bytes_read
=
p_pread
(
fd
,
cgraph_checksum
.
id
,
GIT_OID_RAWSZ
,
st
.
st_size
-
GIT_OID_RAWSZ
);
p_close
(
fd
);
if
(
bytes_read
!=
GIT_OID_RAWSZ
)
return
true
;
return
!
git_oid_equal
(
&
cgraph_checksum
,
&
cgraph
->
checksum
);
}
int
git_commit_graph_entry_find
(
git_commit_graph_entry
*
e
,
const
git_commit_graph_file
*
cgraph
,
...
...
src/commit_graph.h
View file @
d7e65096
...
...
@@ -89,6 +89,14 @@ typedef struct git_commit_graph_entry {
}
git_commit_graph_entry
;
int
git_commit_graph_open
(
git_commit_graph_file
**
cgraph_out
,
const
char
*
path
);
/*
* Returns whether the commit_graph_file needs to be reloaded since the
* contents of the commit-graph file have changed on disk. If `path` is NULL,
* the filename stored in `cgraph` will be used.
*/
bool
git_commit_graph_needs_refresh
(
const
git_commit_graph_file
*
cgraph
,
const
char
*
path
);
int
git_commit_graph_entry_find
(
git_commit_graph_entry
*
e
,
const
git_commit_graph_file
*
cgraph
,
...
...
tests/graph/commit_graph.c
View file @
d7e65096
...
...
@@ -15,6 +15,7 @@ void test_graph_commit_graph__parse(void)
cl_git_pass
(
git_repository_open
(
&
repo
,
cl_fixture
(
"testrepo.git"
)));
cl_git_pass
(
git_buf_joinpath
(
&
commit_graph_path
,
git_repository_path
(
repo
),
"objects/info/commit-graph"
));
cl_git_pass
(
git_commit_graph_open
(
&
cgraph
,
git_buf_cstr
(
&
commit_graph_path
)));
cl_assert_equal_i
(
git_commit_graph_needs_refresh
(
cgraph
,
git_buf_cstr
(
&
commit_graph_path
)),
0
);
cl_git_pass
(
git_oid_fromstr
(
&
id
,
"5001298e0c09ad9c34e4249bc5801c75e9754fa5"
));
cl_git_pass
(
git_commit_graph_entry_find
(
&
e
,
cgraph
,
&
id
,
GIT_OID_HEXSZ
));
...
...
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