Parse binary headers with file paths (#55)

Some patches may include one or more file paths as part of the binary
header when there is no binary data. Git accounts for this by only
checking the prefix and suffix of the line, but I missed that logic when
implementing this originally.
This commit is contained in:
Billy Keyes
2025-01-07 19:27:03 -08:00
committed by GitHub
parent 8584cd59af
commit 14da3d30f7
2 changed files with 21 additions and 4 deletions
+11 -4
View File
@@ -50,11 +50,11 @@ func (p *parser) ParseBinaryFragments(f *File) (n int, err error) {
}
func (p *parser) ParseBinaryMarker() (isBinary bool, hasData bool, err error) {
switch p.Line(0) {
case "GIT binary patch\n":
line := p.Line(0)
switch {
case line == "GIT binary patch\n":
hasData = true
case "Binary files differ\n":
case "Files differ\n":
case isBinaryNoDataMarker(line):
default:
return false, false, nil
}
@@ -65,6 +65,13 @@ func (p *parser) ParseBinaryMarker() (isBinary bool, hasData bool, err error) {
return true, hasData, nil
}
func isBinaryNoDataMarker(line string) bool {
if strings.HasSuffix(line, " differ\n") {
return strings.HasPrefix(line, "Binary files ") || strings.HasPrefix(line, "Files ")
}
return false
}
func (p *parser) ParseBinaryFragmentHeader() (*BinaryFragment, error) {
parts := strings.SplitN(strings.TrimSuffix(p.Line(0), "\n"), " ", 2)
if len(parts) < 2 {