@@ -74,14 +74,24 @@ func cmdDiff(args []string) {
7474 os .Exit (1 )
7575 }
7676
77+ // Run detection and git log concurrently.
78+ var commits []string
79+ done := make (chan struct {})
80+ go func () {
81+ commits = gitCommitLog (root , ref1 , ref2 )
82+ close (done )
83+ }()
84+
7785 engine := detect .New (knowledgeBase , root )
7886 r , err := engine .Run ()
7987 if err != nil {
8088 _ , _ = fmt .Fprintf (os .Stderr , "error: %v\n " , err )
8189 os .Exit (1 )
8290 }
8391
92+ <- done
8493 r .DiffRef = diffRef
94+ r .DiffCommits = commits
8595 r .ChangedFiles = changedFiles
8696
8797 r = detect .FilterByChangedFiles (r , knowledgeBase , changedFiles )
@@ -142,7 +152,7 @@ func gitChangedFiles(ctx context.Context, root, ref1, ref2 string, includeUncomm
142152 var files []string
143153
144154 addFiles := func (output string ) {
145- for _ , f := range strings .Split (strings .TrimSpace (output ), "\n " ) {
155+ for f := range strings .SplitSeq (strings .TrimSpace (output ), "\n " ) {
146156 f = strings .TrimSpace (f )
147157 if f != "" && ! seen [f ] {
148158 seen [f ] = true
@@ -216,3 +226,28 @@ func gitChangedFiles(ctx context.Context, root, ref1, ref2 string, includeUncomm
216226
217227 return files , nil
218228}
229+
230+ // gitCommitLog returns oneline commit summaries between two refs.
231+ func gitCommitLog (root , ref1 , ref2 string ) []string {
232+ var args []string
233+ if ref2 != "" {
234+ args = []string {"log" , "--oneline" , ref1 + ".." + ref2 }
235+ } else {
236+ args = []string {"log" , "--oneline" , ref1 + "..HEAD" }
237+ }
238+
239+ cmd := exec .Command ("git" , args ... )
240+ cmd .Dir = root
241+ out , err := cmd .Output ()
242+ if err != nil {
243+ return nil
244+ }
245+
246+ var commits []string
247+ for line := range strings .SplitSeq (strings .TrimSpace (string (out )), "\n " ) {
248+ if line != "" {
249+ commits = append (commits , line )
250+ }
251+ }
252+ return commits
253+ }
0 commit comments