-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
libfetchers/git-utils: Do not refresh pack files in GitFileSystemObje… #14696
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
+35
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1068,6 +1068,13 @@ struct GitFileSystemObjectSinkImpl : GitFileSystemObjectSink | |
| */ | ||
| std::string regularFileContentsBuffer; | ||
|
|
||
| /** | ||
| * If repo has a non-null packBackend, this has a copy of the refresh function | ||
| * from the backend virtual table. This is needed to restore it after we've flushed | ||
| * the sink. We modify it to avoid unnecessary I/O on non-existent oids. | ||
| */ | ||
| decltype(::git_odb_backend::refresh) packfileOdbRefresh = nullptr; | ||
|
|
||
| void pushBuilder(std::string name) | ||
| { | ||
| const git_tree_entry * entry; | ||
|
|
@@ -1093,6 +1100,29 @@ struct GitFileSystemObjectSinkImpl : GitFileSystemObjectSink | |
| GitFileSystemObjectSinkImpl(ref<GitRepoImpl> repo) | ||
| : repo(repo) | ||
| { | ||
| /* Monkey-patching the pack backend to only read the pack directory | ||
| once. Otherwise it will do a readdir for each added oid when it's | ||
| not found and that translates to ~6 syscalls. Since we are never | ||
| writing pack files until flushing we can force the odb backend to | ||
| read the directory just once. It's very convenient that the vtable is | ||
| semi-public interface and is up for grabs. | ||
|
|
||
| This is purely an optimization for our use-case with a tarball cache. | ||
| libgit2 calls refresh() if the backend provides it when an oid isn't found. | ||
| We are only writing objects to a mempack (it has higher priority) and there isn't | ||
| a realistic use-case where a previously missing object would appear from thin air | ||
| on the disk (unless another process happens to be unpacking a similar tarball to | ||
| the cache at the same time, but that's a very unrealistic scenario). | ||
| */ | ||
| if (auto * backend = repo->packBackend) { | ||
| if (backend->refresh(backend)) /* Refresh just once manually. */ | ||
| throw Error("refreshing packfiles: %s", git_error_last()->message); | ||
| /* Save the function pointer to restore it later in flush() and | ||
| unset it in the vtable. libgit2 does nothing if it's a nullptr: | ||
| https://github.com/libgit2/libgit2/blob/58d9363f02f1fa39e46d49b604f27008e75b72f2/src/libgit2/odb.c#L1922 | ||
| */ | ||
| packfileOdbRefresh = std::exchange(backend->refresh, nullptr); | ||
| } | ||
| pushBuilder(""); | ||
| } | ||
|
|
||
|
|
@@ -1309,6 +1339,11 @@ struct GitFileSystemObjectSinkImpl : GitFileSystemObjectSink | |
|
|
||
| auto [oid, _name] = popBuilder(); | ||
|
|
||
| if (auto * backend = repo->packBackend) { | ||
| /* We are done writing blobs, can restore refresh functionality. */ | ||
| backend->refresh = packfileOdbRefresh; | ||
|
Comment on lines
+1343
to
+1344
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume that the status of |
||
| } | ||
|
|
||
| repo->flush(); | ||
|
|
||
| return toHash(oid); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this different than
?