summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2017-12-02 15:34:39 +0800
committerGitHub <noreply@github.com>2017-12-02 15:34:39 +0800
commit35cc5b0402d46d672e02bbe1ad15d1460077e8f4 (patch)
tree47723925eb89e286f328503ae30e77ca1eaaf021 /modules
parent674422b642452050a7185f10908a9e8a86604f24 (diff)
downloadgitea-35cc5b0402d46d672e02bbe1ad15d1460077e8f4.tar.gz
gitea-35cc5b0402d46d672e02bbe1ad15d1460077e8f4.zip
Remove GetRepositoryByRef and add GetRepositoryByOwnerAndName (#3043)
* remove GetRepositoryByRef and add GetRepositoryByOwnerAndName * fix tests * fix tests bug * some improvements
Diffstat (limited to 'modules')
-rw-r--r--modules/context/context.go9
-rw-r--r--modules/lfs/server.go17
2 files changed, 9 insertions, 17 deletions
diff --git a/modules/context/context.go b/modules/context/context.go
index 6fb0a2cde3..10a84cd9b1 100644
--- a/modules/context/context.go
+++ b/modules/context/context.go
@@ -176,12 +176,9 @@ func Contexter() macaron.Handler {
repoName := c.Params(":reponame")
branchName := "master"
- owner, err := models.GetUserByName(ownerName)
- if err == nil {
- repo, err := models.GetRepositoryByName(owner.ID, repoName)
- if err == nil && len(repo.DefaultBranch) > 0 {
- branchName = repo.DefaultBranch
- }
+ repo, err := models.GetRepositoryByOwnerAndName(ownerName, repoName)
+ if err == nil && len(repo.DefaultBranch) > 0 {
+ branchName = repo.DefaultBranch
}
prefix := setting.AppURL + path.Join(ownerName, repoName, "src", "branch", branchName)
c.PlainText(http.StatusOK, []byte(com.Expand(`
diff --git a/modules/lfs/server.go b/modules/lfs/server.go
index 68f2af1519..474a3f56c3 100644
--- a/modules/lfs/server.go
+++ b/modules/lfs/server.go
@@ -108,10 +108,9 @@ func ObjectOidHandler(ctx *context.Context) {
}
func getAuthenticatedRepoAndMeta(ctx *context.Context, rv *RequestVars, requireWrite bool) (*models.LFSMetaObject, *models.Repository) {
- repositoryString := rv.User + "/" + rv.Repo
- repository, err := models.GetRepositoryByRef(repositoryString)
+ repository, err := models.GetRepositoryByOwnerAndName(rv.User, rv.Repo)
if err != nil {
- log.Debug("Could not find repository: %s - %s", repositoryString, err)
+ log.Debug("Could not find repository: %s/%s - %s", rv.User, rv.Repo, err)
writeStatus(ctx, 404)
return nil, nil
}
@@ -197,7 +196,6 @@ func getMetaHandler(ctx *context.Context) {
// PostHandler instructs the client how to upload data
func PostHandler(ctx *context.Context) {
-
if !setting.LFS.StartServer {
writeStatus(ctx, 404)
return
@@ -210,10 +208,9 @@ func PostHandler(ctx *context.Context) {
rv := unpack(ctx)
- repositoryString := rv.User + "/" + rv.Repo
- repository, err := models.GetRepositoryByRef(repositoryString)
+ repository, err := models.GetRepositoryByOwnerAndName(rv.User, rv.Repo)
if err != nil {
- log.Debug("Could not find repository: %s - %s", repositoryString, err)
+ log.Debug("Could not find repository: %s/%s - %s", rv.User, rv.Repo, err)
writeStatus(ctx, 404)
return
}
@@ -261,12 +258,10 @@ func BatchHandler(ctx *context.Context) {
// Create a response object
for _, object := range bv.Objects {
-
- repositoryString := object.User + "/" + object.Repo
- repository, err := models.GetRepositoryByRef(repositoryString)
+ repository, err := models.GetRepositoryByOwnerAndName(object.User, object.Repo)
if err != nil {
- log.Debug("Could not find repository: %s - %s", repositoryString, err)
+ log.Debug("Could not find repository: %s/%s - %s", object.User, object.Repo, err)
writeStatus(ctx, 404)
return
}