From d9cd8eec62115dd64e38157889c4b2a2cf2b9780 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Mon, 21 Jun 2021 16:43:00 +0200 Subject: [PATCH 1/2] Fixed down offset. --- routers/web/repo/compare.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index f53a31769df19..fddfc4a63a897 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -714,7 +714,11 @@ func ExcerptBlob(ctx *context.Context) { lastLeft += chunkSize lastRight += chunkSize } else { - section.Lines, err = getExcerptLines(commit, filePath, lastLeft, lastRight, idxRight-lastRight-1) + offset := -1 + if direction == "down" { + offset = 0 + } + section.Lines, err = getExcerptLines(commit, filePath, lastLeft, lastRight, idxRight-lastRight+offset) leftHunkSize = 0 rightHunkSize = 0 idxLeft = lastLeft From 039996b8ea2fb481d3169cf94f14e469dd64899c Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Tue, 22 Jun 2021 14:36:34 +0000 Subject: [PATCH 2/2] Fixed wrong line count result. --- modules/git/blob.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/git/blob.go b/modules/git/blob.go index 732356e5b2f96..5831bc3735aae 100644 --- a/modules/git/blob.go +++ b/modules/git/blob.go @@ -34,7 +34,7 @@ func (b *Blob) GetBlobContent() (string, error) { return string(buf), nil } -// GetBlobLineCount gets line count of lob as raw text +// GetBlobLineCount gets line count of the blob func (b *Blob) GetBlobLineCount() (int, error) { reader, err := b.DataAsync() if err != nil { @@ -42,10 +42,14 @@ func (b *Blob) GetBlobLineCount() (int, error) { } defer reader.Close() buf := make([]byte, 32*1024) - count := 0 + count := 1 lineSep := []byte{'\n'} + + c, err := reader.Read(buf) + if c == 0 && err == io.EOF { + return 0, nil + } for { - c, err := reader.Read(buf) count += bytes.Count(buf[:c], lineSep) switch { case err == io.EOF: @@ -53,6 +57,7 @@ func (b *Blob) GetBlobLineCount() (int, error) { case err != nil: return count, err } + c, err = reader.Read(buf) } }