@@ -573,6 +573,7 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
573
573
}
574
574
}
575
575
576
+ var commentCommits = opts .Commits .Commits
576
577
if len (opts .Commits .Commits ) > setting .UI .FeedMaxCommitNum {
577
578
opts .Commits .Commits = opts .Commits .Commits [:setting .UI .FeedMaxCommitNum ]
578
579
}
@@ -653,7 +654,7 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
653
654
}
654
655
655
656
issues := make ([]* Issue , 0 , len (prs ))
656
- lastCommitID := opts . Commits . Commits [len (opts . Commits . Commits )- 1 ].Sha1
657
+ lastCommitID := commentCommits [len (commentCommits )- 1 ].Sha1
657
658
for _ , pr := range prs {
658
659
pr .LastCommitID = lastCommitID
659
660
if err := pr .UpdateCols ("last_commit_id" ); err != nil {
@@ -668,15 +669,43 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
668
669
return fmt .Errorf ("IssueList.LoadRepositories: %v" , err )
669
670
}
670
671
672
+ var commitIDCache = make (map [string ]string )
673
+ var ok bool
671
674
for _ , issue := range issues {
675
+ var commitID string
672
676
if isForcePush {
673
677
if err := ClearPullPushComment (issue ); err != nil {
674
678
return fmt .Errorf ("ClearPullPushComent: %v" , err )
675
679
}
680
+
681
+ var key = fmt .Sprintf ("%s/%s" , issue .Repo .RepoPath (), issue .PullRequest .BaseBranch )
682
+ if commitID , ok = commitIDCache [key ]; ! ok {
683
+ gitRepo , err := git .OpenRepository (issue .Repo .RepoPath ())
684
+ if err != nil {
685
+ return fmt .Errorf ("OpenRepository: %v" , err )
686
+ }
687
+ commit , err := gitRepo .GetBranchCommit (issue .PullRequest .BaseBranch )
688
+ if err != nil {
689
+ return fmt .Errorf ("GetBranchCommit: %v" , err )
690
+ }
691
+ commitID = commit .ID .String ()
692
+ commitIDCache [key ] = commitID
693
+ }
676
694
}
677
695
678
- for i := len (opts .Commits .Commits ) - 1 ; i >= 0 ; i -- {
679
- if err := CreatePullPushComment (pusher , issue .Repo , issue , opts .Commits .Commits [i ]); err != nil {
696
+ var findStart = false
697
+ for i := len (commentCommits ) - 1 ; i >= 0 ; i -- {
698
+ if isForcePush {
699
+ if commitID == commentCommits [i ].Sha1 {
700
+ findStart = true
701
+ continue
702
+ }
703
+ if ! findStart {
704
+ continue
705
+ }
706
+ }
707
+
708
+ if err := CreatePullPushComment (pusher , issue .Repo , issue , commentCommits [i ]); err != nil {
680
709
return fmt .Errorf ("CreatePullPushComment: %v" , err )
681
710
}
682
711
}
0 commit comments