mirror of
https://github.com/bluekeyes/go-gitdiff
synced 2026-06-08 13:18:30 +00:00
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:
+11
-4
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user