@@ -12,7 +12,6 @@ import (
12
12
"os"
13
13
"path/filepath"
14
14
"strings"
15
- "sync"
16
15
"time"
17
16
18
17
"code.gitea.io/gitea/models"
@@ -42,9 +41,9 @@ type GiteaLocalUploader struct {
42
41
repoOwner string
43
42
repoName string
44
43
repo * repo_model.Repository
45
- labels sync. Map
46
- milestones sync. Map
47
- issues sync. Map
44
+ labels map [ string ] * models. Label
45
+ milestones map [ string ] int64
46
+ issues map [ int64 ] * models. Issue
48
47
gitRepo * git.Repository
49
48
prHeadCache map [string ]struct {}
50
49
userMap map [int64 ]int64 // external user id mapping to user id
@@ -59,6 +58,8 @@ func NewGiteaLocalUploader(ctx context.Context, doer *user_model.User, repoOwner
59
58
doer : doer ,
60
59
repoOwner : repoOwner ,
61
60
repoName : repoName ,
61
+ milestones : make (map [string ]int64 ),
62
+ issues : make (map [int64 ]* models.Issue ),
62
63
prHeadCache : make (map [string ]struct {}),
63
64
userMap : make (map [int64 ]int64 ),
64
65
prCache : make (map [int64 ]* models.PullRequest ),
@@ -201,7 +202,7 @@ func (g *GiteaLocalUploader) CreateMilestones(milestones ...*base.Milestone) err
201
202
}
202
203
203
204
for _ , ms := range mss {
204
- g .milestones . Store ( ms .Name , ms .ID )
205
+ g .milestones [ ms .Name ] = ms .ID
205
206
}
206
207
return nil
207
208
}
@@ -223,7 +224,7 @@ func (g *GiteaLocalUploader) CreateLabels(labels ...*base.Label) error {
223
224
return err
224
225
}
225
226
for _ , lb := range lbs {
226
- g .labels . Store ( lb .Name , lb )
227
+ g .labels [ lb .Name ] = lb
227
228
}
228
229
return nil
229
230
}
@@ -333,19 +334,13 @@ func (g *GiteaLocalUploader) CreateIssues(issues ...*base.Issue) error {
333
334
for _ , issue := range issues {
334
335
var labels []* models.Label
335
336
for _ , label := range issue .Labels {
336
- lb , ok := g .labels . Load ( label .Name )
337
+ lb , ok := g .labels [ label .Name ]
337
338
if ok {
338
- labels = append (labels , lb .( * models. Label ) )
339
+ labels = append (labels , lb )
339
340
}
340
341
}
341
342
342
- var milestoneID int64
343
- if issue .Milestone != "" {
344
- milestone , ok := g .milestones .Load (issue .Milestone )
345
- if ok {
346
- milestoneID = milestone .(int64 )
347
- }
348
- }
343
+ milestoneID := g .milestones [issue .Milestone ]
349
344
350
345
if issue .Created .IsZero () {
351
346
if issue .Closed != nil {
@@ -404,7 +399,7 @@ func (g *GiteaLocalUploader) CreateIssues(issues ...*base.Issue) error {
404
399
}
405
400
406
401
for _ , is := range iss {
407
- g .issues . Store ( is .Index , is )
402
+ g .issues [ is .Index ] = is
408
403
}
409
404
}
410
405
@@ -416,16 +411,14 @@ func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error {
416
411
cms := make ([]* models.Comment , 0 , len (comments ))
417
412
for _ , comment := range comments {
418
413
var issue * models.Issue
419
- issueInter , ok := g .issues . Load ( comment .IssueIndex )
414
+ issue , ok := g .issues [ comment .IssueIndex ]
420
415
if ! ok {
421
416
var err error
422
417
issue , err = models .GetIssueByIndex (g .repo .ID , comment .IssueIndex )
423
418
if err != nil {
424
419
return err
425
420
}
426
- g .issues .Store (comment .IssueIndex , issue )
427
- } else {
428
- issue = issueInter .(* models.Issue )
421
+ g .issues [comment .IssueIndex ] = issue
429
422
}
430
423
431
424
if comment .Created .IsZero () {
@@ -487,7 +480,7 @@ func (g *GiteaLocalUploader) CreatePullRequests(prs ...*base.PullRequest) error
487
480
return err
488
481
}
489
482
for _ , pr := range gprs {
490
- g .issues . Store ( pr .Issue .Index , pr .Issue )
483
+ g .issues [ pr .Issue .Index ] = pr .Issue
491
484
pull .AddToTaskQueue (pr )
492
485
}
493
486
return nil
@@ -496,19 +489,13 @@ func (g *GiteaLocalUploader) CreatePullRequests(prs ...*base.PullRequest) error
496
489
func (g * GiteaLocalUploader ) newPullRequest (pr * base.PullRequest ) (* models.PullRequest , error ) {
497
490
var labels []* models.Label
498
491
for _ , label := range pr .Labels {
499
- lb , ok := g .labels . Load ( label .Name )
492
+ lb , ok := g .labels [ label .Name ]
500
493
if ok {
501
- labels = append (labels , lb .( * models. Label ) )
494
+ labels = append (labels , lb )
502
495
}
503
496
}
504
497
505
- var milestoneID int64
506
- if pr .Milestone != "" {
507
- milestone , ok := g .milestones .Load (pr .Milestone )
508
- if ok {
509
- milestoneID = milestone .(int64 )
510
- }
511
- }
498
+ milestoneID := g .milestones [pr .Milestone ]
512
499
513
500
// download patch file
514
501
err := func () error {
@@ -700,18 +687,15 @@ func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error {
700
687
cms := make ([]* models.Review , 0 , len (reviews ))
701
688
for _ , review := range reviews {
702
689
var issue * models.Issue
703
- issueInter , ok := g .issues . Load ( review .IssueIndex )
690
+ issue , ok := g .issues [ review .IssueIndex ]
704
691
if ! ok {
705
692
var err error
706
693
issue , err = models .GetIssueByIndex (g .repo .ID , review .IssueIndex )
707
694
if err != nil {
708
695
return err
709
696
}
710
- g .issues .Store (review .IssueIndex , issue )
711
- } else {
712
- issue = issueInter .(* models.Issue )
697
+ g .issues [review .IssueIndex ] = issue
713
698
}
714
-
715
699
if review .CreatedAt .IsZero () {
716
700
review .CreatedAt = time .Unix (int64 (issue .CreatedUnix ), 0 )
717
701
}
0 commit comments