summaryrefslogtreecommitdiffstats
path: root/routers/repo
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-05-25 20:11:25 -0400
committerUnknown <joe2010xtmf@163.com>2014-05-25 20:11:25 -0400
commit688ec6ecbdf0e1c450aa93fdc4d760c4ae63a73f (patch)
tree8adb59c369d1fe1bd41ae7be38785dc613a29a91 /routers/repo
parent87854c95a90cf1bebe1bffb833389471fb35f234 (diff)
downloadgitea-688ec6ecbdf0e1c450aa93fdc4d760c4ae63a73f.tar.gz
gitea-688ec6ecbdf0e1c450aa93fdc4d760c4ae63a73f.zip
Fixed #209
Diffstat (limited to 'routers/repo')
-rw-r--r--routers/repo/branch.go7
-rw-r--r--routers/repo/commit.go24
-rw-r--r--routers/repo/download.go21
-rw-r--r--routers/repo/git.go55
-rw-r--r--routers/repo/http.go27
-rw-r--r--routers/repo/issue.go5
-rw-r--r--routers/repo/setting.go3
7 files changed, 34 insertions, 108 deletions
diff --git a/routers/repo/branch.go b/routers/repo/branch.go
index 92265d2e56..2e2ae69254 100644
--- a/routers/repo/branch.go
+++ b/routers/repo/branch.go
@@ -11,9 +11,12 @@ import (
)
func Branches(ctx *middleware.Context, params martini.Params) {
+ ctx.Data["Title"] = "Branches"
+ ctx.Data["IsRepoToolbarBranches"] = true
+
brs, err := ctx.Repo.GitRepo.GetBranches()
if err != nil {
- ctx.Handle(404, "repo.Branches", err)
+ ctx.Handle(500, "repo.Branches", err)
return
} else if len(brs) == 0 {
ctx.Handle(404, "repo.Branches", nil)
@@ -21,7 +24,5 @@ func Branches(ctx *middleware.Context, params martini.Params) {
}
ctx.Data["Branches"] = brs
- ctx.Data["IsRepoToolbarBranches"] = true
-
ctx.HTML(200, "repo/branches")
}
diff --git a/routers/repo/commit.go b/routers/repo/commit.go
index 88b6593e76..44427b8a42 100644
--- a/routers/repo/commit.go
+++ b/routers/repo/commit.go
@@ -15,6 +15,8 @@ import (
)
func Commits(ctx *middleware.Context, params martini.Params) {
+ ctx.Data["IsRepoToolbarCommits"] = true
+
userName := ctx.Repo.Owner.Name
repoName := ctx.Repo.Repository.Name
@@ -47,8 +49,8 @@ func Commits(ctx *middleware.Context, params martini.Params) {
nextPage = 0
}
- //both `git log branchName` and `git log commitId` work
- commits, err := ctx.Repo.Commit.CommitsByRange(page)
+ // Both `git log branchName` and `git log commitId` work.
+ ctx.Data["Commits"], err = ctx.Repo.Commit.CommitsByRange(page)
if err != nil {
ctx.Handle(500, "repo.Commits(CommitsByRange)", err)
return
@@ -57,14 +59,14 @@ func Commits(ctx *middleware.Context, params martini.Params) {
ctx.Data["Username"] = userName
ctx.Data["Reponame"] = repoName
ctx.Data["CommitCount"] = commitsCount
- ctx.Data["Commits"] = commits
ctx.Data["LastPageNum"] = lastPage
ctx.Data["NextPageNum"] = nextPage
- ctx.Data["IsRepoToolbarCommits"] = true
ctx.HTML(200, "repo/commits")
}
func Diff(ctx *middleware.Context, params martini.Params) {
+ ctx.Data["IsRepoToolbarCommits"] = true
+
userName := ctx.Repo.Owner.Name
repoName := ctx.Repo.Repository.Name
commitId := ctx.Repo.CommitId
@@ -109,13 +111,15 @@ func Diff(ctx *middleware.Context, params martini.Params) {
ctx.Data["Diff"] = diff
ctx.Data["Parents"] = parents
ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0
- ctx.Data["IsRepoToolbarCommits"] = true
ctx.Data["SourcePath"] = "/" + path.Join(userName, repoName, "src", commitId)
ctx.Data["RawPath"] = "/" + path.Join(userName, repoName, "raw", commitId)
ctx.HTML(200, "repo/diff")
}
func SearchCommits(ctx *middleware.Context, params martini.Params) {
+ ctx.Data["IsSearchPage"] = true
+ ctx.Data["IsRepoToolbarCommits"] = true
+
keyword := ctx.Query("q")
if len(keyword) == 0 {
ctx.Redirect(ctx.Repo.RepoLink + "/commits/" + ctx.Repo.BranchName)
@@ -145,12 +149,12 @@ func SearchCommits(ctx *middleware.Context, params martini.Params) {
ctx.Data["Reponame"] = repoName
ctx.Data["CommitCount"] = commits.Len()
ctx.Data["Commits"] = commits
- ctx.Data["IsSearchPage"] = true
- ctx.Data["IsRepoToolbarCommits"] = true
ctx.HTML(200, "repo/commits")
}
func FileHistory(ctx *middleware.Context, params martini.Params) {
+ ctx.Data["IsRepoToolbarCommits"] = true
+
fileName := params["_1"]
if len(fileName) == 0 {
Commits(ctx, params)
@@ -194,8 +198,8 @@ func FileHistory(ctx *middleware.Context, params martini.Params) {
nextPage = 0
}
- //both `git log branchName` and `git log commitId` work
- commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(branchName, fileName, page)
+ ctx.Data["Commits"], err = ctx.Repo.GitRepo.CommitsByFileAndRange(
+ branchName, fileName, page)
if err != nil {
ctx.Handle(500, "repo.FileHistory(CommitsByRange)", err)
return
@@ -205,9 +209,7 @@ func FileHistory(ctx *middleware.Context, params martini.Params) {
ctx.Data["Reponame"] = repoName
ctx.Data["FileName"] = fileName
ctx.Data["CommitCount"] = commitsCount
- ctx.Data["Commits"] = commits
ctx.Data["LastPageNum"] = lastPage
ctx.Data["NextPageNum"] = nextPage
- ctx.Data["IsRepoToolbarCommits"] = true
ctx.HTML(200, "repo/commits")
}
diff --git a/routers/repo/download.go b/routers/repo/download.go
index e5ec1c79f1..5df78dc7d8 100644
--- a/routers/repo/download.go
+++ b/routers/repo/download.go
@@ -18,18 +18,17 @@ import (
)
func SingleDownload(ctx *middleware.Context, params martini.Params) {
- // Get tree path
treename := params["_1"]
blob, err := ctx.Repo.Commit.GetBlobByPath(treename)
if err != nil {
- ctx.Handle(404, "repo.SingleDownload(GetBlobByPath)", err)
+ ctx.Handle(500, "repo.SingleDownload(GetBlobByPath)", err)
return
}
data, err := blob.Data()
if err != nil {
- ctx.Handle(404, "repo.SingleDownload(Data)", err)
+ ctx.Handle(500, "repo.SingleDownload(Data)", err)
return
}
@@ -47,8 +46,8 @@ func ZipDownload(ctx *middleware.Context, params martini.Params) {
commitId := ctx.Repo.CommitId
archivesPath := filepath.Join(ctx.Repo.GitRepo.Path, "archives/zip")
if !com.IsDir(archivesPath) {
- if err := os.MkdirAll(archivesPath, 0755); err != nil {
- ctx.Handle(404, "ZipDownload -> os.Mkdir(archivesPath)", err)
+ if err := os.MkdirAll(archivesPath, 0655); err != nil {
+ ctx.Handle(500, "ZipDownload -> os.Mkdir(archivesPath)", err)
return
}
}
@@ -60,9 +59,8 @@ func ZipDownload(ctx *middleware.Context, params martini.Params) {
return
}
- err := ctx.Repo.Commit.CreateArchive(archivePath, git.AT_ZIP)
- if err != nil {
- ctx.Handle(404, "ZipDownload -> CreateArchive "+archivePath, err)
+ if err := ctx.Repo.Commit.CreateArchive(archivePath, git.AT_ZIP); err != nil {
+ ctx.Handle(500, "ZipDownload -> CreateArchive "+archivePath, err)
return
}
@@ -74,7 +72,7 @@ func TarGzDownload(ctx *middleware.Context, params martini.Params) {
archivesPath := filepath.Join(ctx.Repo.GitRepo.Path, "archives/targz")
if !com.IsDir(archivesPath) {
if err := os.MkdirAll(archivesPath, 0755); err != nil {
- ctx.Handle(404, "TarGzDownload -> os.Mkdir(archivesPath)", err)
+ ctx.Handle(500, "TarGzDownload -> os.Mkdir(archivesPath)", err)
return
}
}
@@ -86,9 +84,8 @@ func TarGzDownload(ctx *middleware.Context, params martini.Params) {
return
}
- err := ctx.Repo.Commit.CreateArchive(archivePath, git.AT_TARGZ)
- if err != nil {
- ctx.Handle(404, "TarGzDownload -> CreateArchive "+archivePath, err)
+ if err := ctx.Repo.Commit.CreateArchive(archivePath, git.AT_TARGZ); err != nil {
+ ctx.Handle(500, "TarGzDownload -> CreateArchive "+archivePath, err)
return
}
diff --git a/routers/repo/git.go b/routers/repo/git.go
deleted file mode 100644
index 30c1042e0a..0000000000
--- a/routers/repo/git.go
+++ /dev/null
@@ -1,55 +0,0 @@
-package repo
-
-import (
- "fmt"
- "strings"
-)
-
-const advertise_refs = "--advertise-refs"
-
-func command(cmd string, opts ...string) string {
- return fmt.Sprintf("git %s %s", cmd, strings.Join(opts, " "))
-}
-
-/*func upload_pack(repository_path string, opts ...string) string {
- cmd = "upload-pack"
- opts = append(opts, "--stateless-rpc", repository_path)
- return command(cmd, opts...)
-}
-
-func receive_pack(repository_path string, opts ...string) string {
- cmd = "receive-pack"
- opts = append(opts, "--stateless-rpc", repository_path)
- return command(cmd, opts...)
-}*/
-
-/*func update_server_info(repository_path, opts = {}, &block)
- cmd = "update-server-info"
- args = []
- opts.each {|k,v| args << command_options[k] if command_options.has_key?(k) }
- opts[:args] = args
- Dir.chdir(repository_path) do # "git update-server-info" does not take a parameter to specify the repository, so set the working directory to the repository
- self.command(cmd, opts, &block)
- end
- end
-
- def get_config_setting(repository_path, key)
- path = get_config_location(repository_path)
- raise "Config file could not be found for repository in #{repository_path}." unless path
- self.command("config", {:args => ["-f #{path}", key]}).chomp
- end
-
- def get_config_location(repository_path)
- non_bare = File.join(repository_path,'.git') # This is where the config file will be if the repository is non-bare
- if File.exists?(non_bare) then # The repository is non-bare
- non_bare_config = File.join(non_bare, 'config')
- return non_bare_config if File.exists?(non_bare_config)
- else # We are dealing with a bare repository
- bare_config = File.join(repository_path, "config")
- return bare_config if File.exists?(bare_config)
- end
- return nil
- end
-
- end
-*/
diff --git a/routers/repo/http.go b/routers/repo/http.go
index a6189ff2c3..f4cc00aaf3 100644
--- a/routers/repo/http.go
+++ b/routers/repo/http.go
@@ -22,8 +22,8 @@ import (
"github.com/go-martini/martini"
"github.com/gogits/gogs/models"
- "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/middleware"
+ "github.com/gogits/gogs/modules/setting"
)
func Http(ctx *middleware.Context, params martini.Params) {
@@ -59,7 +59,7 @@ func Http(ctx *middleware.Context, params martini.Params) {
// only public pull don't need auth
isPublicPull := !repo.IsPrivate && isPull
- var askAuth = !isPublicPull || base.Service.RequireSignInView
+ var askAuth = !isPublicPull || setting.Service.RequireSignInView
var authUser *models.User
var authUsername, passwd string
@@ -123,7 +123,7 @@ func Http(ctx *middleware.Context, params martini.Params) {
}
}
- config := Config{base.RepoRootPath, "git", true, true, func(rpc string, input []byte) {
+ config := Config{setting.RepoRootPath, "git", true, true, func(rpc string, input []byte) {
if rpc == "receive-pack" {
firstLine := bytes.IndexRune(input, '\000')
if firstLine > -1 {
@@ -141,16 +141,6 @@ func Http(ctx *middleware.Context, params martini.Params) {
handler := HttpBackend(&config)
handler(ctx.ResponseWriter, ctx.Req)
-
- /* Webdav
- dir := models.RepoPath(username, reponame)
-
- prefix := path.Join("/", username, params["reponame"])
- server := webdav.NewServer(
- dir, prefix, true)
-
- server.ServeHTTP(ctx.ResponseWriter, ctx.Req)
- */
}
type route struct {
@@ -483,14 +473,3 @@ func hdrCacheForever(w http.ResponseWriter) {
w.Header().Set("Expires", fmt.Sprintf("%d", expires))
w.Header().Set("Cache-Control", "public, max-age=31536000")
}
-
-// Main
-/*
-func main() {
- http.HandleFunc("/", requestHandler())
-
- err := http.ListenAndServe(":8080", nil)
- if err != nil {
- log.Fatal("ListenAndServe: ", err)
- }
-}*/
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index 6e04288c2b..006b467a86 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -19,6 +19,7 @@ import (
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/mailer"
"github.com/gogits/gogs/modules/middleware"
+ "github.com/gogits/gogs/modules/setting"
)
func Issues(ctx *middleware.Context) {
@@ -242,7 +243,7 @@ func CreateIssuePost(ctx *middleware.Context, params martini.Params, form auth.C
}
// Mail watchers and mentions.
- if base.Service.NotifyMail {
+ if setting.Service.NotifyMail {
tos, err := mailer.SendIssueNotifyMail(ctx.User, ctx.Repo.Owner, ctx.Repo.Repository, issue)
if err != nil {
ctx.Handle(500, "issue.CreateIssue(SendIssueNotifyMail)", err)
@@ -677,7 +678,7 @@ func Comment(ctx *middleware.Context, params martini.Params) {
}
// Mail watchers and mentions.
- if base.Service.NotifyMail {
+ if setting.Service.NotifyMail {
issue.Content = content
tos, err := mailer.SendIssueNotifyMail(ctx.User, ctx.Repo.Owner, ctx.Repo.Repository, issue)
if err != nil {
diff --git a/routers/repo/setting.go b/routers/repo/setting.go
index fa4973ecd6..fe2489923e 100644
--- a/routers/repo/setting.go
+++ b/routers/repo/setting.go
@@ -16,6 +16,7 @@ import (
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/mailer"
"github.com/gogits/gogs/modules/middleware"
+ "github.com/gogits/gogs/modules/setting"
)
func Setting(ctx *middleware.Context) {
@@ -189,7 +190,7 @@ func CollaborationPost(ctx *middleware.Context) {
return
}
- if base.Service.NotifyMail {
+ if setting.Service.NotifyMail {
if err = mailer.SendCollaboratorMail(ctx.Render, u, ctx.User, ctx.Repo.Repository); err != nil {
ctx.Handle(500, "setting.CollaborationPost(SendCollaboratorMail)", err)
return