Skip to content

Commit 0fa7917

Browse files
committed
fix gogit build
1 parent 5e20f4d commit 0fa7917

15 files changed

+62
-52
lines changed

modules/git/blob_gogit.go

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

99
import (
10+
"context"
1011
"io"
1112

1213
"github.com/go-git/go-git/v5/plumbing"
@@ -22,11 +23,11 @@ type Blob struct {
2223

2324
// DataAsync gets a ReadCloser for the contents of a blob without reading it all.
2425
// Calling the Close function on the result will discard all unread output.
25-
func (b *Blob) DataAsync() (io.ReadCloser, error) {
26+
func (b *Blob) DataAsync(ctx context.Context) (io.ReadCloser, error) {
2627
return b.gogitEncodedObj.Reader()
2728
}
2829

2930
// Size returns the uncompressed size of the blob
30-
func (b *Blob) Size() int64 {
31+
func (b *Blob) Size(ctx context.Context) int64 {
3132
return b.gogitEncodedObj.Size()
3233
}

modules/git/commit_info_gogit.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, repoLink string, commit *
3737
var revs map[string]*Commit
3838
if commit.repo.LastCommitCache != nil {
3939
var unHitPaths []string
40-
revs, unHitPaths, err = getLastCommitForPathsByCache(commit.ID.String(), treePath, entryPaths, commit.repo.LastCommitCache)
40+
revs, unHitPaths, err = getLastCommitForPathsByCache(ctx, commit.ID.String(), treePath, entryPaths, commit.repo.LastCommitCache)
4141
if err != nil {
4242
return nil, nil, err
4343
}
@@ -73,7 +73,7 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, repoLink string, commit *
7373

7474
// If the entry is a submodule, add a submodule file for this
7575
if entry.IsSubModule() {
76-
commitsInfo[i].SubmoduleFile, err = GetCommitInfoSubmoduleFile(repoLink, path.Join(treePath, entry.Name()), commit, entry.ID)
76+
commitsInfo[i].SubmoduleFile, err = GetCommitInfoSubmoduleFile(ctx, repoLink, path.Join(treePath, entry.Name()), commit, entry.ID)
7777
if err != nil {
7878
return nil, nil, err
7979
}
@@ -143,11 +143,11 @@ func getFileHashes(c cgobject.CommitNode, treePath string, paths []string) (map[
143143
return hashes, nil
144144
}
145145

146-
func getLastCommitForPathsByCache(commitID, treePath string, paths []string, cache *LastCommitCache) (map[string]*Commit, []string, error) {
146+
func getLastCommitForPathsByCache(ctx context.Context, commitID, treePath string, paths []string, cache *LastCommitCache) (map[string]*Commit, []string, error) {
147147
var unHitEntryPaths []string
148148
results := make(map[string]*Commit)
149149
for _, p := range paths {
150-
lastCommit, err := cache.Get(commitID, path.Join(treePath, p))
150+
lastCommit, err := cache.Get(ctx, commitID, path.Join(treePath, p))
151151
if err != nil {
152152
return nil, nil, err
153153
}

modules/git/languagestats/language_stats_gogit.go

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

88
import (
99
"bytes"
10+
"context"
1011
"io"
1112

1213
"code.gitea.io/gitea/modules/analyze"
@@ -21,7 +22,7 @@ import (
2122
)
2223

2324
// GetLanguageStats calculates language stats for git repository at specified commit
24-
func GetLanguageStats(repo *git_module.Repository, commitID string) (map[string]int64, error) {
25+
func GetLanguageStats(ctx context.Context, repo *git_module.Repository, commitID string) (map[string]int64, error) {
2526
r, err := git.PlainOpen(repo.Path)
2627
if err != nil {
2728
return nil, err
@@ -42,7 +43,7 @@ func GetLanguageStats(repo *git_module.Repository, commitID string) (map[string]
4243
return nil, err
4344
}
4445

45-
checker, err := attribute.NewBatchChecker(repo, commitID, attribute.LinguistAttributes)
46+
checker, err := attribute.NewBatchChecker(ctx, repo, commitID, attribute.LinguistAttributes)
4647
if err != nil {
4748
return nil, err
4849
}
@@ -67,7 +68,7 @@ func GetLanguageStats(repo *git_module.Repository, commitID string) (map[string]
6768
isDocumentation := optional.None[bool]()
6869
isDetectable := optional.None[bool]()
6970

70-
attrs, err := checker.CheckPath(f.Name)
71+
attrs, err := checker.CheckPath(ctx, f.Name)
7172
if err == nil {
7273
isVendored = attrs.GetVendored()
7374
if isVendored.ValueOrDefault(false) {

modules/git/last_commit_cache_gogit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (c *Commit) recursiveCache(ctx context.Context, index cgobject.CommitNode,
3232
return nil
3333
}
3434

35-
entries, err := tree.ListEntries()
35+
entries, err := tree.ListEntries(ctx)
3636
if err != nil {
3737
return err
3838
}
@@ -51,7 +51,7 @@ func (c *Commit) recursiveCache(ctx context.Context, index cgobject.CommitNode,
5151

5252
for entry := range commits {
5353
if entryMap[entry].IsDir() {
54-
subTree, err := tree.SubTree(entry)
54+
subTree, err := tree.SubTree(ctx, entry)
5555
if err != nil {
5656
return err
5757
}

modules/git/notes_gogit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
// FIXME: Add LastCommitCache support
2020
func GetNote(ctx context.Context, repo *Repository, commitID string, note *Note) error {
2121
log.Trace("Searching for git note corresponding to the commit %q in the repository %q", commitID, repo.Path)
22-
notes, err := repo.GetCommit(NotesRef)
22+
notes, err := repo.GetCommit(ctx, NotesRef)
2323
if err != nil {
2424
if IsErrNotExist(err) {
2525
return err

modules/git/pipeline/lfs_gogit.go

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

88
import (
99
"bufio"
10+
"context"
1011
"io"
1112
"sort"
1213
"strings"
@@ -20,7 +21,7 @@ import (
2021
)
2122

2223
// FindLFSFile finds commits that contain a provided pointer file hash
23-
func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, error) {
24+
func FindLFSFile(ctx context.Context, repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, error) {
2425
resultsMap := map[string]*LFSResult{}
2526
results := make([]*LFSResult, 0)
2627

@@ -105,7 +106,7 @@ func FindLFSFile(repo *git.Repository, objectID git.ObjectID) ([]*LFSResult, err
105106
i++
106107
}
107108
}()
108-
go NameRevStdin(repo.Ctx, shasToNameReader, nameRevStdinWriter, &wg, basePath)
109+
go NameRevStdin(ctx, shasToNameReader, nameRevStdinWriter, &wg, basePath)
109110
go func() {
110111
defer wg.Done()
111112
defer shasToNameWriter.Close()

modules/git/repo_base_gogit.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package git
88

99
import (
10-
"context"
1110
"path/filepath"
1211

1312
gitealog "code.gitea.io/gitea/modules/log"
@@ -34,13 +33,12 @@ type Repository struct {
3433
gogitStorage *filesystem.Storage
3534
gpgSettings *GPGSettings
3635

37-
Ctx context.Context
3836
LastCommitCache *LastCommitCache
3937
objectFormat ObjectFormat
4038
}
4139

4240
// OpenRepository opens the repository at the given path within the context.Context
43-
func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) {
41+
func OpenRepository(repoPath string) (*Repository, error) {
4442
repoPath, err := filepath.Abs(repoPath)
4543
if err != nil {
4644
return nil, err
@@ -80,7 +78,6 @@ func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) {
8078
gogitRepo: gogitRepo,
8179
gogitStorage: storage,
8280
tagCache: newObjectCache[*Tag](),
83-
Ctx: ctx,
8481
objectFormat: ParseGogitHash(plumbing.ZeroHash).Type(),
8582
}, nil
8683
}

modules/git/repo_branch_gogit.go

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

99
import (
10+
"context"
1011
"sort"
1112
"strings"
1213

@@ -17,9 +18,9 @@ import (
1718
// IsObjectExist returns true if the given object exists in the repository.
1819
// FIXME: Inconsistent behavior with nogogit edition
1920
// Unlike the implementation of IsObjectExist in nogogit edition, it does not support short hashes here.
20-
// For example, IsObjectExist("153f451") will return false, but it will return true in nogogit edition.
21+
// For example, IsObjectExist(ctx, "153f451") will return false, but it will return true in nogogit edition.
2122
// To fix this, the solution could be adding support for short hashes in gogit edition if it's really needed.
22-
func (repo *Repository) IsObjectExist(name string) bool {
23+
func (repo *Repository) IsObjectExist(ctx context.Context, name string) bool {
2324
if name == "" {
2425
return false
2526
}
@@ -33,7 +34,7 @@ func (repo *Repository) IsObjectExist(name string) bool {
3334
// Unlike the implementation of IsObjectExist in nogogit edition, it does not support blob hashes here.
3435
// For example, IsObjectExist([existing_blob_hash]) will return false, but it will return true in nogogit edition.
3536
// To fix this, the solution could be refusing to support blob hashes in nogogit edition since a blob hash is not a reference.
36-
func (repo *Repository) IsReferenceExist(name string) bool {
37+
func (repo *Repository) IsReferenceExist(ctx context.Context, name string) bool {
3738
if name == "" {
3839
return false
3940
}
@@ -44,7 +45,7 @@ func (repo *Repository) IsReferenceExist(name string) bool {
4445
}
4546

4647
// IsBranchExist returns true if given branch exists in current repository.
47-
func (repo *Repository) IsBranchExist(name string) bool {
48+
func (repo *Repository) IsBranchExist(ctx context.Context, name string) bool {
4849
if name == "" {
4950
return false
5051
}
@@ -60,7 +61,7 @@ func (repo *Repository) IsBranchExist(name string) bool {
6061
// Branches are returned with sort of `-committerdate` as the nogogit
6162
// implementation. This requires full fetch, sort and then the
6263
// skip/limit applies later as gogit returns in undefined order.
63-
func (repo *Repository) GetBranchNames(skip, limit int) ([]string, int, error) {
64+
func (repo *Repository) GetBranchNames(ctx context.Context, skip, limit int) ([]string, int, error) {
6465
type BranchData struct {
6566
name string
6667
committerDate int64
@@ -136,7 +137,7 @@ func (repo *Repository) WalkReferences(arg ObjectType, skip, limit int, walkfn f
136137
}
137138

138139
// GetRefsBySha returns all references filtered with prefix that belong to a sha commit hash
139-
func (repo *Repository) GetRefsBySha(sha, prefix string) ([]string, error) {
140+
func (repo *Repository) GetRefsBySha(ctx context.Context, sha, prefix string) ([]string, error) {
140141
var revList []string
141142
iter, err := repo.gogitRepo.References()
142143
if err != nil {

modules/git/repo_commit_gogit.go

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

99
import (
10+
"context"
1011
"strings"
1112

1213
"code.gitea.io/gitea/modules/git/gitcmd"
@@ -17,7 +18,7 @@ import (
1718
)
1819

1920
// GetRefCommitID returns the last commit ID string of given reference.
20-
func (repo *Repository) GetRefCommitID(name string) (string, error) {
21+
func (repo *Repository) GetRefCommitID(ctx context.Context, name string) (string, error) {
2122
if plumbing.IsHash(name) {
2223
return name, nil
2324
}
@@ -39,8 +40,8 @@ func (repo *Repository) GetRefCommitID(name string) (string, error) {
3940
}
4041

4142
// ConvertToHash returns a Hash object from a potential ID string
42-
func (repo *Repository) ConvertToGitID(commitID string) (ObjectID, error) {
43-
objectFormat, err := repo.GetObjectFormat()
43+
func (repo *Repository) ConvertToGitID(ctx context.Context, commitID string) (ObjectID, error) {
44+
objectFormat, err := repo.GetObjectFormat(ctx)
4445
if err != nil {
4546
return nil, err
4647
}
@@ -54,7 +55,7 @@ func (repo *Repository) ConvertToGitID(commitID string) (ObjectID, error) {
5455
actualCommitID, _, err := gitcmd.NewCommand("rev-parse", "--verify").
5556
AddDynamicArguments(commitID).
5657
WithDir(repo.Path).
57-
RunStdString(repo.Ctx)
58+
RunStdString(ctx)
5859
actualCommitID = strings.TrimSpace(actualCommitID)
5960
if err != nil {
6061
if strings.Contains(err.Error(), "unknown revision or path") ||
@@ -68,16 +69,16 @@ func (repo *Repository) ConvertToGitID(commitID string) (ObjectID, error) {
6869
}
6970

7071
// IsCommitExist returns true if given commit exists in current repository.
71-
func (repo *Repository) IsCommitExist(name string) bool {
72-
hash, err := repo.ConvertToGitID(name)
72+
func (repo *Repository) IsCommitExist(ctx context.Context, name string) bool {
73+
hash, err := repo.ConvertToGitID(ctx, name)
7374
if err != nil {
7475
return false
7576
}
7677
_, err = repo.gogitRepo.CommitObject(plumbing.Hash(hash.RawValue()))
7778
return err == nil
7879
}
7980

80-
func (repo *Repository) getCommit(id ObjectID) (*Commit, error) {
81+
func (repo *Repository) getCommit(ctx context.Context, id ObjectID) (*Commit, error) {
8182
var tagObject *object.Tag
8283

8384
commitID := plumbing.Hash(id.RawValue())

modules/git/repo_ref_gogit.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
package git
77

88
import (
9+
"context"
910
"strings"
1011

1112
"github.com/go-git/go-git/v5"
1213
"github.com/go-git/go-git/v5/plumbing"
1314
)
1415

1516
// GetRefsFiltered returns all references of the repository that matches patterm exactly or starting with.
16-
func (repo *Repository) GetRefsFiltered(pattern string) ([]*Reference, error) {
17+
func (repo *Repository) GetRefsFiltered(ctx context.Context, pattern string) ([]*Reference, error) {
1718
r, err := git.PlainOpen(repo.Path)
1819
if err != nil {
1920
return nil, err
@@ -30,7 +31,7 @@ func (repo *Repository) GetRefsFiltered(pattern string) ([]*Reference, error) {
3031
refType := string(ObjectCommit)
3132
if ref.Name().IsTag() {
3233
// tags can be of type `commit` (lightweight) or `tag` (annotated)
33-
if tagType, _ := repo.GetTagType(ParseGogitHash(ref.Hash())); err == nil {
34+
if tagType, _ := repo.GetTagType(ctx, ParseGogitHash(ref.Hash())); err == nil {
3435
refType = tagType
3536
}
3637
}

0 commit comments

Comments
 (0)