Browse Source

Merge branch 'master' of github.com:gogits/gogs

pull/31/head
Unknown 11 years ago
parent
commit
c44f18cae1
  1. 33
      models/repo2.go
  2. 65
      routers/repo/repo.go

33
models/repo2.go

@ -8,7 +8,7 @@ import (
"path" "path"
"time" "time"
git "github.com/speedata/gogit" git "github.com/gogits/git"
) )
type RepoFile struct { type RepoFile struct {
@ -46,20 +46,33 @@ func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile,
return nil, err return nil, err
} }
var repodirs []*RepoFile
var repofiles []*RepoFile var repofiles []*RepoFile
lastCommit.Tree.Walk(func(dirname string, entry *git.TreeEntry) int { lastCommit.Tree.Walk(func(dirname string, entry *git.TreeEntry) int {
if dirname == rpath { if dirname == rpath {
repofiles = append(repofiles, &RepoFile{ switch entry.Filemode {
entry.Id, case git.FileModeBlob, git.FileModeBlobExec:
entry.Filemode, repofiles = append(repofiles, &RepoFile{
entry.Name, entry.Id,
path.Join(dirname, entry.Name), entry.Filemode,
lastCommit.Message(), entry.Name,
lastCommit.Committer.When, path.Join(dirname, entry.Name),
}) lastCommit.Message(),
lastCommit.Committer.When,
})
case git.FileModeTree:
repodirs = append(repodirs, &RepoFile{
entry.Id,
entry.Filemode,
entry.Name,
path.Join(dirname, entry.Name),
lastCommit.Message(),
lastCommit.Committer.When,
})
}
} }
return 0 return 0
}) })
return repofiles, nil return append(repodirs, repofiles...), nil
} }

65
routers/repo/repo.go

@ -5,29 +5,23 @@
package repo package repo
import ( import (
"net/http"
"github.com/martini-contrib/render"
"github.com/martini-contrib/sessions"
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/middleware"
) )
func Create(form auth.CreateRepoForm, ctx *middleware.Context, req *http.Request, r render.Render, data base.TmplData, session sessions.Session) { func Create(ctx *middleware.Context, form auth.CreateRepoForm) {
data["Title"] = "Create repository" ctx.Data["Title"] = "Create repository"
if req.Method == "GET" { if ctx.Req.Method == "GET" {
data["LanguageIgns"] = models.LanguageIgns ctx.Data["LanguageIgns"] = models.LanguageIgns
data["Licenses"] = models.Licenses ctx.Data["Licenses"] = models.Licenses
r.HTML(200, "repo/create", data) ctx.Render.HTML(200, "repo/create", ctx.Data)
return return
} }
if hasErr, ok := data["HasError"]; ok && hasErr.(bool) { if hasErr, ok := ctx.Data["HasError"]; ok && hasErr.(bool) {
r.HTML(200, "repo/create", data) ctx.Render.HTML(200, "repo/create", ctx.Data)
return return
} }
@ -36,10 +30,10 @@ func Create(form auth.CreateRepoForm, ctx *middleware.Context, req *http.Request
user, err := models.GetUserById(form.UserId) user, err := models.GetUserById(form.UserId)
if err != nil { if err != nil {
if err.Error() == models.ErrUserNotExist.Error() { if err.Error() == models.ErrUserNotExist.Error() {
data["HasError"] = true ctx.Data["HasError"] = true
data["ErrorMsg"] = "User does not exist" ctx.Data["ErrorMsg"] = "User does not exist"
auth.AssignForm(form, data) auth.AssignForm(form, ctx.Data)
r.HTML(200, "repo/create", data) ctx.Render.HTML(200, "repo/create", ctx.Data)
return return
} }
} }
@ -48,27 +42,27 @@ func Create(form auth.CreateRepoForm, ctx *middleware.Context, req *http.Request
if _, err = models.CreateRepository(user, if _, err = models.CreateRepository(user,
form.RepoName, form.Description, form.Language, form.License, form.RepoName, form.Description, form.Language, form.License,
form.Visibility == "private", form.InitReadme == "on"); err == nil { form.Visibility == "private", form.InitReadme == "on"); err == nil {
r.Redirect("/"+user.Name+"/"+form.RepoName, 302) ctx.Render.Redirect("/"+user.Name+"/"+form.RepoName, 302)
return return
} }
} }
if err.Error() == models.ErrRepoAlreadyExist.Error() { if err.Error() == models.ErrRepoAlreadyExist.Error() {
data["HasError"] = true ctx.Data["HasError"] = true
data["ErrorMsg"] = "Repository name has already been used" ctx.Data["ErrorMsg"] = "Repository name has already been used"
auth.AssignForm(form, data) auth.AssignForm(form, ctx.Data)
r.HTML(200, "repo/create", data) ctx.Render.HTML(200, "repo/create", ctx.Data)
return return
} }
ctx.Handle(200, "repo.Create", err) ctx.Handle(200, "repo.Create", err)
} }
func Delete(form auth.DeleteRepoForm, ctx *middleware.Context, req *http.Request, r render.Render, data base.TmplData, session sessions.Session) { func Delete(ctx *middleware.Context, form auth.DeleteRepoForm) {
data["Title"] = "Delete repository" ctx.Data["Title"] = "Delete repository"
if req.Method == "GET" { if ctx.Req.Method == "GET" {
r.HTML(200, "repo/delete", data) ctx.Render.HTML(200, "repo/delete", ctx.Data)
return return
} }
@ -77,23 +71,22 @@ func Delete(form auth.DeleteRepoForm, ctx *middleware.Context, req *http.Request
return return
} }
r.Redirect("/", 302) ctx.Render.Redirect("/", 302)
} }
func List(ctx *middleware.Context, req *http.Request, r render.Render, data base.TmplData, session sessions.Session) { func List(ctx *middleware.Context) {
u := auth.SignedInUser(session) if ctx.User != nil {
if u != nil { ctx.Render.Redirect("/")
r.Redirect("/")
return return
} }
data["Title"] = "Repositories" ctx.Data["Title"] = "Repositories"
repos, err := models.GetRepositories(u) repos, err := models.GetRepositories(ctx.User)
if err != nil { if err != nil {
ctx.Handle(200, "repo.List", err) ctx.Handle(200, "repo.List", err)
return return
} }
data["Repos"] = repos ctx.Data["Repos"] = repos
r.HTML(200, "repo/list", data) ctx.Render.HTML(200, "repo/list", ctx.Data)
} }

Loading…
Cancel
Save