Skip to content

Commit 6aa9099

Browse files
committed
temp: simplify code
1 parent d42de12 commit 6aa9099

File tree

6 files changed

+128
-292
lines changed

6 files changed

+128
-292
lines changed

modules/git/blob.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package git
77
import (
88
"bytes"
99
"encoding/base64"
10+
"errors"
1011
"io"
1112

1213
"code.gitea.io/gitea/modules/typesniffer"
@@ -34,8 +35,9 @@ func (b *Blob) GetBlobContent(limit int64) (string, error) {
3435
return string(buf), err
3536
}
3637

37-
// GetBlobLineCount gets line count of the blob
38-
func (b *Blob) GetBlobLineCount() (int, error) {
38+
// GetBlobLineCount gets line count of the blob.
39+
// It will also try to write the content to w if it's not nil, then we could pre-fetch the content without reading it again.
40+
func (b *Blob) GetBlobLineCount(w io.Writer) (int, error) {
3941
reader, err := b.DataAsync()
4042
if err != nil {
4143
return 0, err
@@ -44,20 +46,20 @@ func (b *Blob) GetBlobLineCount() (int, error) {
4446
buf := make([]byte, 32*1024)
4547
count := 1
4648
lineSep := []byte{'\n'}
47-
48-
c, err := reader.Read(buf)
49-
if c == 0 && err == io.EOF {
50-
return 0, nil
51-
}
5249
for {
50+
c, err := reader.Read(buf)
51+
if w != nil {
52+
if _, err := w.Write(buf[:c]); err != nil {
53+
return count, err
54+
}
55+
}
5356
count += bytes.Count(buf[:c], lineSep)
5457
switch {
55-
case err == io.EOF:
58+
case errors.Is(err, io.EOF):
5659
return count, nil
5760
case err != nil:
5861
return count, err
5962
}
60-
c, err = reader.Read(buf)
6163
}
6264
}
6365

modules/setting/git.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,10 @@ var Git = struct {
3838
Pull int
3939
GC int `ini:"GC"`
4040
} `ini:"git.timeout"`
41-
MaxDiffHighlightFileSize int64
4241
}{
4342
DisableDiffHighlight: false,
4443
MaxGitDiffLines: 1000,
4544
MaxGitDiffLineCharacters: 5000,
46-
MaxDiffHighlightFileSize: 5000,
4745
MaxGitDiffFiles: 100,
4846
CommitsRangeSize: 50,
4947
BranchesRangeSize: 20,

routers/web/repo/blame.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func RefBlame(ctx *context.Context) {
9797
return
9898
}
9999

100-
ctx.Data["NumLines"], err = blob.GetBlobLineCount()
100+
ctx.Data["NumLines"], err = blob.GetBlobLineCount(nil)
101101
if err != nil {
102102
ctx.NotFound(err)
103103
return

0 commit comments

Comments
 (0)