fix(diff): skip binary file contents in reviews#187
Conversation
Greptile SummaryThis PR adds binary file detection to skip reading binary file contents in direct file diffs and to mark binary diffs (both file-pair and git-sourced) so the UI renders a placeholder instead of attempting to decode non-textual content. A new Confidence Score: 5/5Safe to merge; the single finding is a naming-only P2 with no functional impact. All logic is correct — binary detection fires before file reads, the src/core/binary.ts — minor naming issue only. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[loadFileDiffChangeset] --> B{isProbablyBinaryFile\nleft or right?}
B -- yes --> C[buildBinaryFileDiffChangeset]
C --> D[createSkippedBinaryMetadata\ntype: new/change/deleted]
D --> E[buildDiffFile\nisBinary: true explicit]
B -- no --> F[Bun.file.text x2\nread full contents]
F --> G[parseDiffFromFile\ncreateTwoFilesPatch]
G --> H[buildDiffFile\nisBinary: patchLooksBinary fallback]
I[loadGitChangeset] --> J[normalizePatchChangeset]
J --> K[buildDiffFile\nisBinary: patchLooksBinary fallback]
E --> L[DiffFile.isBinary = true]
H --> L
K --> L
L --> M{diffMessage}
M -- rename-pure --> N[rename message]
M -- isBinary --> O[Binary file skipped]
M -- new/deleted/other --> P[type-specific message]
Q[HunkDiffView toInternalDiffFile] --> R[patchLooksBinary on patch]
R --> L
Reviews (1): Last reviewed commit: "fix(diff): skip binary file contents in ..." | Re-trigger Greptile |
src/core/binary.ts
Outdated
| function isSuspiciousTextByte(byte: number) { | ||
| return byte < 0x07 || (byte > 0x0d && byte < 0x20) || byte === 0x7f; | ||
| } |
There was a problem hiding this comment.
isSuspiciousTextByte reads as "this byte looks like a suspicious text byte," but the function returns true for control-character ranges that signal binary content — the exact opposite of what the name implies. The JSDoc even says "strong binary signal instead of normal text content," which contradicts the identifier. A name like isBinarySignalByte or looksLikeBinaryByte would match both the doc and the intent.
| function isSuspiciousTextByte(byte: number) { | |
| return byte < 0x07 || (byte > 0x0d && byte < 0x20) || byte === 0x7f; | |
| } | |
| /** Return whether one byte is a strong binary signal instead of normal text content. */ | |
| function isBinarySignalByte(byte: number) { |
The call site on line 74 would also need updating to isBinarySignalByte(byte).
There was a problem hiding this comment.
Good catch. I renamed the helper to isBinarySignalByte, updated the call site, and renamed the counter to binarySignalBytes for consistency. I also re-ran bun run typecheck and bun test src/core/loaders.test.ts.
This comment was generated by Pi using OpenAI o3
Summary
Testing
This PR description was generated by Pi using OpenAI o3