Skip to content

Commit 792701a

Browse files
committed
Fix panic when get editor config file (go-gitea#36241)
Fix go-gitea#36239
1 parent e147a82 commit 792701a

File tree

5 files changed

+29
-53
lines changed

5 files changed

+29
-53
lines changed

modules/git/blob_gogit.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,38 @@ package git
99
import (
1010
"io"
1111

12+
"code.gitea.io/gitea/modules/log"
13+
1214
"github.com/go-git/go-git/v5/plumbing"
1315
)
1416

1517
// Blob represents a Git object.
1618
type Blob struct {
17-
ID ObjectID
19+
ID ObjectID
20+
repo *Repository
21+
name string
22+
}
1823

19-
gogitEncodedObj plumbing.EncodedObject
20-
name string
24+
func (b *Blob) gogitEncodedObj() (plumbing.EncodedObject, error) {
25+
return b.repo.gogitRepo.Storer.EncodedObject(plumbing.AnyObject, plumbing.Hash(b.ID.RawValue()))
2126
}
2227

2328
// DataAsync gets a ReadCloser for the contents of a blob without reading it all.
2429
// Calling the Close function on the result will discard all unread output.
2530
func (b *Blob) DataAsync() (io.ReadCloser, error) {
26-
return b.gogitEncodedObj.Reader()
31+
obj, err := b.gogitEncodedObj()
32+
if err != nil {
33+
return nil, err
34+
}
35+
return obj.Reader()
2736
}
2837

2938
// Size returns the uncompressed size of the blob
3039
func (b *Blob) Size() int64 {
31-
return b.gogitEncodedObj.Size()
40+
obj, err := b.gogitEncodedObj()
41+
if err != nil {
42+
log.Error("Error getting gogit encoded object for blob %s(%s): %v", b.name, b.ID.String(), err)
43+
return 0
44+
}
45+
return obj.Size()
3246
}

modules/git/repo_blob.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,11 @@ func (repo *Repository) GetBlob(idStr string) (*Blob, error) {
99
if err != nil {
1010
return nil, err
1111
}
12-
return repo.getBlob(id)
12+
if id.IsZero() {
13+
return nil, ErrNotExist{id.String(), ""}
14+
}
15+
return &Blob{
16+
ID: id,
17+
repo: repo,
18+
}, nil
1319
}

modules/git/repo_blob_gogit.go

Lines changed: 0 additions & 22 deletions
This file was deleted.

modules/git/repo_blob_nogogit.go

Lines changed: 0 additions & 16 deletions
This file was deleted.

modules/git/tree_entry_gogit.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package git
88

99
import (
10-
"github.com/go-git/go-git/v5/plumbing"
1110
"github.com/go-git/go-git/v5/plumbing/filemode"
1211
"github.com/go-git/go-git/v5/plumbing/object"
1312
)
@@ -83,14 +82,9 @@ func (te *TreeEntry) IsExecutable() bool {
8382

8483
// Blob returns the blob object the entry
8584
func (te *TreeEntry) Blob() *Blob {
86-
encodedObj, err := te.ptree.repo.gogitRepo.Storer.EncodedObject(plumbing.AnyObject, te.gogitTreeEntry.Hash)
87-
if err != nil {
88-
return nil
89-
}
90-
9185
return &Blob{
92-
ID: ParseGogitHash(te.gogitTreeEntry.Hash),
93-
gogitEncodedObj: encodedObj,
94-
name: te.Name(),
86+
ID: ParseGogitHash(te.gogitTreeEntry.Hash),
87+
repo: te.ptree.repo,
88+
name: te.Name(),
9589
}
9690
}

0 commit comments

Comments
 (0)