1
1
mirror of https://github.com/go-gitea/gitea synced 2025-08-13 04:58:19 +00:00
This commit is contained in:
Unknown
2014-05-25 20:11:25 -04:00
parent 87854c95a9
commit 688ec6ecbd
37 changed files with 693 additions and 482 deletions

View File

@@ -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")
}

View File

@@ -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")
}

View File

@@ -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
}

View File

@@ -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
*/

View File

@@ -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)
}
}*/

View File

@@ -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 {

View File

@@ -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