diff options
author | Colin Stolley <ccstolley@github.com> | 2022-06-16 16:50:35 -0500 |
---|---|---|
committer | Derrick Stolee <derrickstolee@github.com> | 2022-11-03 12:09:18 -0400 |
commit | 2c4eb83ee14bca44c2442727bacd82312cbedfc5 (patch) | |
tree | 3646cb856d757d18d09bfd6e214be681dd448c74 /src/libgit2/commit_graph.h | |
parent | a3841af5eecc6301e87f8302c7fdce6555e39247 (diff) | |
download | libgit2-2c4eb83ee14bca44c2442727bacd82312cbedfc5.tar.gz |
commit-graph: only verify csum on git_commit_graph_open().
It is expensive to compute the sha1 of the entire commit-graph file each
time we open it. Git only does this if it is re-writing the file.
This patch will only verify the checksum when calling the external API
git_commit_graph_open(), which explicitly says it opens and verifies
the commit graph in the documentation.
For internal library calls, we call git_commit_graph_get_file(), which
mmaps the commit-graph file in read-only mode. Therefore it is safe to
skip the validation check there.
Tests were added to check that the validation works in the happy path,
and prevents us from opening the file when validation fails.
(Note from Derrick Stolee: This patch was applied internally at GitHub
after we recognized the performance impact it had during an upgrade of
libgit2. The original author left the company before we remembered to
send it upstream.)
Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Diffstat (limited to 'src/libgit2/commit_graph.h')
-rw-r--r-- | src/libgit2/commit_graph.h | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/libgit2/commit_graph.h b/src/libgit2/commit_graph.h index b78ab8177..517abb239 100644 --- a/src/libgit2/commit_graph.h +++ b/src/libgit2/commit_graph.h @@ -106,6 +106,9 @@ struct git_commit_graph { /** 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); +/** 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); |