Skip to content

Commit ec7ffbf

Browse files
committed
add context to getTree
1 parent fa34fff commit ec7ffbf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+111
-104
lines changed

modules/actions/workflows.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ func IsWorkflow(path string) bool {
4444
return strings.HasPrefix(path, ".gitea/workflows") || strings.HasPrefix(path, ".github/workflows")
4545
}
4646

47-
func ListWorkflows(commit *git.Commit) (git.Entries, error) {
48-
tree, err := commit.SubTree(".gitea/workflows")
47+
func ListWorkflows(ctx context.Context, commit *git.Commit) (git.Entries, error) {
48+
tree, err := commit.SubTree(ctx, ".gitea/workflows")
4949
if _, ok := err.(git.ErrNotExist); ok {
50-
tree, err = commit.SubTree(".github/workflows")
50+
tree, err = commit.SubTree(ctx, ".github/workflows")
5151
}
5252
if _, ok := err.(git.ErrNotExist); ok {
5353
return nil, nil
@@ -104,7 +104,7 @@ func DetectWorkflows(
104104
payload api.Payloader,
105105
detectSchedule bool,
106106
) ([]*DetectedWorkflow, []*DetectedWorkflow, error) {
107-
entries, err := ListWorkflows(commit)
107+
entries, err := ListWorkflows(ctx, commit)
108108
if err != nil {
109109
return nil, nil, err
110110
}
@@ -149,7 +149,7 @@ func DetectWorkflows(
149149
}
150150

151151
func DetectScheduledWorkflows(ctx context.Context, gitRepo *git.Repository, commit *git.Commit) ([]*DetectedWorkflow, error) {
152-
entries, err := ListWorkflows(commit)
152+
entries, err := ListWorkflows(ctx, commit)
153153
if err != nil {
154154
return nil, err
155155
}

modules/git/blame.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func CreateBlameReader(ctx context.Context, objectFormat ObjectFormat, repoPath
181181
}
182182

183183
func tryCreateBlameIgnoreRevsFile(ctx context.Context, commit *Commit) *string {
184-
entry, err := commit.GetTreeEntryByPath(".git-blame-ignore-revs")
184+
entry, err := commit.GetTreeEntryByPath(ctx, ".git-blame-ignore-revs")
185185
if err != nil {
186186
return nil
187187
}

modules/git/commit.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@ func (c *Commit) FileChangedSinceCommit(ctx context.Context, filename, pastCommi
319319

320320
// HasFile returns true if the file given exists on this commit
321321
// This does only mean it's there - it does not mean the file was changed during the commit.
322-
func (c *Commit) HasFile(filename string) (bool, error) {
323-
_, err := c.GetBlobByPath(filename)
322+
func (c *Commit) HasFile(ctx context.Context, filename string) (bool, error) {
323+
_, err := c.GetBlobByPath(ctx, filename)
324324
if err != nil {
325325
return false, err
326326
}
@@ -329,7 +329,7 @@ func (c *Commit) HasFile(filename string) (bool, error) {
329329

330330
// GetFileContent reads a file content as a string or returns false if this was not possible
331331
func (c *Commit) GetFileContent(ctx context.Context, filename string, limit int) (string, error) {
332-
entry, err := c.GetTreeEntryByPath(filename)
332+
entry, err := c.GetTreeEntryByPath(ctx, filename)
333333
if err != nil {
334334
return "", err
335335
}

modules/git/commit_info_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func testGetCommitsInfo(t *testing.T, repo1 *Repository) {
6464
assert.NotNil(t, commit.Tree)
6565
assert.NotNil(t, commit.Tree.repo)
6666

67-
tree, err := commit.Tree.SubTree(testCase.Path)
67+
tree, err := commit.Tree.SubTree(t.Context(), testCase.Path)
6868
if err != nil {
6969
assert.NoError(t, err, "Unable to get subtree: %s of commit: %s from testcase due to error: %v", testCase.Path, testCase.CommitID, err)
7070
// no point trying to do anything else for this test.

modules/git/commit_submodule.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func (c *Commit) GetSubModules(ctx context.Context) (*ObjectCache[*SubModule], e
1515
return c.submoduleCache, nil
1616
}
1717

18-
entry, err := c.GetTreeEntryByPath(".gitmodules")
18+
entry, err := c.GetTreeEntryByPath(ctx, ".gitmodules")
1919
if err != nil {
2020
if _, ok := err.(ErrNotExist); ok {
2121
return nil, nil

modules/git/last_commit_cache_gogit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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/last_commit_cache_nogogit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (c *Commit) recursiveCache(ctx context.Context, tree *Tree, treePath string
4040
for _, treeEntry := range entries {
4141
// entryMap won't contain "" therefore skip this.
4242
if treeEntry.IsDir() {
43-
subTree, err := tree.SubTree(treeEntry.Name())
43+
subTree, err := tree.SubTree(ctx, treeEntry.Name())
4444
if err != nil {
4545
return err
4646
}

modules/git/log_name_status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func (g *LogNameStatusRepoParser) Close() {
295295
func WalkGitLog(ctx context.Context, repo *Repository, head *Commit, treepath string, paths ...string) (map[string]string, error) {
296296
headRef := head.ID.String()
297297

298-
tree, err := head.SubTree(treepath)
298+
tree, err := head.SubTree(ctx, treepath)
299299
if err != nil {
300300
return nil, err
301301
}

modules/git/notes_nogogit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ func GetNote(ctx context.Context, repo *Repository, commitID string, note *Note)
3434
var entry *TreeEntry
3535
originalCommitID := commitID
3636
for len(commitID) > 2 {
37-
entry, err = tree.GetTreeEntryByPath(commitID)
37+
entry, err = tree.GetTreeEntryByPath(ctx, commitID)
3838
if err == nil {
3939
path += commitID
4040
break
4141
}
4242
if IsErrNotExist(err) {
43-
tree, err = tree.SubTree(commitID[0:2])
43+
tree, err = tree.SubTree(ctx, commitID[0:2])
4444
path += commitID[0:2] + "/"
4545
commitID = commitID[2:]
4646
}

modules/git/repo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ type GPGSettings struct {
3232
const prettyLogFormat = `--pretty=format:%H`
3333

3434
// GetAllCommitsCount returns count of all commits in repository
35-
func (repo *Repository) GetAllCommitsCount() (int64, error) {
36-
return AllCommitsCount(repo.Ctx, repo.Path, false)
35+
func (repo *Repository) GetAllCommitsCount(ctx context.Context) (int64, error) {
36+
return AllCommitsCount(ctx, repo.Path, false)
3737
}
3838

3939
func (repo *Repository) parsePrettyFormatLogToList(logs []byte) ([]*Commit, error) {

0 commit comments

Comments
 (0)