Skip to content

Commit ea27930

Browse files
committed
add context to GetTreePathLatestCommit
1 parent 1611740 commit ea27930

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

modules/git/tree.go

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

77
import (
88
"bytes"
9+
"context"
910
"strings"
1011
)
1112

@@ -64,10 +65,10 @@ func (repo *Repository) LsTree(ref string, filenames ...string) ([]string, error
6465
}
6566

6667
// GetTreePathLatestCommit returns the latest commit of a tree path
67-
func (repo *Repository) GetTreePathLatestCommit(refName, treePath string) (*Commit, error) {
68+
func (repo *Repository) GetTreePathLatestCommit(ctx context.Context, refName, treePath string) (*Commit, error) {
6869
stdout, _, err := NewCommand("rev-list", "-1").
6970
AddDynamicArguments(refName).AddDashesAndList(treePath).
70-
RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path})
71+
RunStdString(ctx, &RunOpts{Dir: repo.Path})
7172
if err != nil {
7273
return nil, err
7374
}

modules/git/tree_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func Test_GetTreePathLatestCommit(t *testing.T) {
3535
assert.NoError(t, err)
3636
assert.EqualValues(t, "544d8f7a3b15927cddf2299b4b562d6ebd71b6a7", commitID)
3737

38-
commit, err := repo.GetTreePathLatestCommit("master", "blame.txt")
38+
commit, err := repo.GetTreePathLatestCommit(t.Context(), "master", "blame.txt")
3939
assert.NoError(t, err)
4040
assert.NotNil(t, commit)
4141
assert.EqualValues(t, "45fb6cbc12f970b04eacd5cd4165edd11c8d7376", commit.ID.String())

routers/api/v1/repo/file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func getBlobForEntry(ctx *context.APIContext) (blob *git.Blob, entry *git.TreeEn
241241
return nil, nil, nil
242242
}
243243

244-
latestCommit, err := ctx.Repo.GitRepo.GetTreePathLatestCommit(ctx.Repo.Commit.ID.String(), ctx.Repo.TreePath)
244+
latestCommit, err := ctx.Repo.GitRepo.GetTreePathLatestCommit(ctx, ctx.Repo.Commit.ID.String(), ctx.Repo.TreePath)
245245
if err != nil {
246246
ctx.APIErrorInternal(err)
247247
return nil, nil, nil

routers/web/repo/download.go

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

100-
latestCommit, err := ctx.Repo.GitRepo.GetTreePathLatestCommit(ctx.Repo.Commit.ID.String(), ctx.Repo.TreePath)
100+
latestCommit, err := ctx.Repo.GitRepo.GetTreePathLatestCommit(ctx, ctx.Repo.Commit.ID.String(), ctx.Repo.TreePath)
101101
if err != nil {
102102
ctx.ServerError("GetTreePathLatestCommit", err)
103103
return nil, nil

0 commit comments

Comments
 (0)