diff options
Diffstat (limited to 'internal/route/api/v1/repo/commits.go')
-rw-r--r-- | internal/route/api/v1/repo/commits.go | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/internal/route/api/v1/repo/commits.go b/internal/route/api/v1/repo/commits.go index ddcd09b7..b3903053 100644 --- a/internal/route/api/v1/repo/commits.go +++ b/internal/route/api/v1/repo/commits.go @@ -16,6 +16,7 @@ import ( "gogs.io/gogs/internal/context" "gogs.io/gogs/internal/db" "gogs.io/gogs/internal/db/errors" + "gogs.io/gogs/internal/gitutil" ) func GetSingleCommit(c *context.APIContext) { @@ -25,14 +26,14 @@ func GetSingleCommit(c *context.APIContext) { return } - gitRepo, err := git.OpenRepository(c.Repo.Repository.RepoPath()) + gitRepo, err := git.Open(c.Repo.Repository.RepoPath()) if err != nil { - c.ServerError("OpenRepository", err) + c.ServerError("open repository", err) return } - commit, err := gitRepo.GetCommit(c.Params(":sha")) + commit, err := gitRepo.CatFileCommit(c.Params(":sha")) if err != nil { - c.NotFoundOrServerError("GetCommit", git.IsErrNotExist, err) + c.NotFoundOrServerError("get commit", gitutil.IsErrRevisionNotExist, err) return } @@ -59,8 +60,8 @@ func GetSingleCommit(c *context.APIContext) { } // Retrieve parent(s) of the commit - apiParents := make([]*api.CommitMeta, commit.ParentCount()) - for i := 0; i < commit.ParentCount(); i++ { + apiParents := make([]*api.CommitMeta, commit.ParentsCount()) + for i := 0; i < commit.ParentsCount(); i++ { sha, _ := commit.ParentID(i) apiParents[i] = &api.CommitMeta{ URL: c.BaseURL + "/repos/" + c.Repo.Repository.FullName() + "/commits/" + sha.String(), @@ -99,24 +100,24 @@ func GetSingleCommit(c *context.APIContext) { } func GetReferenceSHA(c *context.APIContext) { - gitRepo, err := git.OpenRepository(c.Repo.Repository.RepoPath()) + gitRepo, err := git.Open(c.Repo.Repository.RepoPath()) if err != nil { - c.ServerError("OpenRepository", err) + c.ServerError("open repository", err) return } ref := c.Params("*") - refType := 0 // 0-undetermined, 1-branch, 2-tag - if strings.HasPrefix(ref, git.BRANCH_PREFIX) { - ref = strings.TrimPrefix(ref, git.BRANCH_PREFIX) + refType := 0 // 0-unknown, 1-branch, 2-tag + if strings.HasPrefix(ref, git.RefsHeads) { + ref = strings.TrimPrefix(ref, git.RefsHeads) refType = 1 - } else if strings.HasPrefix(ref, git.TAG_PREFIX) { - ref = strings.TrimPrefix(ref, git.TAG_PREFIX) + } else if strings.HasPrefix(ref, git.RefsTags) { + ref = strings.TrimPrefix(ref, git.RefsTags) refType = 2 } else { - if gitRepo.IsBranchExist(ref) { + if gitRepo.HasBranch(ref) { refType = 1 - } else if gitRepo.IsTagExist(ref) { + } else if gitRepo.HasTag(ref) { refType = 2 } else { c.NotFound() @@ -126,12 +127,12 @@ func GetReferenceSHA(c *context.APIContext) { var sha string if refType == 1 { - sha, err = gitRepo.GetBranchCommitID(ref) + sha, err = gitRepo.BranchCommitID(ref) } else if refType == 2 { - sha, err = gitRepo.GetTagCommitID(ref) + sha, err = gitRepo.TagCommitID(ref) } if err != nil { - c.NotFoundOrServerError("get reference commit ID", git.IsErrNotExist, err) + c.NotFoundOrServerError("get reference commit ID", gitutil.IsErrRevisionNotExist, err) return } c.PlainText(http.StatusOK, []byte(sha)) |