mirror of
https://github.com/alibaba/open-code-review.git
synced 2026-07-09 17:28:58 +00:00
When a file was renamed on the target branch, ocr review emitted '[ocr] WARNING: cannot read file <old path> at ref <to>: exit status 128'. Two compounding bugs: 1. The parser required 'a/'/'b/' prefixes when matching '--- /dev/null' / '+++ /dev/null', but git emits these lines without prefixes, so IsNew/IsDeleted were never set and deleted files fell through to a doomed 'git show ref:<old path>'. 2. 'rename from' / 'rename to' extended headers were never parsed, and git diff/show call sites did not force rename detection, so renames degraded to delete+add whenever the user had diff.renames=false. Fixes: - Parse 'rename from'/'rename to', 'new file mode', 'deleted file mode' and unprefixed /dev/null markers in ParseDiffText. - Pass --find-renames to all git diff/show invocations so rename detection no longer depends on user config. - Add IsRenamed to model.Diff (json: is_renamed) and prefer it in diffStatus. - Add parser unit tests and a range-mode rename regression test. Fixes #99
15 lines
511 B
Go
15 lines
511 B
Go
package model
|
|
|
|
// Diff represents a single file change in a git diff.
|
|
type Diff struct {
|
|
OldPath string `json:"old_path"`
|
|
NewPath string `json:"new_path"`
|
|
Diff string `json:"diff"`
|
|
NewFileContent string `json:"new_file_content"`
|
|
IsBinary bool `json:"is_binary"`
|
|
IsDeleted bool `json:"is_deleted"`
|
|
IsNew bool `json:"is_new"`
|
|
IsRenamed bool `json:"is_renamed"`
|
|
Insertions int64 `json:"insertions"`
|
|
Deletions int64 `json:"deletions"`
|
|
}
|