feat(extraction): add Extractor::extract_file_with_source - #90
Merged
Merged
Conversation
extract_file reads the file itself with std::fs::read, so a caller that already holds the content cannot use it. Building a graph from a bare clone means the content comes from `git show <ref>:<path>` and never lands in a worktree (sshaaf#78). extract_file now reads the bytes and delegates to extract_file_with_source, which holds the body unchanged. Disk stays the default and extract_file keeps its signature. Signed-off-by: nerdalytics <97166791+nerdalytics@users.noreply.github.com>
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.
Description
Extractor::extract_filereads its own bytes withstd::fs::read, so a caller that already holds the content cannot use it. I hit this in #78, where I extract each commit out of a bare clone. The content comes fromgit show <ref>:<path>, and a bare clone has no worktree to read it from.Type of Change
Changes Made
Extractor.
extract_filenow reads the bytes and passes them to a newextract_file_with_source, which contains the original body unchanged. Disk stays the default,extract_filekeeps its signature, and the change adds no dependency.Naming. I followed
GraphBuilder::ensure_file_node_with_source(graph_builder.rs:228), which already splits the same way in this crate.Testing
extract_file_with_source_needs_no_file_on_diskextracts a Rust symbol from a path under aTempDirthat was never written, so it fails if the method ever reads from disk again.cargo test -p rgctl-extraction --libreports 47 passed, 0 failed.Two pre-existing problems show up in the wider gates, and neither comes from this change.
cargo test -p rgctl-extraction --test markdown_context_gqlgives 3 passed and 8 failed, andcargo clippy --lib --bins -- -D warningsgives 7collapsible_iferrors inrgctl-plugin-apiunder clippy 1.98.0. I stashed my diff and reran both againstmainat 68e3dcc, which gave the same 8 failures and the same 7 errors.cargo testTest environment:
Checklist
cargo fmt)cargo test). Eight tests in this crate fail onmaintoo. See the Testing section.cargo clippy -p rgctl-extraction --all-targetsreports nothing inextractor.rs.Extractordirectly.Performance Impact
extract_filemoves aVec<u8>it already owned, and does the same single read as before.Breaking Changes
None.
extract_filekeeps its signature and its behavior.Additional Notes
This does not make extraction content-agnostic on its own.
FileDiscoverer::discover(rgctl-extraction/src/discovery/mod.rs:80) reaches the filesystem in three places. It walks the tree withWalkBuilder, stats each entry inis_too_large(:153), and opens each file inis_binary(:158).IncrementalUpdater::apply_change_setcalls it (rgctl-incremental/src/updater.rs:153). After this change,extract_fileis the only content read a caller can bypass, and I am not changing the discoverer here.