diff options
author | Matthias Loibl <mail@matthiasloibl.com> | 2017-01-17 06:58:58 +0100 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-01-17 13:58:58 +0800 |
commit | d1006150fb3a82a8dd6e418578dc44474191bfd0 (patch) | |
tree | 99d13e24a1be0d118686106c1f6bbbe4dbaf6793 /models/release.go | |
parent | 6dd096b7f08799ff27d9e34356fb1163ca10f388 (diff) | |
download | gitea-d1006150fb3a82a8dd6e418578dc44474191bfd0.tar.gz gitea-d1006150fb3a82a8dd6e418578dc44474191bfd0.zip |
Refactor process package and introduce ProcessManager{} with tests (#75)
* Add a process.Manager singleton with process.GetManager()
* Use process.GetManager everywhere
* Fix godoc comments for process module
* Increment process counter id after locking the mutex
Diffstat (limited to 'models/release.go')
-rw-r--r-- | models/release.go | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/models/release.go b/models/release.go index 113a0d68e4..f60213ee92 100644 --- a/models/release.go +++ b/models/release.go @@ -10,14 +10,11 @@ import ( "strings" "time" - "github.com/go-xorm/xorm" - "code.gitea.io/git" - "code.gitea.io/gitea/modules/process" "code.gitea.io/gitea/modules/setting" - api "code.gitea.io/sdk/gitea" + "github.com/go-xorm/xorm" ) // Release represents a release of repository. @@ -159,7 +156,7 @@ func createTag(gitRepo *git.Repository, rel *Release) error { func addReleaseAttachments(releaseID int64, attachmentUUIDs []string) (err error) { // Check attachments - var attachments = make([]*Attachment,0) + var attachments = make([]*Attachment, 0) for _, uuid := range attachmentUUIDs { attach, err := getAttachmentByUUID(x, uuid) if err != nil { @@ -257,9 +254,10 @@ func GetReleasesByRepoIDAndNames(repoID int64, tagNames []string) (rels []*Relea } type releaseMetaSearch struct { - ID [] int64 - Rel [] *Release + ID []int64 + Rel []*Release } + func (s releaseMetaSearch) Len() int { return len(s.ID) } @@ -272,18 +270,18 @@ func (s releaseMetaSearch) Less(i, j int) bool { } // GetReleaseAttachments retrieves the attachments for releases -func GetReleaseAttachments(rels ... *Release) (err error){ +func GetReleaseAttachments(rels ...*Release) (err error) { if len(rels) == 0 { return } - // To keep this efficient as possible sort all releases by id, + // To keep this efficient as possible sort all releases by id, // select attachments by release id, // then merge join them // Sort var sortedRels = releaseMetaSearch{ID: make([]int64, len(rels)), Rel: make([]*Release, len(rels))} - var attachments [] *Attachment + var attachments []*Attachment for index, element := range rels { element.Attachments = []*Attachment{} sortedRels.ID[index] = element.ID @@ -375,7 +373,7 @@ func DeleteReleaseByID(id int64, u *User, delTag bool) error { } if delTag { - _, stderr, err := process.ExecDir(-1, repo.RepoPath(), + _, stderr, err := process.GetManager().ExecDir(-1, repo.RepoPath(), fmt.Sprintf("DeleteReleaseByID (git tag -d): %d", rel.ID), "git", "tag", "-d", rel.TagName) if err != nil && !strings.Contains(stderr, "not found") { |