forked from NYANDEV/forgejo
Merge branch 'dev' of github.com:gogits/gogs into dev
This commit is contained in:
commit
99713e1180
8 changed files with 171 additions and 37 deletions
25
cmd/serve.go
25
cmd/serve.go
|
@ -13,6 +13,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
|
"github.com/satori/go.uuid"
|
||||||
|
|
||||||
"github.com/gogits/gogs/models"
|
"github.com/gogits/gogs/models"
|
||||||
"github.com/gogits/gogs/modules/log"
|
"github.com/gogits/gogs/modules/log"
|
||||||
|
@ -165,7 +166,9 @@ func runServ(k *cli.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
models.SetRepoEnvs(user.Id, user.Name, repoName, repoUserName)
|
//models.SetRepoEnvs(user.Id, user.Name, repoName, repoUserName)
|
||||||
|
uuid := uuid.NewV4().String()
|
||||||
|
os.Setenv("uuid", uuid)
|
||||||
|
|
||||||
gitcmd := exec.Command(verb, repoPath)
|
gitcmd := exec.Command(verb, repoPath)
|
||||||
gitcmd.Dir = setting.RepoRootPath
|
gitcmd.Dir = setting.RepoRootPath
|
||||||
|
@ -177,4 +180,24 @@ func runServ(k *cli.Context) {
|
||||||
println("Gogs: internal error:", err)
|
println("Gogs: internal error:", err)
|
||||||
log.GitLogger.Fatal("Fail to execute git command: %v", err)
|
log.GitLogger.Fatal("Fail to execute git command: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if isWrite {
|
||||||
|
tasks, err := models.GetUpdateTasksByUuid(uuid)
|
||||||
|
if err != nil {
|
||||||
|
log.GitLogger.Fatal("Fail to get update task: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, task := range tasks {
|
||||||
|
err = models.Update(task.RefName, task.OldCommitId, task.NewCommitId,
|
||||||
|
user.Name, repoUserName, repoName, user.Id)
|
||||||
|
if err != nil {
|
||||||
|
log.GitLogger.Fatal("Fail to update: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = models.DelUpdateTasksByUuid(uuid)
|
||||||
|
if err != nil {
|
||||||
|
log.GitLogger.Fatal("Fail to del update task: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,8 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
|
|
||||||
"github.com/gogits/gogs/models"
|
"github.com/gogits/gogs/models"
|
||||||
"github.com/gogits/gogs/modules/log"
|
"github.com/gogits/gogs/modules/log"
|
||||||
)
|
)
|
||||||
|
@ -37,12 +35,27 @@ func runUpdate(c *cli.Context) {
|
||||||
log.GitLogger.Fatal("refName is empty, shouldn't use")
|
log.GitLogger.Fatal("refName is empty, shouldn't use")
|
||||||
}
|
}
|
||||||
|
|
||||||
userName := os.Getenv("userName")
|
//userName := os.Getenv("userName")
|
||||||
userId, _ := strconv.ParseInt(os.Getenv("userId"), 10, 64)
|
//userId, _ := strconv.ParseInt(os.Getenv("userId"), 10, 64)
|
||||||
repoUserName := os.Getenv("repoUserName")
|
//repoUserName := os.Getenv("repoUserName")
|
||||||
repoName := os.Getenv("repoName")
|
//repoName := os.Getenv("repoName")
|
||||||
|
uuid := os.Getenv("uuid")
|
||||||
|
|
||||||
if err := models.Update(args[0], args[1], args[2], userName, repoUserName, repoName, userId); err != nil {
|
task := models.UpdateTask{
|
||||||
|
Uuid: uuid,
|
||||||
|
RefName: args[0],
|
||||||
|
OldCommitId: args[1],
|
||||||
|
NewCommitId: args[2],
|
||||||
|
}
|
||||||
|
|
||||||
|
log.GitLogger.Error("%v", task)
|
||||||
|
|
||||||
|
if err := models.AddUpdateTask(&task); err != nil {
|
||||||
log.GitLogger.Fatal(err.Error())
|
log.GitLogger.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*if err := models.Update(args[0], args[1], args[2], userName, repoUserName, repoName, userId); err != nil {
|
||||||
|
log.GitLogger.Fatal(err.Error())
|
||||||
|
}*/
|
||||||
|
//setEnvs(args[0], args[1], args[2], userName, repoUserName, repoName, userId)
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,8 @@ func init() {
|
||||||
tables = append(tables, new(User), new(PublicKey), new(Repository), new(Watch),
|
tables = append(tables, new(User), new(PublicKey), new(Repository), new(Watch),
|
||||||
new(Action), new(Access), new(Issue), new(Comment), new(Oauth2), new(Follow),
|
new(Action), new(Access), new(Issue), new(Comment), new(Oauth2), new(Follow),
|
||||||
new(Mirror), new(Release), new(LoginSource), new(Webhook), new(IssueUser),
|
new(Mirror), new(Release), new(LoginSource), new(Webhook), new(IssueUser),
|
||||||
new(Milestone), new(Label), new(HookTask), new(Team), new(OrgUser), new(TeamUser))
|
new(Milestone), new(Label), new(HookTask), new(Team), new(OrgUser), new(TeamUser),
|
||||||
|
new(UpdateTask))
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadModelsConfig() {
|
func LoadModelsConfig() {
|
||||||
|
|
|
@ -302,7 +302,7 @@ func MigrateRepository(u *User, name, desc string, private, mirror bool, url str
|
||||||
|
|
||||||
// extractGitBareZip extracts git-bare.zip to repository path.
|
// extractGitBareZip extracts git-bare.zip to repository path.
|
||||||
func extractGitBareZip(repoPath string) error {
|
func extractGitBareZip(repoPath string) error {
|
||||||
z, err := zip.Open(path.Join(setting.RepoRootPath, "git-bare.zip"))
|
z, err := zip.Open(filepath.Join(setting.RepoRootPath, "git-bare.zip"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,39 @@ import (
|
||||||
"github.com/gogits/gogs/modules/log"
|
"github.com/gogits/gogs/modules/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type UpdateTask struct {
|
||||||
|
Id int64
|
||||||
|
Uuid string `xorm:"index"`
|
||||||
|
RefName string
|
||||||
|
OldCommitId string
|
||||||
|
NewCommitId string
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddUpdateTask(task *UpdateTask) error {
|
||||||
|
_, err := x.Insert(task)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetUpdateTasksByUuid(uuid string) ([]*UpdateTask, error) {
|
||||||
|
task := &UpdateTask{
|
||||||
|
Uuid: uuid,
|
||||||
|
}
|
||||||
|
tasks := make([]*UpdateTask, 0)
|
||||||
|
err := x.Find(&tasks, task)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return tasks, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func DelUpdateTasksByUuid(uuid string) error {
|
||||||
|
_, err := x.Delete(&UpdateTask{Uuid: uuid})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName string, userId int64) error {
|
func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName string, userId int64) error {
|
||||||
|
//fmt.Println(refName, oldCommitId, newCommitId)
|
||||||
|
//fmt.Println(userName, repoUserName, repoName)
|
||||||
isNew := strings.HasPrefix(oldCommitId, "0000000")
|
isNew := strings.HasPrefix(oldCommitId, "0000000")
|
||||||
if isNew &&
|
if isNew &&
|
||||||
strings.HasPrefix(newCommitId, "0000000") {
|
strings.HasPrefix(newCommitId, "0000000") {
|
||||||
|
@ -40,6 +72,44 @@ func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName
|
||||||
return fmt.Errorf("runUpdate.Open repoId: %v", err)
|
return fmt.Errorf("runUpdate.Open repoId: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ru, err := GetUserByName(repoUserName)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("runUpdate.GetUserByName: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
repos, err := GetRepositoryByName(ru.Id, repoName)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("runUpdate.GetRepositoryByName userId: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// if tags push
|
||||||
|
if strings.HasPrefix(refName, "refs/tags/") {
|
||||||
|
tagName := git.RefEndName(refName)
|
||||||
|
tag, err := repo.GetTag(tagName)
|
||||||
|
if err != nil {
|
||||||
|
log.GitLogger.Fatal("runUpdate.GetTag: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var actEmail string
|
||||||
|
if tag.Tagger != nil {
|
||||||
|
actEmail = tag.Tagger.Email
|
||||||
|
} else {
|
||||||
|
cmt, err := tag.Commit()
|
||||||
|
if err != nil {
|
||||||
|
log.GitLogger.Fatal("runUpdate.GetTag Commit: %v", err)
|
||||||
|
}
|
||||||
|
actEmail = cmt.Committer.Email
|
||||||
|
}
|
||||||
|
|
||||||
|
commit := &base.PushCommits{}
|
||||||
|
|
||||||
|
if err = CommitRepoAction(userId, ru.Id, userName, actEmail,
|
||||||
|
repos.Id, repoUserName, repoName, refName, commit); err != nil {
|
||||||
|
log.GitLogger.Fatal("runUpdate.models.CommitRepoAction: %s/%s:%v", repoUserName, repoName, err)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
newCommit, err := repo.GetCommit(newCommitId)
|
newCommit, err := repo.GetCommit(newCommitId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("runUpdate GetCommit of newCommitId: %v", err)
|
return fmt.Errorf("runUpdate GetCommit of newCommitId: %v", err)
|
||||||
|
@ -63,21 +133,13 @@ func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName
|
||||||
return fmt.Errorf("runUpdate.Commit repoId: %v", err)
|
return fmt.Errorf("runUpdate.Commit repoId: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ru, err := GetUserByName(repoUserName)
|
// if commits push
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("runUpdate.GetUserByName: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
repos, err := GetRepositoryByName(ru.Id, repoName)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("runUpdate.GetRepositoryByName userId: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
commits := make([]*base.PushCommit, 0)
|
commits := make([]*base.PushCommit, 0)
|
||||||
var maxCommits = 3
|
var maxCommits = 3
|
||||||
var actEmail string
|
var actEmail string
|
||||||
for e := l.Front(); e != nil; e = e.Next() {
|
for e := l.Front(); e != nil; e = e.Next() {
|
||||||
commit := e.Value.(*git.Commit)
|
commit := e.Value.(*git.Commit)
|
||||||
|
|
||||||
if actEmail == "" {
|
if actEmail == "" {
|
||||||
actEmail = commit.Committer.Email
|
actEmail = commit.Committer.Email
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,8 +56,10 @@ type Context struct {
|
||||||
Repository *models.Repository
|
Repository *models.Repository
|
||||||
Owner *models.User
|
Owner *models.User
|
||||||
Commit *git.Commit
|
Commit *git.Commit
|
||||||
|
Tag *git.Tag
|
||||||
GitRepo *git.Repository
|
GitRepo *git.Repository
|
||||||
BranchName string
|
BranchName string
|
||||||
|
TagName string
|
||||||
CommitId string
|
CommitId string
|
||||||
RepoLink string
|
RepoLink string
|
||||||
CloneLink struct {
|
CloneLink struct {
|
||||||
|
|
|
@ -185,16 +185,16 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler {
|
||||||
ctx.Repo.CommitId = ctx.Repo.Commit.Id.String()
|
ctx.Repo.CommitId = ctx.Repo.Commit.Id.String()
|
||||||
|
|
||||||
} else if gitRepo.IsTagExist(refName) {
|
} else if gitRepo.IsTagExist(refName) {
|
||||||
ctx.Repo.IsBranch = true
|
ctx.Repo.IsTag = true
|
||||||
ctx.Repo.BranchName = refName
|
ctx.Repo.BranchName = refName
|
||||||
|
|
||||||
ctx.Repo.Commit, err = gitRepo.GetCommitOfTag(refName)
|
ctx.Repo.Tag, err = gitRepo.GetTag(refName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(404, "RepoAssignment invalid tag", nil)
|
ctx.Handle(404, "RepoAssignment invalid tag", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
ctx.Repo.Commit, _ = ctx.Repo.Tag.Commit()
|
||||||
ctx.Repo.CommitId = ctx.Repo.Commit.Id.String()
|
ctx.Repo.CommitId = ctx.Repo.Commit.Id.String()
|
||||||
|
|
||||||
} else if len(refName) == 40 {
|
} else if len(refName) == 40 {
|
||||||
ctx.Repo.IsCommit = true
|
ctx.Repo.IsCommit = true
|
||||||
ctx.Repo.CommitId = refName
|
ctx.Repo.CommitId = refName
|
||||||
|
@ -244,6 +244,7 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["BranchName"] = ctx.Repo.BranchName
|
ctx.Data["BranchName"] = ctx.Repo.BranchName
|
||||||
|
ctx.Data["TagName"] = ctx.Repo.TagName
|
||||||
brs, err := ctx.Repo.GitRepo.GetBranches()
|
brs, err := ctx.Repo.GitRepo.GetBranches()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("RepoAssignment(GetBranches): %v", err)
|
log.Error("RepoAssignment(GetBranches): %v", err)
|
||||||
|
|
|
@ -7,6 +7,7 @@ package repo
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -130,24 +131,49 @@ func Http(ctx *middleware.Context, params martini.Params) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
config := Config{setting.RepoRootPath, "git", true, true, func(rpc string, input []byte) {
|
var f func(rpc string, input []byte)
|
||||||
|
|
||||||
|
f = func(rpc string, input []byte) {
|
||||||
if rpc == "receive-pack" {
|
if rpc == "receive-pack" {
|
||||||
firstLine := bytes.IndexRune(input, '\000')
|
var lastLine int64 = 0
|
||||||
if firstLine > -1 {
|
|
||||||
fields := strings.Fields(string(input[:firstLine]))
|
for {
|
||||||
if len(fields) == 3 {
|
head := input[lastLine : lastLine+2]
|
||||||
|
if head[0] == '0' && head[1] == '0' {
|
||||||
|
size, err := strconv.ParseInt(string(input[lastLine+2:lastLine+4]), 16, 32)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("%v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if size == 0 {
|
||||||
|
//fmt.Println(string(input[lastLine:]))
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
line := input[lastLine : lastLine+size]
|
||||||
|
idx := bytes.IndexRune(line, '\000')
|
||||||
|
if idx > -1 {
|
||||||
|
line = line[:idx]
|
||||||
|
}
|
||||||
|
fields := strings.Fields(string(line))
|
||||||
|
if len(fields) >= 3 {
|
||||||
oldCommitId := fields[0][4:]
|
oldCommitId := fields[0][4:]
|
||||||
newCommitId := fields[1]
|
newCommitId := fields[1]
|
||||||
refName := fields[2]
|
refName := fields[2]
|
||||||
|
|
||||||
if err = models.Update(refName, oldCommitId, newCommitId, authUsername, username, reponame, authUser.Id); err != nil {
|
models.Update(refName, oldCommitId, newCommitId, authUsername, username, reponame, authUser.Id)
|
||||||
log.GitLogger.Error(err.Error())
|
}
|
||||||
return
|
lastLine = lastLine + size
|
||||||
|
} else {
|
||||||
|
//fmt.Println("ddddddddddd")
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}}
|
|
||||||
|
config := Config{setting.RepoRootPath, "git", true, true, f}
|
||||||
|
|
||||||
handler := HttpBackend(&config)
|
handler := HttpBackend(&config)
|
||||||
handler(ctx.ResponseWriter, ctx.Req)
|
handler(ctx.ResponseWriter, ctx.Req)
|
||||||
|
@ -240,8 +266,14 @@ func serviceRpc(rpc string, hr handler) {
|
||||||
w.Header().Set("Content-Type", fmt.Sprintf("application/x-git-%s-result", rpc))
|
w.Header().Set("Content-Type", fmt.Sprintf("application/x-git-%s-result", rpc))
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
|
|
||||||
input, _ := ioutil.ReadAll(r.Body)
|
var input []byte
|
||||||
br := bytes.NewReader(input)
|
var br io.Reader
|
||||||
|
if hr.Config.OnSucceed != nil {
|
||||||
|
input, _ = ioutil.ReadAll(r.Body)
|
||||||
|
br = bytes.NewReader(input)
|
||||||
|
} else {
|
||||||
|
br = r.Body
|
||||||
|
}
|
||||||
|
|
||||||
args := []string{rpc, "--stateless-rpc", dir}
|
args := []string{rpc, "--stateless-rpc", dir}
|
||||||
cmd := exec.Command(hr.Config.GitBinPath, args...)
|
cmd := exec.Command(hr.Config.GitBinPath, args...)
|
||||||
|
|
Loading…
Reference in a new issue