From 7ab94fe816bd726c995f2937a040c3d8c7898205 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 26 Mar 2014 09:22:08 -0400 Subject: [PATCH 1/3] Fix issue on windows --- README.md | 2 +- README_ZH.md | 2 +- gogs.go | 2 +- models/repo.go | 3 ++- modules/base/conf.go | 2 +- update.go | 24 ++++++++++++------------ 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index c708bf55c8..b7396e5f47 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ More importantly, Gogs only needs one binary to setup your own project hosting o - User profile page. - Repository viewer. - Gravatar and cache support. -- Mail service(register). +- Mail service(register, issue). - Administration panel. - Supports MySQL, PostgreSQL and SQLite3(binary release only). diff --git a/README_ZH.md b/README_ZH.md index ee9c3b7c42..9c9f4b3980 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -29,7 +29,7 @@ Gogs 完全使用 Go 语言来实现对 Git 数据的操作,实现 **零** 依 - 用户个人信息页面 - 仓库浏览器 - Gravatar 以及缓存支持 -- 邮件服务(注册) +- 邮件服务(注册、Issue) - 管理员面板 - 支持 MySQL、PostgreSQL 以及 SQLite3(仅限二进制版本) diff --git a/gogs.go b/gogs.go index d88a2bc6f4..ba443c6e65 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.1.8.0326" +const APP_VER = "0.1.8.0326 Alpha" func init() { base.AppVer = APP_VER diff --git a/models/repo.go b/models/repo.go index 477f9472b4..c80d2f2c2c 100644 --- a/models/repo.go +++ b/models/repo.go @@ -251,7 +251,8 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep } defer pu.Close() // TODO: Windows .bat - if _, err = pu.WriteString(fmt.Sprintf("#!/usr/bin/env bash\n%s update $1 $2 $3\n", appPath)); err != nil { + if _, err = pu.WriteString(fmt.Sprintf("#!/usr/bin/env bash\n%s update $1 $2 $3\n", + strings.Replace(appPath, "\\", "/", -1))); err != nil { return err } diff --git a/modules/base/conf.go b/modules/base/conf.go index 0fb1ccdcf6..2e56883937 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -80,7 +80,7 @@ func ExecDir() (string, error) { if err != nil { return "", err } - return path.Dir(p), nil + return path.Dir(strings.Replace(p, "\\", "/", -1)), nil } var logLevels = map[string]string{ diff --git a/update.go b/update.go index 5c6d5b28ce..39729937e1 100644 --- a/update.go +++ b/update.go @@ -5,18 +5,18 @@ package main import ( -"os" -"os/exec" -"strings" -"strconv" -"container/list" + "container/list" + "os" + "os/exec" + "strconv" + "strings" -"github.com/codegangsta/cli" -//"github.com/gogits/gogs/modules/log" -"github.com/gogits/gogs/models" -"github.com/gogits/gogs/modules/base" -"github.com/qiniu/log" -"github.com/gogits/git" + "github.com/codegangsta/cli" + //"github.com/gogits/gogs/modules/log" + "github.com/gogits/git" + "github.com/gogits/gogs/models" + "github.com/gogits/gogs/modules/base" + "github.com/qiniu/log" ) var CmdUpdate = cli.Command{ @@ -103,7 +103,7 @@ func runUpdate(c *cli.Context) { // if a new branch if strings.HasPrefix(oldCommitId, "0000000") { l, err = ref.AllCommits() - + } else { l = ref.CommitsBetween(newCommit, oldCommit) } From 4662a73ac34adeeeb6fc48ba6ac69b6a4adf18bc Mon Sep 17 00:00:00 2001 From: skyblue Date: Wed, 26 Mar 2014 21:26:31 +0800 Subject: [PATCH 2/3] name change of avatar --- modules/avatar/avatar.go | 14 +++++++------- modules/avatar/avatar_test.go | 2 +- web.go | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/avatar/avatar.go b/modules/avatar/avatar.go index 449c9656dc..06e2c1385b 100644 --- a/modules/avatar/avatar.go +++ b/modules/avatar/avatar.go @@ -9,7 +9,7 @@ It is recommend to use this way cacheDir := "./cache" defaultImg := "./default.jpg" - http.Handle("/avatar/", avatar.HttpHandler(cacheDir, defaultImg)) + http.Handle("/avatar/", avatar.CacheServer(cacheDir, defaultImg)) */ package avatar @@ -135,12 +135,12 @@ func (this *Avatar) UpdateTimeout(timeout time.Duration) error { return err } -type avatarHandler struct { +type service struct { cacheDir string altImage string } -func (this *avatarHandler) mustInt(r *http.Request, defaultValue int, keys ...string) int { +func (this *service) mustInt(r *http.Request, defaultValue int, keys ...string) int { var v int for _, k := range keys { if _, err := fmt.Sscanf(r.FormValue(k), "%d", &v); err == nil { @@ -150,7 +150,7 @@ func (this *avatarHandler) mustInt(r *http.Request, defaultValue int, keys ...st return defaultValue } -func (this *avatarHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { +func (this *service) ServeHTTP(w http.ResponseWriter, r *http.Request) { urlPath := r.URL.Path hash := urlPath[strings.LastIndex(urlPath, "/")+1:] size := this.mustInt(r, 80, "s", "size") // default size = 80*80 @@ -183,9 +183,9 @@ func (this *avatarHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } -// http.Handle("/avatar/", avatar.HttpHandler("./cache")) -func HttpHandler(cacheDir string, defaultImgPath string) http.Handler { - return &avatarHandler{ +// http.Handle("/avatar/", avatar.CacheServer("./cache")) +func CacheServer(cacheDir string, defaultImgPath string) http.Handler { + return &service{ cacheDir: cacheDir, altImage: defaultImgPath, } diff --git a/modules/avatar/avatar_test.go b/modules/avatar/avatar_test.go index 4656d6f0f4..0cbf70fe60 100644 --- a/modules/avatar/avatar_test.go +++ b/modules/avatar/avatar_test.go @@ -51,7 +51,7 @@ func TestFetchMany(t *testing.T) { // wget http://www.artsjournal.com/artfulmanager/wp/wp-content/uploads/2013/12/200x200xmirror_cat.jpg.pagespeed.ic.GOZSv6v1_H.jpg -O default.jpg /* func TestHttp(t *testing.T) { - http.Handle("/", avatar.HttpHandler("./", "default.jpg")) + http.Handle("/", avatar.CacheServer("./", "default.jpg")) http.ListenAndServe(":8001", nil) } */ diff --git a/web.go b/web.go index 9b7b21639a..9423c3eecb 100644 --- a/web.go +++ b/web.go @@ -96,8 +96,8 @@ func runWeb(*cli.Context) { m.Get("/stars", reqSignIn, user.Stars) m.Get("/help", routers.Help) - avatarCache := avatar.HttpHandler("public/img/avatar/", "public/img/avatar_default.jpg") - m.Get("/avatar/:hash", avatarCache.ServeHTTP) + avt := avatar.CacheServer("public/img/avatar/", "public/img/avatar_default.jpg") + m.Get("/avatar/:hash", avt.ServeHTTP) m.Group("/user", func(r martini.Router) { r.Any("/login", binding.BindIgnErr(auth.LogInForm{}), user.SignIn) From 32e05ae2120e864d6e1bd85fb01ef87e23c3ae89 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 26 Mar 2014 09:40:02 -0400 Subject: [PATCH 3/3] Fix issue: update hook text busy --- models/repo.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/models/repo.go b/models/repo.go index c80d2f2c2c..0ef049cc6e 100644 --- a/models/repo.go +++ b/models/repo.go @@ -235,6 +235,18 @@ func initRepoCommit(tmpPath string, sig *git.Signature) (err error) { return nil } +func createHookUpdate(hookPath, content string) error { + pu, err := os.OpenFile(hookPath, os.O_CREATE|os.O_WRONLY, 0777) + if err != nil { + return err + } + defer pu.Close() + if _, err = pu.WriteString(content); err != nil { + return err + } + return nil +} + // InitRepository initializes README and .gitignore if needed. func initRepository(f string, user *User, repo *Repository, initReadme bool, repoLang, license string) error { repoPath := RepoPath(user.Name, repo.Name) @@ -245,14 +257,9 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep } // hook/post-update - pu, err := os.OpenFile(filepath.Join(repoPath, "hooks", "update"), os.O_CREATE|os.O_WRONLY, 0777) - if err != nil { - return err - } - defer pu.Close() - // TODO: Windows .bat - if _, err = pu.WriteString(fmt.Sprintf("#!/usr/bin/env bash\n%s update $1 $2 $3\n", - strings.Replace(appPath, "\\", "/", -1))); err != nil { + if err := createHookUpdate(filepath.Join(repoPath, "hooks", "update"), + fmt.Sprintf("#!/usr/bin/env bash\n%s update $1 $2 $3\n", + strings.Replace(appPath, "\\", "/", -1))); err != nil { return err }