77package models
88
99import (
10- "container/list"
1110 "fmt"
1211 "regexp"
1312 "strconv"
@@ -191,11 +190,11 @@ type Comment struct {
191190 RefIssue * Issue `xorm:"-"`
192191 RefComment * Comment `xorm:"-"`
193192
194- Commits * list. List `xorm:"-"`
195- OldCommit string `xorm:"-"`
196- NewCommit string `xorm:"-"`
197- CommitsNum int64 `xorm:"-"`
198- IsForcePush bool `xorm:"-"`
193+ Commits [] * SignCommitWithStatuses `xorm:"-"`
194+ OldCommit string `xorm:"-"`
195+ NewCommit string `xorm:"-"`
196+ CommitsNum int64 `xorm:"-"`
197+ IsForcePush bool `xorm:"-"`
199198}
200199
201200// PushActionContent is content of push pull comment
@@ -675,13 +674,8 @@ func (c *Comment) LoadPushCommits() (err error) {
675674 }
676675 defer gitRepo .Close ()
677676
678- c .Commits = gitRepo .GetCommitsFromIDs (data .CommitIDs )
679- c .CommitsNum = int64 (c .Commits .Len ())
680- if c .CommitsNum > 0 {
681- c .Commits = ValidateCommitsWithEmails (c .Commits )
682- c .Commits = ParseCommitsWithSignature (c .Commits , c .Issue .Repo )
683- c .Commits = ParseCommitsWithStatus (c .Commits , c .Issue .Repo )
684- }
677+ c .Commits = ConvertFromGitCommit (gitRepo .GetCommitsFromIDs (data .CommitIDs ), c .Issue .Repo )
678+ c .CommitsNum = int64 (len (c .Commits ))
685679 }
686680
687681 return err
@@ -1293,21 +1287,17 @@ func getCommitIDsFromRepo(repo *Repository, oldCommitID, newCommitID, baseBranch
12931287 return nil , false , err
12941288 }
12951289
1296- var (
1297- commits * list.List
1298- commitChecks map [string ]commitBranchCheckItem
1299- )
1300- commits , err = newCommit .CommitsBeforeUntil (oldCommitID )
1290+ commits , err := newCommit .CommitsBeforeUntil (oldCommitID )
13011291 if err != nil {
13021292 return nil , false , err
13031293 }
13041294
1305- commitIDs = make ([]string , 0 , commits . Len ( ))
1306- commitChecks = make (map [string ]commitBranchCheckItem )
1295+ commitIDs = make ([]string , 0 , len ( commits ))
1296+ commitChecks : = make (map [string ]* commitBranchCheckItem )
13071297
1308- for e := commits . Front (); e != nil ; e = e . Next () {
1309- commitChecks [e . Value .( * git. Commit ). ID .String ()] = commitBranchCheckItem {
1310- Commit : e . Value .( * git. Commit ) ,
1298+ for _ , commit := range commits {
1299+ commitChecks [commit . ID .String ()] = & commitBranchCheckItem {
1300+ Commit : commit ,
13111301 Checked : false ,
13121302 }
13131303 }
@@ -1316,8 +1306,8 @@ func getCommitIDsFromRepo(repo *Repository, oldCommitID, newCommitID, baseBranch
13161306 return
13171307 }
13181308
1319- for e := commits . Back (); e != nil ; e = e . Prev () {
1320- commitID := e . Value .( * git. Commit ) .ID .String ()
1309+ for i := len ( commits ) - 1 ; i >= 0 ; i -- {
1310+ commitID := commits [ i ] .ID .String ()
13211311 if item , ok := commitChecks [commitID ]; ok && item .Checked {
13221312 commitIDs = append (commitIDs , commitID )
13231313 }
@@ -1331,64 +1321,49 @@ type commitBranchCheckItem struct {
13311321 Checked bool
13321322}
13331323
1334- func commitBranchCheck (gitRepo * git.Repository , startCommit * git.Commit , endCommitID , baseBranch string , commitList map [string ]commitBranchCheckItem ) (err error ) {
1335- var (
1336- item commitBranchCheckItem
1337- ok bool
1338- listItem * list.Element
1339- tmp string
1340- )
1341-
1324+ func commitBranchCheck (gitRepo * git.Repository , startCommit * git.Commit , endCommitID , baseBranch string , commitList map [string ]* commitBranchCheckItem ) error {
13421325 if startCommit .ID .String () == endCommitID {
1343- return
1326+ return nil
13441327 }
13451328
1346- checkStack := list .New ()
1347- checkStack .PushBack (startCommit .ID .String ())
1348- listItem = checkStack .Back ()
1329+ checkStack := make ([]string , 0 , 10 )
1330+ checkStack = append (checkStack , startCommit .ID .String ())
13491331
1350- for listItem != nil {
1351- tmp = listItem . Value .( string )
1352- checkStack . Remove ( listItem )
1332+ for len ( checkStack ) > 0 {
1333+ commitID := checkStack [ 0 ]
1334+ checkStack = checkStack [ 1 :]
13531335
1354- if item , ok = commitList [tmp ]; ! ok {
1355- listItem = checkStack . Back ()
1336+ item , ok : = commitList [commitID ]
1337+ if ! ok {
13561338 continue
13571339 }
13581340
13591341 if item .Commit .ID .String () == endCommitID {
1360- listItem = checkStack .Back ()
13611342 continue
13621343 }
13631344
1364- if err = item .Commit .LoadBranchName (); err != nil {
1365- return
1345+ if err : = item .Commit .LoadBranchName (); err != nil {
1346+ return err
13661347 }
13671348
13681349 if item .Commit .Branch == baseBranch {
1369- listItem = checkStack .Back ()
13701350 continue
13711351 }
13721352
13731353 if item .Checked {
1374- listItem = checkStack .Back ()
13751354 continue
13761355 }
13771356
13781357 item .Checked = true
1379- commitList [tmp ] = item
13801358
13811359 parentNum := item .Commit .ParentCount ()
13821360 for i := 0 ; i < parentNum ; i ++ {
1383- var parentCommit * git.Commit
1384- parentCommit , err = item .Commit .Parent (i )
1361+ parentCommit , err := item .Commit .Parent (i )
13851362 if err != nil {
1386- return
1363+ return err
13871364 }
1388- checkStack . PushBack ( parentCommit .ID .String ())
1365+ checkStack = append ( checkStack , parentCommit .ID .String ())
13891366 }
1390-
1391- listItem = checkStack .Back ()
13921367 }
13931368 return nil
13941369}
0 commit comments