mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-26 16:22:15 +01:00
bug fixed
This commit is contained in:
parent
d374b13d44
commit
fc1419d763
2 changed files with 97 additions and 32 deletions
37
serve.go
37
serve.go
|
@ -5,20 +5,17 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
//"container/list"
|
||||||
"container/list"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
"github.com/gogits/gogs/modules/log"
|
"github.com/gogits/gogs/modules/log"
|
||||||
|
|
||||||
"github.com/gogits/git"
|
//"github.com/gogits/git"
|
||||||
"github.com/gogits/gogs/models"
|
"github.com/gogits/gogs/models"
|
||||||
"github.com/gogits/gogs/modules/base"
|
"github.com/gogits/gogs/modules/base"
|
||||||
)
|
)
|
||||||
|
@ -115,11 +112,11 @@ func runServ(k *cli.Context) {
|
||||||
isWrite := In(verb, COMMANDS_WRITE)
|
isWrite := In(verb, COMMANDS_WRITE)
|
||||||
isRead := In(verb, COMMANDS_READONLY)
|
isRead := In(verb, COMMANDS_READONLY)
|
||||||
|
|
||||||
repo, err := models.GetRepositoryByName(user.Id, repoName)
|
//repo, err := models.GetRepositoryByName(user.Id, repoName)
|
||||||
var isExist bool = true
|
//var isExist bool = true
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == models.ErrRepoNotExist {
|
if err == models.ErrRepoNotExist {
|
||||||
isExist = false
|
//isExist = false
|
||||||
if isRead {
|
if isRead {
|
||||||
println("Repository", user.Name+"/"+repoName, "is not exist")
|
println("Repository", user.Name+"/"+repoName, "is not exist")
|
||||||
return
|
return
|
||||||
|
@ -168,6 +165,7 @@ func runServ(k *cli.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
var rep *git.Repository
|
var rep *git.Repository
|
||||||
repoPath := models.RepoPath(user.Name, repoName)
|
repoPath := models.RepoPath(user.Name, repoName)
|
||||||
if !isExist {
|
if !isExist {
|
||||||
|
@ -194,14 +192,20 @@ func runServ(k *cli.Context) {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
os.Setenv("userName", user.Name)
|
||||||
|
os.Setenv("userId", strconv.Itoa(int(user.Id)))
|
||||||
|
//os.Setenv("repoId", repoId)
|
||||||
|
os.Setenv("repoName", repoName)
|
||||||
|
|
||||||
gitcmd := exec.Command(verb, rRepo)
|
gitcmd := exec.Command(verb, rRepo)
|
||||||
gitcmd.Dir = base.RepoRootPath
|
gitcmd.Dir = base.RepoRootPath
|
||||||
|
|
||||||
var s string
|
//var s string
|
||||||
b := bytes.NewBufferString(s)
|
//b := bytes.NewBufferString(s)
|
||||||
|
|
||||||
gitcmd.Stdout = io.MultiWriter(os.Stdout, b)
|
gitcmd.Stdout = os.Stdout
|
||||||
//gitcmd.Stdin = io.MultiReader(os.Stdin, b)
|
//gitcmd.Stdin = io.MultiReader(os.Stdin, b)
|
||||||
gitcmd.Stdin = os.Stdin
|
gitcmd.Stdin = os.Stdin
|
||||||
gitcmd.Stderr = os.Stderr
|
gitcmd.Stderr = os.Stderr
|
||||||
|
@ -213,16 +217,13 @@ func runServ(k *cli.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//if isRead {
|
//if isRead {
|
||||||
return
|
// return
|
||||||
//}
|
//}
|
||||||
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
log.Info(s)
|
|
||||||
|
|
||||||
// find push reference name
|
// find push reference name
|
||||||
//var t = "ok refs/heads/"
|
//var t = "ok refs/heads/"
|
||||||
//var i int
|
//var i int
|
||||||
var refname string
|
//var refname string
|
||||||
/*for {
|
/*for {
|
||||||
l, err := b.ReadString('\n')
|
l, err := b.ReadString('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -237,7 +238,7 @@ func runServ(k *cli.Context) {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
refs2, err := rep.AllReferencesMap()
|
/*refs2, err := rep.AllReferencesMap()
|
||||||
for name, ref := range refs2 {
|
for name, ref := range refs2 {
|
||||||
if ref2, ok := refs[name]; ok {
|
if ref2, ok := refs[name]; ok {
|
||||||
if ref.Oid.Equal(ref2.Oid) {
|
if ref.Oid.Equal(ref2.Oid) {
|
||||||
|
@ -323,5 +324,5 @@ func runServ(k *cli.Context) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("update-server-info: %v", err)
|
log.Error("update-server-info: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
92
update.go
92
update.go
|
@ -6,9 +6,17 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
"strconv"
|
||||||
|
"container/list"
|
||||||
|
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
//"github.com/gogits/gogs/modules/log"
|
//"github.com/gogits/gogs/modules/log"
|
||||||
|
"github.com/gogits/gogs/models"
|
||||||
|
"github.com/gogits/gogs/modules/base"
|
||||||
"github.com/qiniu/log"
|
"github.com/qiniu/log"
|
||||||
|
"github.com/gogits/git"
|
||||||
)
|
)
|
||||||
|
|
||||||
var CmdUpdate = cli.Command{
|
var CmdUpdate = cli.Command{
|
||||||
|
@ -31,16 +39,30 @@ func runUpdate(c *cli.Context) {
|
||||||
defer w.Close()
|
defer w.Close()
|
||||||
|
|
||||||
log.SetOutput(w)
|
log.SetOutput(w)
|
||||||
for i, arg := range c.Args() {
|
|
||||||
log.Info(i, arg)
|
|
||||||
|
|
||||||
|
args := c.Args()
|
||||||
|
if len(args) != 3 {
|
||||||
|
log.Error("received less 3 parameters")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refName := args[0]
|
||||||
|
oldCommitId := args[1]
|
||||||
|
newCommitId := args[2]
|
||||||
|
|
||||||
userName := os.Getenv("userName")
|
userName := os.Getenv("userName")
|
||||||
//userId := os.Getenv("userId")
|
userId := os.Getenv("userId")
|
||||||
//repoId := os.Getenv("repoId")
|
//repoId := os.Getenv("repoId")
|
||||||
//repoName := os.Getenv("repoName")
|
repoName := os.Getenv("repoName")
|
||||||
|
|
||||||
log.Info("username", userName)
|
log.Info("username", userName)
|
||||||
/*f := models.RepoPath(userName, repoName)
|
f := models.RepoPath(userName, repoName)
|
||||||
|
|
||||||
|
gitUpdate := exec.Command("git", "update-server-info")
|
||||||
|
gitUpdate.Dir = f
|
||||||
|
gitUpdate.Run()
|
||||||
|
|
||||||
repo, err := git.OpenRepository(f)
|
repo, err := git.OpenRepository(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -48,13 +70,45 @@ func runUpdate(c *cli.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ref, err := repo.LookupReference("HEAD")
|
ref, err := repo.LookupReference(refName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("runUpdate.Ref repoId: %v", err)
|
log.Error("runUpdate.Ref repoId: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
lastCommit, err := repo.LookupCommit(ref.Oid)
|
oldOid, err := git.NewOidFromString(oldCommitId)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("runUpdate.Ref repoId: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
oldCommit, err := repo.LookupCommit(oldOid)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("runUpdate.Ref repoId: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
newOid, err := git.NewOidFromString(newCommitId)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("runUpdate.Ref repoId: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
newCommit, err := repo.LookupCommit(newOid)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("runUpdate.Ref repoId: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var l *list.List
|
||||||
|
// if a new branch
|
||||||
|
if strings.HasPrefix(oldCommitId, "0000000") {
|
||||||
|
l, err = ref.AllCommits()
|
||||||
|
|
||||||
|
} else {
|
||||||
|
l = ref.CommitsBetween(newCommit, oldCommit)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("runUpdate.Commit repoId: %v", err)
|
log.Error("runUpdate.Commit repoId: %v", err)
|
||||||
return
|
return
|
||||||
|
@ -65,18 +119,28 @@ func runUpdate(c *cli.Context) {
|
||||||
log.Error("runUpdate.Parse userId: %v", err)
|
log.Error("runUpdate.Parse userId: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sRepoId, err := strconv.Atoi(repoId)
|
|
||||||
|
repos, err := models.GetRepositoryByName(int64(sUserId), repoName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("runUpdate.Parse repoId: %v", err)
|
log.Error("runUpdate.GetRepositoryByName userId: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
commits := make([][]string, 0)
|
commits := make([][]string, 0)
|
||||||
commits = append(commits, []string{lastCommit.Id().String(), lastCommit.Message()})
|
var maxCommits = 3
|
||||||
|
for e := l.Front(); e != nil; e = e.Next() {
|
||||||
|
commit := e.Value.(*git.Commit)
|
||||||
|
commits = append(commits, []string{commit.Id().String(), commit.Message()})
|
||||||
|
if len(commits) >= maxCommits {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//commits = append(commits, []string{lastCommit.Id().String(), lastCommit.Message()})
|
||||||
if err = models.CommitRepoAction(int64(sUserId), userName,
|
if err = models.CommitRepoAction(int64(sUserId), userName,
|
||||||
int64(sRepoId), repoName, commits); err != nil {
|
repos.Id, repoName, refName, &base.PushCommits{l.Len(), commits}); err != nil {
|
||||||
log.Error("runUpdate.models.CommitRepoAction: %v", err)
|
log.Error("runUpdate.models.CommitRepoAction: %v", err)
|
||||||
} else {
|
} else {
|
||||||
l := exec.Command("exec", "git", "update-server-info")
|
|
||||||
l.Run()
|
}
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue