diff options
author | Unknwon <u@gogs.io> | 2016-08-15 18:40:32 -0700 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2016-08-15 18:40:32 -0700 |
commit | 4042d1f0c3c545773f81e2ca1b4eb8662bc4c425 (patch) | |
tree | 9bbbb404c9ee719f10e379cfc9699fddeaa94c0a /routers | |
parent | 4a46613916cdfa6a168746aba6abcd698cd17875 (diff) | |
download | gitea-4042d1f0c3c545773f81e2ca1b4eb8662bc4c425.tar.gz gitea-4042d1f0c3c545773f81e2ca1b4eb8662bc4c425.zip |
models/issue: improve quality and performance of NewIssue function
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/repo/issue.go | 4 | ||||
-rw-r--r-- | routers/repo/branch.go | 50 | ||||
-rw-r--r-- | routers/repo/issue.go | 10 |
3 files changed, 7 insertions, 57 deletions
diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 1440a17cdc..0d5ba756bb 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -149,9 +149,9 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) { } if ctx.Repo.IsWriter() && form.Milestone != nil && issue.MilestoneID != *form.Milestone { - oldMid := issue.MilestoneID + oldMilestoneID := issue.MilestoneID issue.MilestoneID = *form.Milestone - if err = models.ChangeMilestoneAssign(oldMid, issue); err != nil { + if err = models.ChangeMilestoneAssign(issue, oldMilestoneID); err != nil { ctx.Error(500, "ChangeMilestoneAssign", err) return } diff --git a/routers/repo/branch.go b/routers/repo/branch.go index c8407114a9..00f30b0f13 100644 --- a/routers/repo/branch.go +++ b/routers/repo/branch.go @@ -5,13 +5,8 @@ package repo import ( - "github.com/gogits/gogs/models" - "github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/context" - "github.com/gogits/gogs/modules/log" - "net/url" - "strings" ) const ( @@ -34,48 +29,3 @@ func Branches(ctx *context.Context) { ctx.Data["Branches"] = brs ctx.HTML(200, BRANCH) } - -func NewBranchPost(ctx *context.Context, form auth.NewBranchForm) { - oldBranchName := form.OldBranchName - branchName := form.BranchName - - if ctx.HasError() || !ctx.Repo.IsWriter() || branchName == oldBranchName { - ctx.Redirect(ctx.Repo.RepoLink + "/src/" + oldBranchName) - return - } - - branchName = url.QueryEscape(strings.Replace(strings.Trim(branchName, " "), " ", "-", -1)) - - if _, err := ctx.Repo.Repository.GetBranch(branchName); err == nil { - ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName) - return - } - - if err := ctx.Repo.Repository.CreateNewBranch(ctx.User, oldBranchName, branchName); err != nil { - ctx.Handle(404, "repo.Branches(CreateNewBranch)", err) - log.Error(4, "%s: %v", "EditFile", err) - return - } - - // Was successful, so now need to call models.CommitRepoAction() with the new commitID for webhooks and watchers - if branch, err := ctx.Repo.Repository.GetBranch(branchName); err != nil { - log.Error(4, "repo.Repository.GetBranch(%s): %v", branchName, err) - } else if commit, err := branch.GetCommit(); err != nil { - log.Error(4, "branch.GetCommit(): %v", err) - } else { - pc := &models.PushCommits{ - Len: 1, - Commits: []*models.PushCommit{models.CommitToPushCommit(commit)}, - } - oldCommitID := "0000000000000000000000000000000000000000" // New Branch so we use all 0s - newCommitID := commit.ID.String() - if err := models.CommitRepoAction(ctx.User.ID, ctx.Repo.Owner.ID, ctx.User.LowerName, ctx.Repo.Owner.Email, - ctx.Repo.Repository.ID, ctx.Repo.Owner.LowerName, ctx.Repo.Repository.Name, "refs/heads/"+branchName, pc, - oldCommitID, newCommitID); err != nil { - log.Error(4, "models.CommitRepoAction(branch = %s): %v", branchName, err) - } - models.HookQueue.Add(ctx.Repo.Repository.ID) - } - - ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName) -} diff --git a/routers/repo/issue.go b/routers/repo/issue.go index b79ded5329..3b36556c00 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -754,9 +754,9 @@ func UpdateIssueMilestone(ctx *context.Context) { return } - oldMid := issue.MilestoneID - mid := ctx.QueryInt64("id") - if oldMid == mid { + oldMilestoneID := issue.MilestoneID + milestoneID := ctx.QueryInt64("id") + if oldMilestoneID == milestoneID { ctx.JSON(200, map[string]interface{}{ "ok": true, }) @@ -764,8 +764,8 @@ func UpdateIssueMilestone(ctx *context.Context) { } // Not check for invalid milestone id and give responsibility to owners. - issue.MilestoneID = mid - if err := models.ChangeMilestoneAssign(oldMid, issue); err != nil { + issue.MilestoneID = milestoneID + if err := models.ChangeMilestoneAssign(issue, oldMilestoneID); err != nil { ctx.Handle(500, "ChangeMilestoneAssign", err) return } |