summaryrefslogtreecommitdiffstats
path: root/modules/repofiles/tree.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/repofiles/tree.go')
-rw-r--r--modules/repofiles/tree.go11
1 files changed, 7 insertions, 4 deletions
diff --git a/modules/repofiles/tree.go b/modules/repofiles/tree.go
index 4eb54a2598..318a5d152d 100644
--- a/modules/repofiles/tree.go
+++ b/modules/repofiles/tree.go
@@ -16,6 +16,9 @@ import (
// GetTreeBySHA get the GitTreeResponse of a repository using a sha hash.
func GetTreeBySHA(repo *models.Repository, sha string, page, perPage int, recursive bool) (*api.GitTreeResponse, error) {
gitRepo, err := git.OpenRepository(repo.RepoPath())
+ if err != nil {
+ return nil, err
+ }
gitTree, err := gitRepo.GetTree(sha)
if err != nil || gitTree == nil {
return nil, models.ErrSHANotFound{
@@ -39,12 +42,12 @@ func GetTreeBySHA(repo *models.Repository, sha string, page, perPage int, recurs
// 51 is len(sha1) + len("/git/blobs/"). 40 + 11.
blobURL := make([]byte, apiURLLen+51)
- copy(blobURL[:], apiURL)
+ copy(blobURL, apiURL)
copy(blobURL[apiURLLen:], "/git/blobs/")
// 51 is len(sha1) + len("/git/trees/"). 40 + 11.
treeURL := make([]byte, apiURLLen+51)
- copy(treeURL[:], apiURL)
+ copy(treeURL, apiURL)
copy(treeURL[apiURLLen:], "/git/trees/")
// 40 is the size of the sha1 hash in hexadecimal format.
@@ -83,10 +86,10 @@ func GetTreeBySHA(repo *models.Repository, sha string, page, perPage int, recurs
if entries[e].IsDir() {
copy(treeURL[copyPos:], entries[e].ID.String())
- tree.Entries[i].URL = string(treeURL[:])
+ tree.Entries[i].URL = string(treeURL)
} else {
copy(blobURL[copyPos:], entries[e].ID.String())
- tree.Entries[i].URL = string(blobURL[:])
+ tree.Entries[i].URL = string(blobURL)
}
}
return tree, nil