From 62d23e91541550d0478c4884696e918a0e818b4f Mon Sep 17 00:00:00 2001
From: Unknown
Date: Sun, 27 Apr 2014 01:05:13 -0600
Subject: [PATCH] HTTP no follow and offline mode
---
conf/app.ini | 2 ++
gogs.go | 2 +-
models/repo.go | 16 ++-------------
models/update.go | 10 +++++++--
modules/base/conf.go | 18 +++++++++--------
modules/base/template.go | 10 ++++-----
routers/admin/admin.go | 2 ++
routers/install.go | 2 +-
templates/admin/config.tmpl | 4 ++++
templates/base/head.tmpl | 2 +-
templates/base/navbar.tmpl | 6 +++---
templates/release/list.tmpl | 36 ++++++---------------------------
templates/repo/commits.tmpl | 4 ++--
templates/repo/nav.tmpl | 4 ++--
templates/repo/single_file.tmpl | 4 ++--
templates/repo/single_list.tmpl | 2 +-
templates/user/profile.tmpl | 6 +++---
17 files changed, 55 insertions(+), 75 deletions(-)
diff --git a/conf/app.ini b/conf/app.ini
index 25fd41091..e7174e225 100644
--- a/conf/app.ini
+++ b/conf/app.ini
@@ -16,6 +16,8 @@ LICENSES = Apache v2 License|GPL v2|MIT License|Affero GPL|Artistic License 2.0|
PROTOCOL = http
DOMAIN = localhost
ROOT_URL = %(PROTOCOL)s://%(DOMAIN)s:%(HTTP_PORT)s/
+; Disable CDN even in "prod" mode
+OFFLINE_MODE = false
HTTP_ADDR =
HTTP_PORT = 3000
; Generate steps:
diff --git a/gogs.go b/gogs.go
index caa8cf63d..1a8b4d131 100644
--- a/gogs.go
+++ b/gogs.go
@@ -19,7 +19,7 @@ import (
// Test that go1.2 tag above is included in builds. main.go refers to this definition.
const go12tag = true
-const APP_VER = "0.3.0.0426 Alpha"
+const APP_VER = "0.3.0.0427 Alpha"
func init() {
base.AppVer = APP_VER
diff --git a/models/repo.go b/models/repo.go
index 245717437..5f66bca86 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -159,9 +159,7 @@ func MirrorUpdate() {
repoPath := filepath.Join(base.RepoRootPath, m.RepoName+".git")
_, stderr, err := com.ExecCmdDir(repoPath, "git", "remote", "update")
if err != nil {
- return err
- } else if strings.Contains(stderr, "fatal:") {
- return errors.New(stderr)
+ return errors.New("git remote update: " + stderr)
} else if err = git.UnpackRefs(repoPath); err != nil {
return err
}
@@ -177,9 +175,7 @@ func MirrorUpdate() {
func MirrorRepository(repoId int64, userName, repoName, repoPath, url string) error {
_, stderr, err := com.ExecCmd("git", "clone", "--mirror", url, repoPath)
if err != nil {
- return err
- } else if strings.Contains(stderr, "fatal:") {
- return errors.New(stderr)
+ return errors.New("git clone --mirror: " + stderr)
}
if _, err = orm.InsertOne(&Mirror{
@@ -219,23 +215,17 @@ func MigrateRepository(user *User, name, desc string, private, mirror bool, url
// Clone from local repository.
_, stderr, err := com.ExecCmd("git", "clone", repoPath, tmpDir)
if err != nil {
- return repo, err
- } else if strings.Contains(stderr, "fatal:") {
return repo, errors.New("git clone: " + stderr)
}
// Pull data from source.
_, stderr, err = com.ExecCmdDir(tmpDir, "git", "pull", url)
if err != nil {
- return repo, err
- } else if strings.Contains(stderr, "fatal:") {
return repo, errors.New("git pull: " + stderr)
}
// Push data to local repository.
if _, stderr, err = com.ExecCmdDir(tmpDir, "git", "push", "origin", "master"); err != nil {
- return repo, err
- } else if strings.Contains(stderr, "fatal:") {
return repo, errors.New("git push: " + stderr)
}
@@ -429,8 +419,6 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep
_, stderr, err := com.ExecCmd("git", "clone", repoPath, tmpDir)
if err != nil {
- return err
- } else if strings.Contains(stderr, "fatal:") {
return errors.New("git clone: " + stderr)
}
diff --git a/models/update.go b/models/update.go
index 2f59547b7..648c45f16 100644
--- a/models/update.go
+++ b/models/update.go
@@ -1,3 +1,7 @@
+// Copyright 2014 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
package models
import (
@@ -5,9 +9,11 @@ import (
"os/exec"
"strings"
- "github.com/gogits/git"
- "github.com/gogits/gogs/modules/base"
qlog "github.com/qiniu/log"
+
+ "github.com/gogits/git"
+
+ "github.com/gogits/gogs/modules/base"
)
func Update(refName, oldCommitId, newCommitId, userName, repoName string, userId int64) {
diff --git a/modules/base/conf.go b/modules/base/conf.go
index 17b55316a..cfc85ff51 100644
--- a/modules/base/conf.go
+++ b/modules/base/conf.go
@@ -45,14 +45,15 @@ type Oauther struct {
}
var (
- AppVer string
- AppName string
- AppLogo string
- AppUrl string
- IsProdMode bool
- Domain string
- SecretKey string
- RunUser string
+ AppVer string
+ AppName string
+ AppLogo string
+ AppUrl string
+ OfflineMode bool
+ ProdMode bool
+ Domain string
+ SecretKey string
+ RunUser string
RepoRootPath string
ScriptType string
@@ -325,6 +326,7 @@ func NewConfigContext() {
AppLogo = Cfg.MustValue("", "APP_LOGO", "img/favicon.png")
AppUrl = Cfg.MustValue("server", "ROOT_URL")
Domain = Cfg.MustValue("server", "DOMAIN")
+ OfflineMode = Cfg.MustBool("server", "OFFLINE_MODE", false)
SecretKey = Cfg.MustValue("security", "SECRET_KEY")
InstallLock = Cfg.MustBool("security", "INSTALL_LOCK", false)
diff --git a/modules/base/template.go b/modules/base/template.go
index 79aeeb9d7..dd98df75b 100644
--- a/modules/base/template.go
+++ b/modules/base/template.go
@@ -56,8 +56,8 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{
"AppDomain": func() string {
return Domain
},
- "IsProdMode": func() bool {
- return IsProdMode
+ "CdnMode": func() bool {
+ return ProdMode && !OfflineMode
},
"LoadTimes": func(startTime time.Time) string {
return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms"
@@ -124,11 +124,11 @@ func ActionIcon(opType int) string {
const (
TPL_CREATE_REPO = `%s created repository %s`
TPL_COMMIT_REPO = `%s pushed to %s at %s%s`
- TPL_COMMIT_REPO_LI = ``
+ TPL_COMMIT_REPO_LI = ``
TPL_CREATE_ISSUE = `%s opened issue %s#%s
%s
`
TPL_TRANSFER_REPO = `%s transfered repository %s
to %s`
- TPL_PUSH_TAG = `%s pushed tag %s at %s`
+ TPL_PUSH_TAG = `%s pushed tag %s at %s`
)
type PushCommit struct {
@@ -165,7 +165,7 @@ func ActionDesc(act Actioner) string {
buf.WriteString(fmt.Sprintf(TPL_COMMIT_REPO_LI, AvatarLink(commit.AuthorEmail), repoLink, commit.Sha1, commit.Sha1[:7], commit.Message) + "\n")
}
if push.Len > 3 {
- buf.WriteString(fmt.Sprintf(``, actUserName, repoName, branch, push.Len))
+ buf.WriteString(fmt.Sprintf(``, actUserName, repoName, branch, push.Len))
}
return fmt.Sprintf(TPL_COMMIT_REPO, actUserName, actUserName, repoLink, branch, branch, repoLink, repoLink,
buf.String())
diff --git a/routers/admin/admin.go b/routers/admin/admin.go
index d0f737e64..fddd83018 100644
--- a/routers/admin/admin.go
+++ b/routers/admin/admin.go
@@ -139,9 +139,11 @@ func Config(ctx *middleware.Context) {
ctx.Data["AppUrl"] = base.AppUrl
ctx.Data["Domain"] = base.Domain
+ ctx.Data["OfflineMode"] = base.OfflineMode
ctx.Data["RunUser"] = base.RunUser
ctx.Data["RunMode"] = strings.Title(martini.Env)
ctx.Data["RepoRootPath"] = base.RepoRootPath
+ ctx.Data["ScriptType"] = base.ScriptType
ctx.Data["Service"] = base.Service
diff --git a/routers/install.go b/routers/install.go
index 8ffa9b5d1..38bf896f4 100644
--- a/routers/install.go
+++ b/routers/install.go
@@ -30,7 +30,7 @@ func checkRunMode() {
switch base.Cfg.MustValue("", "RUN_MODE") {
case "prod":
martini.Env = martini.Prod
- base.IsProdMode = true
+ base.ProdMode = true
case "test":
martini.Env = martini.Test
}
diff --git a/templates/admin/config.tmpl b/templates/admin/config.tmpl
index d25d40275..b2b25e90f 100644
--- a/templates/admin/config.tmpl
+++ b/templates/admin/config.tmpl
@@ -18,6 +18,8 @@
{{.AppUrl}}
Domain
{{.Domain}}
+ Offline Mode
+
Run User
{{.RunUser}}
@@ -26,6 +28,8 @@
Repository Root Path
{{.RepoRootPath}}
+ Script Type
+ {{.ScriptType}}
diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl
index 68231391c..6794b0171 100644
--- a/templates/base/head.tmpl
+++ b/templates/base/head.tmpl
@@ -12,7 +12,7 @@
{{if .Repository.IsGoget}}{{end}}
- {{if IsProdMode}}
+ {{if CdnMode}}
diff --git a/templates/base/navbar.tmpl b/templates/base/navbar.tmpl
index 932cae36d..b8cba5faa 100644
--- a/templates/base/navbar.tmpl
+++ b/templates/base/navbar.tmpl
@@ -3,7 +3,7 @@
{{else}}
-
+
- zip
+ zip
@@ -50,30 +50,6 @@
{{end}}
{{end}}
-
diff --git a/templates/repo/commits.tmpl b/templates/repo/commits.tmpl
index b14c6bc8c..bfc0bf21b 100644
--- a/templates/repo/commits.tmpl
+++ b/templates/repo/commits.tmpl
@@ -41,8 +41,8 @@
{{if not .IsSearchPage}}{{end}}
diff --git a/templates/repo/nav.tmpl b/templates/repo/nav.tmpl
index ce9c112b8..48fe31a61 100644
--- a/templates/repo/nav.tmpl
+++ b/templates/repo/nav.tmpl
@@ -23,10 +23,10 @@
- Need help cloning? Visit Help!
+ Need help cloning? Visit Help!
diff --git a/templates/repo/single_file.tmpl b/templates/repo/single_file.tmpl
index b8205024c..95c41b701 100644
--- a/templates/repo/single_file.tmpl
+++ b/templates/repo/single_file.tmpl
@@ -14,7 +14,7 @@
{{if not .ReadmeInSingle}}
{{else}}
diff --git a/templates/repo/single_list.tmpl b/templates/repo/single_list.tmpl
index 7b6c6e5e9..49a0ec5af 100644
--- a/templates/repo/single_list.tmpl
+++ b/templates/repo/single_list.tmpl
@@ -1,6 +1,6 @@
{{.LastCommit.Author.Name}} {{TimeSince .LastCommit.Author.When}}
diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl
index 0319f46c2..15d2a0bd5 100644
--- a/templates/user/profile.tmpl
+++ b/templates/user/profile.tmpl
@@ -11,13 +11,13 @@