7
7
package models
8
8
9
9
import (
10
- "container/list"
11
10
"fmt"
12
11
"regexp"
13
12
"strconv"
@@ -191,11 +190,11 @@ type Comment struct {
191
190
RefIssue * Issue `xorm:"-"`
192
191
RefComment * Comment `xorm:"-"`
193
192
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:"-"`
199
198
}
200
199
201
200
// PushActionContent is content of push pull comment
@@ -675,13 +674,8 @@ func (c *Comment) LoadPushCommits() (err error) {
675
674
}
676
675
defer gitRepo .Close ()
677
676
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 ))
685
679
}
686
680
687
681
return err
@@ -1293,21 +1287,17 @@ func getCommitIDsFromRepo(repo *Repository, oldCommitID, newCommitID, baseBranch
1293
1287
return nil , false , err
1294
1288
}
1295
1289
1296
- var (
1297
- commits * list.List
1298
- commitChecks map [string ]commitBranchCheckItem
1299
- )
1300
- commits , err = newCommit .CommitsBeforeUntil (oldCommitID )
1290
+ commits , err := newCommit .CommitsBeforeUntil (oldCommitID )
1301
1291
if err != nil {
1302
1292
return nil , false , err
1303
1293
}
1304
1294
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 )
1307
1297
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 ,
1311
1301
Checked : false ,
1312
1302
}
1313
1303
}
@@ -1316,8 +1306,8 @@ func getCommitIDsFromRepo(repo *Repository, oldCommitID, newCommitID, baseBranch
1316
1306
return
1317
1307
}
1318
1308
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 ()
1321
1311
if item , ok := commitChecks [commitID ]; ok && item .Checked {
1322
1312
commitIDs = append (commitIDs , commitID )
1323
1313
}
@@ -1331,64 +1321,49 @@ type commitBranchCheckItem struct {
1331
1321
Checked bool
1332
1322
}
1333
1323
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 {
1342
1325
if startCommit .ID .String () == endCommitID {
1343
- return
1326
+ return nil
1344
1327
}
1345
1328
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 ())
1349
1331
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 :]
1353
1335
1354
- if item , ok = commitList [tmp ]; ! ok {
1355
- listItem = checkStack . Back ()
1336
+ item , ok : = commitList [commitID ]
1337
+ if ! ok {
1356
1338
continue
1357
1339
}
1358
1340
1359
1341
if item .Commit .ID .String () == endCommitID {
1360
- listItem = checkStack .Back ()
1361
1342
continue
1362
1343
}
1363
1344
1364
- if err = item .Commit .LoadBranchName (); err != nil {
1365
- return
1345
+ if err : = item .Commit .LoadBranchName (); err != nil {
1346
+ return err
1366
1347
}
1367
1348
1368
1349
if item .Commit .Branch == baseBranch {
1369
- listItem = checkStack .Back ()
1370
1350
continue
1371
1351
}
1372
1352
1373
1353
if item .Checked {
1374
- listItem = checkStack .Back ()
1375
1354
continue
1376
1355
}
1377
1356
1378
1357
item .Checked = true
1379
- commitList [tmp ] = item
1380
1358
1381
1359
parentNum := item .Commit .ParentCount ()
1382
1360
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 )
1385
1362
if err != nil {
1386
- return
1363
+ return err
1387
1364
}
1388
- checkStack . PushBack ( parentCommit .ID .String ())
1365
+ checkStack = append ( checkStack , parentCommit .ID .String ())
1389
1366
}
1390
-
1391
- listItem = checkStack .Back ()
1392
1367
}
1393
1368
return nil
1394
1369
}
0 commit comments