bug fixed for message tag

This commit is contained in:
Lunny Xiao 2014-06-28 23:56:41 +08:00
parent 4ce2fa520a
commit 1c46d68aba
6 changed files with 105 additions and 35 deletions

View file

@ -13,6 +13,7 @@ import (
"strings"
"github.com/codegangsta/cli"
"github.com/satori/go.uuid"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/log"
@ -165,7 +166,9 @@ func runServ(k *cli.Context) {
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.Dir = setting.RepoRootPath
@ -177,4 +180,24 @@ func runServ(k *cli.Context) {
println("Gogs: internal error:", 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)
}
}
}

View file

@ -6,10 +6,8 @@ package cmd
import (
"os"
"strconv"
"github.com/codegangsta/cli"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/log"
)
@ -37,12 +35,27 @@ func runUpdate(c *cli.Context) {
log.GitLogger.Fatal("refName is empty, shouldn't use")
}
userName := os.Getenv("userName")
userId, _ := strconv.ParseInt(os.Getenv("userId"), 10, 64)
repoUserName := os.Getenv("repoUserName")
repoName := os.Getenv("repoName")
//userName := os.Getenv("userName")
//userId, _ := strconv.ParseInt(os.Getenv("userId"), 10, 64)
//repoUserName := os.Getenv("repoUserName")
//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())
}
/*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)
}

View file

@ -35,7 +35,8 @@ func init() {
tables = append(tables, new(User), new(PublicKey), new(Repository), new(Watch),
new(Action), new(Access), new(Issue), new(Comment), new(Oauth2), new(Follow),
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() {

View file

@ -16,6 +16,36 @@ import (
"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 {
//fmt.Println(refName, oldCommitId, newCommitId)
//fmt.Println(userName, repoUserName, repoName)
@ -42,29 +72,6 @@ func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName
return fmt.Errorf("runUpdate.Open repoId: %v", err)
}
newCommit, err := repo.GetCommit(newCommitId)
if err != nil {
return fmt.Errorf("runUpdate GetCommit of newCommitId: %v", err)
}
var l *list.List
// if a new branch
if isNew {
l, err = newCommit.CommitsBefore()
if err != nil {
return fmt.Errorf("Find CommitsBefore erro: %v", err)
}
} else {
l, err = newCommit.CommitsBeforeUntil(oldCommitId)
if err != nil {
return fmt.Errorf("Find CommitsBeforeUntil erro: %v", err)
}
}
if err != nil {
return fmt.Errorf("runUpdate.Commit repoId: %v", err)
}
ru, err := GetUserByName(repoUserName)
if err != nil {
return fmt.Errorf("runUpdate.GetUserByName: %v", err)
@ -103,6 +110,29 @@ func Update(refName, oldCommitId, newCommitId, userName, repoUserName, repoName
return err
}
newCommit, err := repo.GetCommit(newCommitId)
if err != nil {
return fmt.Errorf("runUpdate GetCommit of newCommitId: %v", err)
}
var l *list.List
// if a new branch
if isNew {
l, err = newCommit.CommitsBefore()
if err != nil {
return fmt.Errorf("Find CommitsBefore erro: %v", err)
}
} else {
l, err = newCommit.CommitsBeforeUntil(oldCommitId)
if err != nil {
return fmt.Errorf("Find CommitsBeforeUntil erro: %v", err)
}
}
if err != nil {
return fmt.Errorf("runUpdate.Commit repoId: %v", err)
}
// if commits push
commits := make([]*base.PushCommit, 0)
var maxCommits = 3

View file

@ -56,8 +56,10 @@ type Context struct {
Repository *models.Repository
Owner *models.User
Commit *git.Commit
Tag *git.Tag
GitRepo *git.Repository
BranchName string
TagName string
CommitId string
RepoLink string
CloneLink struct {

View file

@ -185,16 +185,16 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler {
ctx.Repo.CommitId = ctx.Repo.Commit.Id.String()
} else if gitRepo.IsTagExist(refName) {
ctx.Repo.IsBranch = true
ctx.Repo.IsTag = true
ctx.Repo.BranchName = refName
ctx.Repo.Commit, err = gitRepo.GetCommitOfTag(refName)
ctx.Repo.Tag, err = gitRepo.GetTag(refName)
if err != nil {
ctx.Handle(404, "RepoAssignment invalid tag", nil)
return
}
ctx.Repo.Commit, _ = ctx.Repo.Tag.Commit()
ctx.Repo.CommitId = ctx.Repo.Commit.Id.String()
} else if len(refName) == 40 {
ctx.Repo.IsCommit = true
ctx.Repo.CommitId = refName
@ -244,6 +244,7 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler {
}
ctx.Data["BranchName"] = ctx.Repo.BranchName
ctx.Data["TagName"] = ctx.Repo.TagName
brs, err := ctx.Repo.GitRepo.GetBranches()
if err != nil {
log.Error("RepoAssignment(GetBranches): %v", err)