aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2021-06-24 17:47:46 +0200
committerGitHub <noreply@github.com>2021-06-24 17:47:46 +0200
commit4cc63e9919486581f7acc49829ebf21bc52dd871 (patch)
tree026d7784462055d3dd4149e414f4053c215081df /modules/git
parent71c5a8f7f8b127c559115a6bbbfe6372ecf6dd10 (diff)
downloadgitea-4cc63e9919486581f7acc49829ebf21bc52dd871.tar.gz
gitea-4cc63e9919486581f7acc49829ebf21bc52dd871.zip
Fix diff expansion is missing final line in a file (#16222)
* Fixed down offset. * Fixed wrong line count result.
Diffstat (limited to 'modules/git')
-rw-r--r--modules/git/blob.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/modules/git/blob.go b/modules/git/blob.go
index 732356e5b2..5831bc3735 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)
}
}