Skip to content
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

[Feature Request] Using git library to extract git related information #9088

Closed
filzrev opened this issue Aug 15, 2023 · 7 comments · Fixed by #9314
Closed

[Feature Request] Using git library to extract git related information #9088

filzrev opened this issue Aug 15, 2023 · 7 comments · Fixed by #9314
Labels
static-site Produce static HTML output ready for publishing to hosts like GitHub pages

Comments

@filzrev
Copy link
Contributor

filzrev commented Aug 15, 2023

Is your feature request related to a problem? Please describe.
Current docfx v2 extracts git related information by invoking git command using CommandUtility.cs.
It takes about 30-60 milliseconds every calls to get file information.
and when it need to get additional information (like committer-date) it require extra command invoke costs.

Describe the solution you'd like
It seems docfx v3 using LibGit2 to get git information.
I hope these features can backport to v2. If it run faster than current implementation.

Describe alternatives you've considered

@KalleOlaviNiemitalo
Copy link

FWIW, nbgv 3.6.133 ships with these unmanaged libraries:

Uncompressed size Path
1125832 tools/net6.0/any/runtimes/linux-arm/native/libgit2-b7bad55.so
1447504 tools/net6.0/any/runtimes/linux-arm64/native/libgit2-b7bad55.so
1520212 tools/net6.0/any/runtimes/linux-musl-arm/native/libgit2-b7bad55.so
1619160 tools/net6.0/any/runtimes/linux-musl-arm64/native/libgit2-b7bad55.so
1663736 tools/net6.0/any/runtimes/linux-musl-x64/native/libgit2-b7bad55.so
1658528 tools/net6.0/any/runtimes/linux-x64/native/libgit2-b7bad55.so
1109816 tools/net6.0/any/runtimes/osx-arm64/native/libgit2-b7bad55.dylib
1183856 tools/net6.0/any/runtimes/osx-x64/native/libgit2-b7bad55.dylib
1429504 tools/net6.0/any/runtimes/win-arm64/native/git2-b7bad55.dll
1703424 tools/net6.0/any/runtimes/win-x64/native/git2-b7bad55.dll
1346048 tools/net6.0/any/runtimes/win-x86/native/git2-b7bad55.dll

The compressed sizes are approximately half of those. In the docfx tool package, I assume it would be possible to deduplicate the libraries across net6.0, net7.0, and net8.0.

Would there have to be a fallback implementation that executes git, in case someone runs DocFX on another architecture like RISC-V (dotnet/runtime#36748 in progress)?

Does the linking exception of the libgit2 license apply when libgit2 is distributed as a shared library rather than "linked into a combined executable"?

@yufeih yufeih added the static-site Produce static HTML output ready for publishing to hosts like GitHub pages label Aug 15, 2023
@filzrev
Copy link
Contributor Author

filzrev commented Aug 15, 2023

It seems better to using fully managed version git reader library.

For example:

I thought following functionalities required to replace git command to library.

1. GetRepoRootCommand

Git Command: git rev-parse --show-toplevel

2. GetLocalBranchCommand

Git Command: git rev-parse --abbrev-ref HEAD

3. GetLocalBranchCommitIdCommand

Git Command:: git rev-parse HEAD

4. GetRemoteBranchCommand

GitCommand: git rev-parse --abbrev-ref @{u}

5. GetGitCommiterDate (Currently not included)

Git Command: git log -1 --format=%cI --no-show-signature {filename}

@yufeih
Copy link
Contributor

yufeih commented Aug 15, 2023

It seems better to using fully managed version git reader library.

Fantastic!

@filzrev
Copy link
Contributor Author

filzrev commented Nov 7, 2023

@yufeih
Is it able to re-open this issue?
I thought following problems are resolved at latest GitReader 1.6.0 release.

  • Wrong remote URL is returned by GitReader
  • Can't get information managed by git submodules.

Remaining Issues

@yufeih yufeih reopened this Nov 8, 2023
@yufeih
Copy link
Contributor

yufeih commented Nov 8, 2023

GitReader has been replaced with a different implementation due to bugs in the library. We should fix the path problem.

@yufeih yufeih closed this as completed Nov 8, 2023
@filzrev
Copy link
Contributor Author

filzrev commented Nov 25, 2023

Can't get information managed by git submodules.

It seems current docfx implementation don't support git submodule repository. (Currently, it returns root repository URL)

It needs to implement extra gitdir: path lookup logics when directory contains git file.
I'll try to create PR that fix this issue later.

@filzrev
Copy link
Contributor Author

filzrev commented Dec 18, 2023

Git submodule supports issue is resolved by PR(#9540).

My remaining issue is to get committer date (Expected to be used for Sitemap/RSS feed).

5. GetGitCommiterDate (Currently not included)

Git Command: git log -1 --format=%cI --no-show-signature {filename}

It seems complex to get this information from .git repository structure without library.
So I'm expected to get this information by using git.exe external executable call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
static-site Produce static HTML output ready for publishing to hosts like GitHub pages
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants