Skip to content

Commit 4f1709b

Browse files
committed
add context to LsTree
1 parent d2c85c4 commit 4f1709b

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

modules/git/tree.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ func (t *Tree) SubTree(rpath string) (*Tree, error) {
4848
}
4949

5050
// LsTree checks if the given filenames are in the tree
51-
func (repo *Repository) LsTree(ref string, filenames ...string) ([]string, error) {
51+
func (repo *Repository) LsTree(ctx context.Context, ref string, filenames ...string) ([]string, error) {
5252
cmd := NewCommand("ls-tree", "-z", "--name-only").
5353
AddDashesAndList(append([]string{ref}, filenames...)...)
5454

55-
res, _, err := cmd.RunStdBytes(repo.Ctx, &RunOpts{Dir: repo.Path})
55+
res, _, err := cmd.RunStdBytes(ctx, &RunOpts{Dir: repo.Path})
5656
if err != nil {
5757
return nil, err
5858
}

services/wiki/wiki.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ func InitWiki(ctx context.Context, repo *repo_model.Repository) error {
5151

5252
// prepareGitPath try to find a suitable file path with file name by the given raw wiki name.
5353
// return: existence, prepared file path with name, error
54-
func prepareGitPath(gitRepo *git.Repository, defaultWikiBranch string, wikiPath WebPath) (bool, string, error) {
54+
func prepareGitPath(ctx context.Context, gitRepo *git.Repository, defaultWikiBranch string, wikiPath WebPath) (bool, string, error) {
5555
unescaped := string(wikiPath) + ".md"
5656
gitPath := WebPathToGitPath(wikiPath)
5757

5858
// Look for both files
59-
filesInIndex, err := gitRepo.LsTree(defaultWikiBranch, unescaped, gitPath)
59+
filesInIndex, err := gitRepo.LsTree(ctx, defaultWikiBranch, unescaped, gitPath)
6060
if err != nil {
6161
if strings.Contains(err.Error(), "Not a valid object name") {
6262
return false, gitPath, nil // branch doesn't exist
@@ -140,7 +140,7 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
140140
}
141141
}
142142

143-
isWikiExist, newWikiPath, err := prepareGitPath(gitRepo, repo.DefaultWikiBranch, newWikiName)
143+
isWikiExist, newWikiPath, err := prepareGitPath(ctx, gitRepo, repo.DefaultWikiBranch, newWikiName)
144144
if err != nil {
145145
return err
146146
}
@@ -156,7 +156,7 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
156156
isOldWikiExist := true
157157
oldWikiPath := newWikiPath
158158
if oldWikiName != newWikiName {
159-
isOldWikiExist, oldWikiPath, err = prepareGitPath(gitRepo, repo.DefaultWikiBranch, oldWikiName)
159+
isOldWikiExist, oldWikiPath, err = prepareGitPath(ctx, gitRepo, repo.DefaultWikiBranch, oldWikiName)
160160
if err != nil {
161161
return err
162162
}
@@ -295,7 +295,7 @@ func DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
295295
return fmt.Errorf("unable to read HEAD tree to index in: %s %w", basePath, err)
296296
}
297297

298-
found, wikiPath, err := prepareGitPath(gitRepo, repo.DefaultWikiBranch, wikiName)
298+
found, wikiPath, err := prepareGitPath(ctx, gitRepo, repo.DefaultWikiBranch, wikiName)
299299
if err != nil {
300300
return err
301301
}

services/wiki/wiki_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func TestPrepareWikiFileName(t *testing.T) {
278278
for _, tt := range tests {
279279
t.Run(tt.name, func(t *testing.T) {
280280
webPath := UserTitleToWebPath("", tt.arg)
281-
existence, newWikiPath, err := prepareGitPath(gitRepo, repo.DefaultWikiBranch, webPath)
281+
existence, newWikiPath, err := prepareGitPath(git.DefaultContext, gitRepo, repo.DefaultWikiBranch, webPath)
282282
if (err != nil) != tt.wantErr {
283283
assert.NoError(t, err)
284284
return
@@ -309,7 +309,7 @@ func TestPrepareWikiFileName_FirstPage(t *testing.T) {
309309

310310
defer gitRepo.Close()
311311

312-
existence, newWikiPath, err := prepareGitPath(gitRepo, "master", "Home")
312+
existence, newWikiPath, err := prepareGitPath(git.DefaultContext, gitRepo, "master", "Home")
313313
assert.False(t, existence)
314314
assert.NoError(t, err)
315315
assert.EqualValues(t, "Home.md", newWikiPath)

0 commit comments

Comments
 (0)