diff options
Diffstat (limited to 'models/git_diff.go')
-rw-r--r-- | models/git_diff.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/models/git_diff.go b/models/git_diff.go index fe99f61bfe..f796f286d6 100644 --- a/models/git_diff.go +++ b/models/git_diff.go @@ -200,6 +200,7 @@ type DiffFile struct { IsCreated bool IsDeleted bool IsBin bool + IsLFSFile bool IsRenamed bool IsSubmodule bool Sections []*DiffSection @@ -245,6 +246,7 @@ func ParsePatch(maxLines, maxLineCharacteres, maxFiles int, reader io.Reader) (* leftLine, rightLine int lineCount int curFileLinesCount int + curFileLFSPrefix bool ) input := bufio.NewReader(reader) @@ -268,6 +270,28 @@ func ParsePatch(maxLines, maxLineCharacteres, maxFiles int, reader io.Reader) (* continue } + trimLine := strings.Trim(line, "+- ") + + if trimLine == LFSMetaFileIdentifier { + curFileLFSPrefix = true + } + + if curFileLFSPrefix && strings.HasPrefix(trimLine, LFSMetaFileOidPrefix) { + oid := strings.TrimPrefix(trimLine, LFSMetaFileOidPrefix) + + if len(oid) == 64 { + m := &LFSMetaObject{Oid: oid} + count, err := x.Count(m) + + if err == nil && count > 0 { + curFile.IsBin = true + curFile.IsLFSFile = true + curSection.Lines = nil + break + } + } + } + curFileLinesCount++ lineCount++ @@ -354,6 +378,7 @@ func ParsePatch(maxLines, maxLineCharacteres, maxFiles int, reader io.Reader) (* break } curFileLinesCount = 0 + curFileLFSPrefix = false // Check file diff type and is submodule. for { |