Skip to content

refactor: extract shared patch helpers#316

Merged
benvinegar merged 1 commit into
mainfrom
refactor/patch-model-helpers
May 15, 2026
Merged

refactor: extract shared patch helpers#316
benvinegar merged 1 commit into
mainfrom
refactor/patch-model-helpers

Conversation

@benvinegar
Copy link
Copy Markdown
Member

Summary

  • Extract patch normalization, Git-format patch handling, git-log stripping, chunking, and DiffFile construction into focused shared helpers.
  • Reuse the shared helpers from the app loader, pager detection, Git VCS placeholders, and public OpenTUI model API.
  • Keep Git untracked-file patch header rewriting at the Git loader boundary and add OpenTUI coverage for noprefix patch normalization.

Verification

  • bun run typecheck
  • bun run format:check
  • bun run lint
  • bun test src/core/patch/gitLog.test.ts src/core/loaders.test.ts src/opentui/HunkDiffView.test.tsx src/core/pager.test.ts src/core/vcs/git.test.ts
  • bun test (543 pass, 9 skipped)

This PR description was generated by Pi using OpenAI GPT-5.1

@benvinegar benvinegar force-pushed the refactor/patch-model-helpers branch from b7f7160 to 56a7c56 Compare May 15, 2026 03:41
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 15, 2026

Greptile Summary

This PR extracts five focused helper modules (diffFile.ts, patch/chunks.ts, patch/gitFormat.ts, patch/gitLog.ts, patch/normalize.ts) from the monolithic loaders.ts, and rewires the app loader, pager, Git VCS adapter, and public OpenTUI API to share them. As a side-effect, createHunkDiffFilesFromPatch now runs the full normalization pipeline (CRLF, terminal control, git-log stripping, noprefix rewriting) before parsing — a genuine behavioral improvement covered by a new test.

  • ~490 lines are removed from loaders.ts by delegating to the new shared helpers; no logic was changed during the move.
  • createSkippedLargeMetadata in vcs/git.ts now accepts an explicit type parameter, and countHunkDiffStats in model.ts is re-exported as an alias to the shared countDiffStats.
  • A new HunkDiffView test confirms that noprefix diff --git headers are correctly normalized through the public createHunkDiffFilesFromPatch API.

Confidence Score: 5/5

Safe to merge — pure refactoring with identical logic in all moved functions, full test suite passing, and one net-new test for the noprefix normalization improvement.

Every extracted function is a byte-for-byte move of existing logic. The only intentional behavioral change — running normalizePatchText in createHunkDiffFilesFromPatch — is additive and directly covered by the new OpenTUI test. The findPatchChunk used by model.ts now uses slightly more robust matching from chunks.ts, which is strictly a superset of the old direct-path matching.

No files require special attention; the most structurally significant changes are src/core/loaders.ts (large deletion) and src/opentui/model.ts (behavioral improvement), both of which look correct.

Important Files Changed

Filename Overview
src/core/diffFile.ts New shared helper file exporting countDiffStats, buildDiffFile, and createSkippedLargeMetadata; clean extraction from loaders.ts with identical logic
src/core/patch/normalize.ts New thin orchestration module combining stripTerminalControl, stripGitLogMetadata, and normalizeGitPatchPrefixes into normalizePatchText; correct pipeline order matches original loaders.ts implementation
src/core/patch/gitFormat.ts Wholesale move of normalizeGitPatchPrefixes and all supporting helpers from loaders.ts; logic is identical, function is now exported for broader reuse
src/core/patch/chunks.ts splitPatchIntoFileChunks and findPatchChunk moved from loaders.ts; the shared findPatchChunk uses stripPrefixes + a/b prefix search which is slightly more robust than the old model.ts version it replaces
src/core/git.ts normalizeUntrackedPatchHeaders and escapeUntrackedPatchPath moved from loaders.ts and made exported; behavior is identical to the original private functions
src/core/loaders.ts ~490 lines removed by delegating to new shared helpers; normalizePatchChangeset now calls normalizePatchText instead of the inline chain
src/core/vcs/git.ts Removes its own createSkippedLargeMetadata and uses the shared version from diffFile.ts; call site correctly passes 'change' as the explicit type argument
src/opentui/model.ts createHunkDiffFilesFromPatch now applies normalizePatchText before chunking/parsing, giving the public API noprefix and CRLF handling; countHunkDiffStats re-exported as alias to countDiffStats

Reviews (1): Last reviewed commit: "refactor: extract shared patch helpers" | Re-trigger Greptile

@benvinegar benvinegar merged commit 6e310a4 into main May 15, 2026
5 checks passed
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.

1 participant