-
-
Notifications
You must be signed in to change notification settings - Fork 172
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
Add a managed Git implementation #521
Conversation
@AArnott let me know how you want to proceed with this - I'm opening the PR to get early feedback. I guess could first work to get the PR to a state where it's good to merge (e.g. code quality, unit tests,...), and then stabilize further (e.g. perf work,...) on a feature/version branch? |
I ran benchmarks on this PR, and here are the results:
|
@AArnott I think this PR is close to ready for review:
One item pending your feedback is the TargetFramework - using Could you have a first glance at this PR and let me know what you think? |
I would prefer to multitarget in order to continue to support netcoreapp2.1/net472 while optimizing perf on netcoreapp3.1 through overrides of Span overloads. I'll take a look at this PR later today. Have you reviewed the various issues where we've discussed this for corner cases in git storage patterns? I can't recall where I saw it, but the libgit2sharp maintainers were warning us that there were many different cases in how packs/objects were stored in the |
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.
This looks exciting. Thanks so much for your work. The perf improvements look significant and the code quality looks really good too. I haven't reviewed everything, but I wanted to share what I have so far with you and get your thoughts before I continue.
src/Nerdbank.GitVersioning.Tasks/Nerdbank.GitVersioning.Tasks.csproj
Outdated
Show resolved
Hide resolved
src/NerdBank.GitVersioning.Benchmarks/NerdBank.GitVersioning.Benchmarks.csproj
Outdated
Show resolved
Hide resolved
src/NerdBank.GitVersioning.Benchmarks/NerdBank.GitVersioning.Benchmarks.csproj
Outdated
Show resolved
Hide resolved
@AArnott Thanks for the feedback! I'll try to get the framework targeting sorted out first, probably early next week. |
Move LibGit2-dependent code to LibGit2VersionOracle
- Work on directories which are not Git repositories (NotRepo) - Work with empty version.json files (VersionJsonWithVersion)
Add worktree support (Worktree_Support)
…a version.json file. Makes all VersionOracleTests pass.
…itory would cause incorrect version numbers.
- no git HEAD - no version.json file
@AArnott, re: Git Pack documentation, here are the documents I found useful:
|
Thanks for that. I did write a test for the short commit id, but it's based on libgit2's (odd?) behavior of not returning anything less than 7 as a length. It's in the |
@AArnott Well, I did a quick implementation of I guess libgit2 does always returns 7 characters to make sure the values are somehow future-proof. |
…d-git' into features/managed-git
Great. However, in adding a couple tests I found that odd-number length partial commits produces an exception. I guess since you're converting the hex to bytes it makes searching by bytes hard when you only have half a byte prescribed. Any ideas? I wouldn't want to cause builds to fail when they specified |
I just added a test for odd length commit lookups by partial id and it threw the same exception. |
I'm trying my hand at a fix for this, unless you'd rather, @qmfrederik |
Got it fixed. :) Merging tonight... |
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.
Your contribution @qmfrederik is amazing. Thank you so much!
And thank you @filipnavara for helping with the awesome performance improvements too! |
- Build with .NET 5.0.100 SDK This requires also updating the NB.GV LKG version we build with. - Build benchmarks for net5.0 as well - Install the new SDK on agents - Add .NET Core 3.1 runtime for testing - Run tests on net5.0 instead of netcoreapp3.1 While we'd rather test *both*, microsoft/MSBuildLocator#95 is likely the cause for a failure of MSBuild to locate System.Collections.dll,v5.0 when running on the .NET Core 3.1 runtime but under the 5.0 SDK.
If all goes well, this will push to nuget.org as 3.4.142-alpha in about 30 minutes. |
Thanks, @AArnott ! It looks like the package didn't make it to nuget.org, but it's available in the CI feed, so that works for me :). |
Ya, it got snagged due to a bad service connection. That has been rectified though so it's on nuget.org now. |
Adds a managed Git implementation to NBGV. The managed implementation is used by default but libgit2sharp is used under a switch or when writing to git is required (e.g.
nbgv prepare-release
).All tests run against both backends.
This implementation already contains a couple of performance optimizations which I worked on with the help of @filipnavara ; but the performance may have regressed as I focused on matching the NBGV features.
Perhaps worth mentioning is that:
File.OpenRead
, but alsoFile.Exists
and just constructing the file name) turned out to be an expensive operation. On Windows, there's for example a P/Invoke call to CreateFile to implement some kind ofTryOpen
, to avoid having to callFile.Exists
followed byFile.OpenRead
(which is slow and racy)FileStream
objects which access git pack files, and caching objects retrieved from a git pack in a cache, because this can be an expensive operation).Streams
which point to the pack file are pooled instead of opening/closing them repeatedly (which is expensive).Notable steps completed:
GitCommit
: Since most commits only have one/two parents, investigate whether it is worth storing the first (two) parents as a field on theGitCommit
struct, and additional parents in a list. This would avoid allocating manyList<GitObjectId>
objects with only a single item.GitCommit
: Investigate whether it's worth parsing theAuthor
value for the current HEAD only.Investigate whether walking the Git tree can be parallelized(deferred)Test that .ps1 scripts in nuget package still work(these scripts were removed as they are incompatible now)ManagedGit.GitRepository.ShortenObjectId
GitRepository.Lookup
Closes #505
Closes #487
Closes #433
Closes #92
Improves perf as tracked by #114