55package files
66
77import (
8+ "context"
89 "fmt"
910 "net/url"
1011 "path"
@@ -38,7 +39,7 @@ func (ct *ContentType) String() string {
3839
3940// GetContentsOrList gets the meta data of a file's contents (*ContentsResponse) if treePath not a tree
4041// directory, otherwise a listing of file contents ([]*ContentsResponse). Ref can be a branch, commit or tag
41- func GetContentsOrList (repo * models.Repository , treePath , ref string ) (interface {}, error ) {
42+ func GetContentsOrList (ctx context. Context , repo * models.Repository , treePath , ref string ) (interface {}, error ) {
4243 if repo .IsEmpty {
4344 return make ([]interface {}, 0 ), nil
4445 }
@@ -56,7 +57,7 @@ func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface
5657 }
5758 treePath = cleanTreePath
5859
59- gitRepo , err := git .OpenRepository ( repo .RepoPath ())
60+ gitRepo , err := git .OpenRepositoryCtx ( ctx , repo .RepoPath ())
6061 if err != nil {
6162 return nil , err
6263 }
@@ -74,7 +75,7 @@ func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface
7475 }
7576
7677 if entry .Type () != "tree" {
77- return GetContents (repo , treePath , origRef , false )
78+ return GetContents (ctx , repo , treePath , origRef , false )
7879 }
7980
8081 // We are in a directory, so we return a list of FileContentResponse objects
@@ -90,7 +91,7 @@ func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface
9091 }
9192 for _ , e := range entries {
9293 subTreePath := path .Join (treePath , e .Name ())
93- fileContentResponse , err := GetContents (repo , subTreePath , origRef , true )
94+ fileContentResponse , err := GetContents (ctx , repo , subTreePath , origRef , true )
9495 if err != nil {
9596 return nil , err
9697 }
@@ -100,7 +101,7 @@ func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface
100101}
101102
102103// GetContents gets the meta data on a file's contents. Ref can be a branch, commit or tag
103- func GetContents (repo * models.Repository , treePath , ref string , forList bool ) (* api.ContentsResponse , error ) {
104+ func GetContents (ctx context. Context , repo * models.Repository , treePath , ref string , forList bool ) (* api.ContentsResponse , error ) {
104105 if ref == "" {
105106 ref = repo .DefaultBranch
106107 }
@@ -115,7 +116,7 @@ func GetContents(repo *models.Repository, treePath, ref string, forList bool) (*
115116 }
116117 treePath = cleanTreePath
117118
118- gitRepo , err := git .OpenRepository ( repo .RepoPath ())
119+ gitRepo , err := git .OpenRepositoryCtx ( ctx , repo .RepoPath ())
119120 if err != nil {
120121 return nil , err
121122 }
@@ -162,7 +163,7 @@ func GetContents(repo *models.Repository, treePath, ref string, forList bool) (*
162163 // Now populate the rest of the ContentsResponse based on entry type
163164 if entry .IsRegular () || entry .IsExecutable () {
164165 contentsResponse .Type = string (ContentTypeRegular )
165- if blobResponse , err := GetBlobBySHA (repo , entry .ID .String ()); err != nil {
166+ if blobResponse , err := GetBlobBySHA (ctx , repo , entry .ID .String ()); err != nil {
166167 return nil , err
167168 } else if ! forList {
168169 // We don't show the content if we are getting a list of FileContentResponses
@@ -218,8 +219,8 @@ func GetContents(repo *models.Repository, treePath, ref string, forList bool) (*
218219}
219220
220221// GetBlobBySHA get the GitBlobResponse of a repository using a sha hash.
221- func GetBlobBySHA (repo * models.Repository , sha string ) (* api.GitBlobResponse , error ) {
222- gitRepo , err := git .OpenRepository ( repo .RepoPath ())
222+ func GetBlobBySHA (ctx context. Context , repo * models.Repository , sha string ) (* api.GitBlobResponse , error ) {
223+ gitRepo , err := git .OpenRepositoryCtx ( ctx , repo .RepoPath ())
223224 if err != nil {
224225 return nil , err
225226 }
0 commit comments