feat(core): analyze a git commit/tree-ish directly via --git-hash - #36
Merged
Conversation
Adds GitSnapshotExtractor, which shells out to git (ls-tree, cat-file --batch) to dump a commit's tracked blobs into a temp directory without checking it out. AnalyzeHandler scans the dump like --list-file and remaps reported paths back to git-relative paths before rendering. Symlink and submodule tree entries are skipped and reported.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
GitSnapshotExtractor(src/Sloc.Core/GitSnapshotExtractor.cs), which shells out togit(ls-tree -r -z,cat-file --batch) to dump every tracked blob of a commit/tree-ish into a temp directory, without checking it out. Symlink and submodule tree entries are skipped and reported.--git-hash <commit>CLI option (mutually exclusive with--list-file);pathis used as the repo root to query.AnalyzeHandlerscans the extracted temp files via the existing--list-filecode path (DirectoryScanner.ScanFiles), then remaps reported paths from temp paths back to git-relative paths before rendering/--baseline/--unique, and cleans up the temp directory in afinally.CLAUDE.md.Test plan
dotnet build Sloc.slnx— 0 warnings, 0 errors.dotnet test Sloc.slnx— 295/295 passing, including new tests:tests/Sloc.Core.Tests/GitSnapshotExtractorTests.cs— HEAD extraction matches working tree, older-commit extraction reflects historical state, symlink entries are skipped, binary content is dumped byte-for-byte, invalid hash / non-repo path throwGitSnapshotException.tests/Sloc.Cli.Tests/AnalyzeHandlerGitHashTests.cs—--git-hash HEADreports git-relative paths and matches a normal scan's totals; invalid hash returnsExitCode.Error; temp directory is cleaned up afterExecutereturns.sloc . --git-hash HEAD -f jsonagainst this repo and confirmed output paths are git-relative and uncommitted files are correctly excluded.