Browse Source

minor fix on #1863

pull/1872/head
Unknwon 9 years ago
parent
commit
16feb5b655
  1. 2
      gogs.go
  2. 40
      modules/middleware/repo.go
  3. 2
      templates/.VERSION

2
gogs.go

@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.6.18.1029 Beta" const APP_VER = "0.6.18.1031 Beta"
func init() { func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())

40
modules/middleware/repo.go

@ -7,6 +7,7 @@ package middleware
import ( import (
"fmt" "fmt"
"net/url" "net/url"
"path"
"strings" "strings"
"github.com/mcuadros/go-version" "github.com/mcuadros/go-version"
@ -30,15 +31,15 @@ func ApiRepoAssignment() macaron.Handler {
repoName := ctx.Params(":reponame") repoName := ctx.Params(":reponame")
var ( var (
u *models.User owner *models.User
err error err error
) )
// Check if the user is the same as the repository owner. // Check if the user is the same as the repository owner.
if ctx.IsSigned && ctx.User.LowerName == strings.ToLower(userName) { if ctx.IsSigned && ctx.User.LowerName == strings.ToLower(userName) {
u = ctx.User owner = ctx.User
} else { } else {
u, err = models.GetUserByName(userName) owner, err = models.GetUserByName(userName)
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.Error(404) ctx.Error(404)
@ -48,10 +49,10 @@ func ApiRepoAssignment() macaron.Handler {
return return
} }
} }
ctx.Repo.Owner = u ctx.Repo.Owner = owner
// Get repository. // Get repository.
repo, err := models.GetRepositoryByName(u.Id, repoName) repo, err := models.GetRepositoryByName(owner.Id, repoName)
if err != nil { if err != nil {
if models.IsErrRepoNotExist(err) { if models.IsErrRepoNotExist(err) {
ctx.Error(404) ctx.Error(404)
@ -234,8 +235,8 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
} }
var ( var (
u *models.User owner *models.User
err error err error
) )
userName := ctx.Params(":username") userName := ctx.Params(":username")
@ -247,9 +248,9 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
// Check if the user is the same as the repository owner // Check if the user is the same as the repository owner
if ctx.IsSigned && ctx.User.LowerName == strings.ToLower(userName) { if ctx.IsSigned && ctx.User.LowerName == strings.ToLower(userName) {
u = ctx.User owner = ctx.User
} else { } else {
u, err = models.GetUserByName(userName) owner, err = models.GetUserByName(userName)
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.Handle(404, "GetUserByName", err) ctx.Handle(404, "GetUserByName", err)
@ -259,10 +260,10 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
return return
} }
} }
ctx.Repo.Owner = u ctx.Repo.Owner = owner
// Get repository. // Get repository.
repo, err := models.GetRepositoryByName(u.Id, repoName) repo, err := models.GetRepositoryByName(owner.Id, repoName)
if err != nil { if err != nil {
if models.IsErrRepoNotExist(err) { if models.IsErrRepoNotExist(err) {
ctx.Handle(404, "GetRepositoryByName", err) ctx.Handle(404, "GetRepositoryByName", err)
@ -331,7 +332,7 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
} }
} }
ctx.Data["Title"] = u.Name + "/" + repo.Name ctx.Data["Title"] = owner.Name + "/" + repo.Name
ctx.Data["Repository"] = repo ctx.Data["Repository"] = repo
ctx.Data["Owner"] = ctx.Repo.Repository.Owner ctx.Data["Owner"] = ctx.Repo.Repository.Owner
ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner() ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner()
@ -345,12 +346,6 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
} }
ctx.Data["CloneLink"] = ctx.Repo.CloneLink ctx.Data["CloneLink"] = ctx.Repo.CloneLink
if ctx.Query("go-get") == "1" {
ctx.Data["GoGetImport"] = fmt.Sprintf("%s/%s/%s", setting.Domain, u.Name, repo.Name)
ctx.Data["GoDocDirectory"] = fmt.Sprintf("%s%s/%s/src/master{/dir}", setting.AppUrl, repo.Owner.LowerName, repo.LowerName)
ctx.Data["GoDocFile"] = fmt.Sprintf("%s%s/%s/src/master{/dir}/{file}#L{line}", setting.AppUrl, repo.Owner.LowerName, repo.LowerName)
}
if ctx.IsSigned { if ctx.IsSigned {
ctx.Data["IsWatchingRepo"] = models.IsWatching(ctx.User.Id, repo.ID) ctx.Data["IsWatchingRepo"] = models.IsWatching(ctx.User.Id, repo.ID)
ctx.Data["IsStaringRepo"] = models.IsStaring(ctx.User.Id, repo.ID) ctx.Data["IsStaringRepo"] = models.IsStaring(ctx.User.Id, repo.ID)
@ -392,6 +387,13 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
ctx.Data["BranchName"] = ctx.Repo.BranchName ctx.Data["BranchName"] = ctx.Repo.BranchName
ctx.Data["CommitID"] = ctx.Repo.CommitID ctx.Data["CommitID"] = ctx.Repo.CommitID
if ctx.Query("go-get") == "1" {
ctx.Data["GoGetImport"] = path.Join(setting.Domain, setting.AppSubUrl, owner.Name, repo.Name)
prefix := path.Join(setting.AppUrl, owner.Name, repo.Name, "src", ctx.Repo.BranchName)
ctx.Data["GoDocDirectory"] = prefix + "{/dir}"
ctx.Data["GoDocFile"] = prefix + "{/dir}/{file}#L{line}"
}
userAgent := ctx.Req.Header.Get("User-Agent") userAgent := ctx.Req.Header.Get("User-Agent")
ua := user_agent.New(userAgent) ua := user_agent.New(userAgent)
browserName, browserVer := ua.Browser() browserName, browserVer := ua.Browser()

2
templates/.VERSION

@ -1 +1 @@
0.6.18.1029 Beta 0.6.18.1031 Beta
Loading…
Cancel
Save