@@ -3,6 +3,7 @@ package todos
33import (
44 "regexp"
55 "strings"
6+ "sync"
67
78 "github.com/augmentable-dev/tickgit/pkg/comments"
89 "github.com/dustin/go-humanize"
@@ -67,11 +68,12 @@ func (t *ToDo) existsInCommit(commit *object.Commit) (bool, error) {
6768 if err != nil {
6869 return false , err
6970 }
70- return strings .Contains (c , t .Comment .String ()), nil
71+ contains := strings .Contains (c , t .Comment .String ())
72+ return contains , nil
7173}
7274
7375// FindBlame sets the blame information on each todo in a set of todos
74- func (t * ToDos ) FindBlame (repo * git.Repository , from * object.Commit ) error {
76+ func (t * ToDos ) FindBlame (repo * git.Repository , from * object.Commit , cb func ( * object. Commit , int ) ) error {
7577 commitIter , err := repo .Log (& git.LogOptions {
7678 From : from .Hash ,
7779 })
@@ -86,18 +88,32 @@ func (t *ToDos) FindBlame(repo *git.Repository, from *object.Commit) error {
8688 if len (remainingTodos ) == 0 {
8789 return storer .ErrStop
8890 }
91+ if commit .NumParents () > 1 {
92+ return nil
93+ }
8994 newRemainingTodos := make (ToDos , 0 )
95+ errs := make (chan error )
96+ var wg sync.WaitGroup
97+ var mux sync.Mutex
9098 for _ , todo := range remainingTodos {
91- exists , err := todo .existsInCommit (commit )
92- if err != nil {
93- return err
94- }
95- if ! exists { // if the todo doesn't exist in this commit, it was added in the previous commit (previous wrt the iterator, more recent in time)
96- todo .Commit = prevCommit
97- } else { // if the todo does exist in this commit, add it to the new list of remaining todos
98- newRemainingTodos = append (newRemainingTodos , todo )
99- }
99+ wg .Add (1 )
100+ go func (todo * ToDo , commit * object.Commit , errs chan error ) {
101+ defer wg .Done ()
102+ mux .Lock ()
103+ exists , err := todo .existsInCommit (commit )
104+ if err != nil {
105+ errs <- err
106+ }
107+ mux .Unlock ()
108+ if ! exists { // if the todo doesn't exist in this commit, it was added in the previous commit (previous wrt the iterator, more recent in time)
109+ todo .Commit = prevCommit
110+ } else { // if the todo does exist in this commit, add it to the new list of remaining todos
111+ newRemainingTodos = append (newRemainingTodos , todo )
112+ }
113+ }(todo , commit , errs )
100114 }
115+ wg .Wait ()
116+ cb (commit , len (newRemainingTodos ))
101117 prevCommit = commit
102118 remainingTodos = newRemainingTodos
103119 return nil
0 commit comments