From 9b509054cf8ef8e15cf567614aef46fe12571904 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 26 Mar 2014 00:00:36 +0800 Subject: [PATCH] bug fixed --- models/repo.go | 5 ++--- serve.go | 22 +++++++++++++++++----- update.go | 24 +++++++++++++++++------- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/models/repo.go b/models/repo.go index d5f9be72acf7..9e469952e30d 100644 --- a/models/repo.go +++ b/models/repo.go @@ -261,7 +261,6 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep return err } - /* // hook/post-update pu, err := os.OpenFile(filepath.Join(repoPath, "hooks", "post-update"), os.O_CREATE|os.O_WRONLY, 0777) if err != nil { @@ -269,11 +268,11 @@ 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\n", appPath)); err != nil { + if _, err = pu.WriteString(fmt.Sprintf("#!/usr/bin/env bash\n%s update ARGV[0] ARGV[1] ARGV[2]\n", appPath)); err != nil { return err } - // hook/post-update + /*// hook/post-update pu2, err := os.OpenFile(filepath.Join(repoPath, "hooks", "post-receive"), os.O_CREATE|os.O_WRONLY, 0777) if err != nil { return err diff --git a/serve.go b/serve.go index 27324df19bd2..6cd1e224a876 100644 --- a/serve.go +++ b/serve.go @@ -212,18 +212,18 @@ func runServ(k *cli.Context) { return } - if isRead { + //if isRead { return - } + //} time.Sleep(time.Second) log.Info(s) // find push reference name - var t = "ok refs/heads/" - var i int + //var t = "ok refs/heads/" + //var i int var refname string - for { + /*for { l, err := b.ReadString('\n') if err != nil { break @@ -235,6 +235,18 @@ func runServ(k *cli.Context) { refname = l[idx+len(t):] } } + */ + + refs2, err := rep.AllReferencesMap() + for name, ref := range refs2 { + if ref2, ok := refs[name]; ok { + if ref.Oid.Equal(ref2.Oid) { + continue + } + } + refname = name + break + } if refname == "" { println("No find any reference name:", s) return diff --git a/update.go b/update.go index 915e046530d4..ebc51b2a0c2c 100644 --- a/update.go +++ b/update.go @@ -4,9 +4,12 @@ package main -import "github.com/codegangsta/cli" - -//"github.com/gogits/gogs/modules/log" +import ( +"fmt" +"os" +"github.com/codegangsta/cli" +"github.com/gogits/gogs/modules/log" +) var CmdUpdate = cli.Command{ Name: "update", @@ -18,11 +21,18 @@ gogs serv provide access auth for repositories`, } // for command: ./gogs update -func runUpdate(*cli.Context) { - /*w, _ := os.Create("update.log") - log.SetOutput(w) +func runUpdate(c *cli.Context) { + level := "0" + os.MkdirAll("log", os.ModePerm) + log.NewLogger(10000, "file", fmt.Sprintf(`{"level":%s,"filename":"%s"}`, level, "log/serv.log")) + log.Info("start update logging...") - userName := os.Getenv("userName") + //w, _ := os.Create("update.log") + //log.SetOutput(w) + for i, arg := range c.Args() { + log.Info("%d : %s", i, arg) +} + /*userName := os.Getenv("userName") userId := os.Getenv("userId") repoId := os.Getenv("repoId") repoName := os.Getenv("repoName")