Skip to content

feat(extraction): add Extractor::extract_file_with_source - #90

Merged
sshaaf merged 1 commit into
sshaaf:mainfrom
nerdalytics:feat/extract-file-with-source
Sep 21, 2026
Merged

sshaaf merged 1 commit into
sshaaf:mainfrom
nerdalytics:feat/extract-file-with-source

Conversation

@nerdalytics

@nerdalytics nerdalytics commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Description

Extractor::extract_file reads its own bytes with std::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 from git show <ref>:<path>, and a bare clone has no worktree to read it from.

Type of Change

  • New feature (non-breaking change which adds functionality)

Changes Made

Extractor. extract_file now reads the bytes and passes them to a new extract_file_with_source, which contains the original body unchanged. Disk stays the default, extract_file keeps 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_disk extracts a Rust symbol from a path under a TempDir that was never written, so it fails if the method ever reads from disk again. cargo test -p rgctl-extraction --lib reports 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_gql gives 3 passed and 8 failed, and cargo clippy --lib --bins -- -D warnings gives 7 collapsible_if errors in rgctl-plugin-api under clippy 1.98.0. I stashed my diff and reran both against main at 68e3dcc, which gave the same 8 failures and the same 7 errors.

  • Unit tests added/updated
  • Integration tests added/updated
  • Tested with cargo test
  • Manual testing performed

Test environment:

  • OS: macOS 26.6.2 (Darwin 25.6.0)
  • Rust version: rustc 1.98.1 (48a229cea 2026-09-01)

Checklist

  • My code follows the style guidelines (ran cargo fmt)
  • I have performed a self-review of my code
  • I have commented my code where necessary
  • I have added tests that prove my fix/feature works
  • All new and existing tests pass (cargo test). Eight tests in this crate fail on main too. See the Testing section.
  • No clippy warnings. cargo clippy -p rgctl-extraction --all-targets reports nothing in extractor.rs.
  • Documentation updated (if applicable). The new method carries a doc comment, and no guide describes Extractor directly.
  • CONTRIBUTING.md guidelines followed
  • All commits are signed and include DCO sign-off

Performance Impact

  • No measurable performance regression

extract_file moves a Vec<u8> it already owned, and does the same single read as before.

Breaking Changes

None. extract_file keeps 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 with WalkBuilder, stats each entry in is_too_large (:153), and opens each file in is_binary (:158). IncrementalUpdater::apply_change_set calls it (rgctl-incremental/src/updater.rs:153). After this change, extract_file is the only content read a caller can bypass, and I am not changing the discoverer here.

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>
@sshaaf
sshaaf merged commit cca21ce into sshaaf:main Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants