fix(loaders): normalize mnemonic pager prefixes#267
Conversation
Greptile SummaryThis PR normalizes Git mnemonic side-prefixes (
Confidence Score: 3/5The mnemonic-prefix detection heuristic can silently corrupt paths for a noprefix rename between root directories whose names happen to match mnemonic characters, making this change risky to merge without an additional guard. The core fix is well-structured, but the heuristic in
Important Files Changed
Prompt To Fix All With AIFix the following 3 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 3
src/core/loaders.ts:382-390
**False positive for noprefix renames between mnemonic-named directories**
`canonicalizeKnownGitPathPair` decides a path pair uses mnemonic side-prefixes if both halves start with a character in `[ciow12]` and the characters differ. A repo that has top-level directories literally named `c/` and `w/` (or any other two distinct mnemonic characters) and renames a file between them in noprefix mode will trip this branch. `c/foo.ts w/bar.ts` is treated as `i/example.ts w/example.ts`, producing `a/foo.ts b/bar.ts` instead of the correct `a/c/foo.ts b/w/bar.ts`, silently dropping the directory segment from every subsequent file path lookup.
Before this PR the two-token rename fallback preserved the full path. The regression only manifests for repos with mnemonic-named root directories, but the failure is silent and produces wrong paths downstream.
### Issue 2 of 3
src/core/loaders.ts:358-364
**Redundant `GIT_MNEMONIC_PREFIXES.has` guard after regex already restricts the character class**
The regex `^([ciow12])\/(.+)$` can only capture a character in `[ciow12]`, so `GIT_MNEMONIC_PREFIXES.has(match[1]!)` will always be `true` when the regex matches. The guard is dead code and adds a small amount of noise; the set itself is the more readable declaration of valid prefixes, so either the regex character class should delegate to it (not currently expressible inline) or the `.has` check can be removed.
### Issue 3 of 3
src/core/loaders.test.ts:1085-1109
**Missing test coverage for mnemonic-prefix rename diffs**
The new test exercises only a simple modification (`value = 1` to `value = 2`). A rename with `diff.mnemonicPrefix=true` emits `diff --git i/old.ts w/new.ts` with `rename from old.ts` / `rename to new.ts` (no prefix on the `rename` lines), which exercises a different code path through `canonicalizeKnownGitPathPair`. Adding a test that commits a rename and diffs with `diff.mnemonicPrefix=true` would confirm the `rename from`/`rename to` lines are handled correctly and guard the path described in the P1 comment above.
Reviews (1): Last reviewed commit: "fix(loaders): normalize mnemonic pager p..." | Re-trigger Greptile |
98b53c0 to
d2af79d
Compare
|
@greptile-apps thanks for the review — addressed all three points in
This comment was generated by Pi using OpenAI GPT-5 |
|
All three changes look correct and well-executed. Mnemonic rename disambiguation —
Regression tests — the three tests cover exactly the cases that needed coverage:
One minor observation: in LGTM overall. Nice fix. Tip: You can customize Greptile's behavior for this repo with |
|
Thanks — small nuance on that Given that, I’m going to leave it as-is rather than add a type-only refactor in this PR. This comment was generated by Pi using OpenAI GPT-5 |
Summary
Fixes
hunk pager/hunk patchhandling for Git patch input emitted withdiff.mnemonicPrefix=true.Git emits mnemonic side prefixes like
i/,w/,c/,1/, and2/instead of the parser-friendlya//b/prefixes. After #240, those patches can parse, but file paths keep the side prefix (for examplew/example.ts). This normalizes mnemonic prefix pairs back to Pierre's expecteda/... b/...shape before parsing so the review path isexample.ts.Fixes #265.
Tests
bun test src/core/loaders.test.tsbun run typecheckbun run lintThis PR description was generated by Pi using OpenAI GPT-5