Skip to content

Commit 3310b08

Browse files
Merge pull request #14 from augmentable-dev/concurrent-comment-search
Concurrent comment search
2 parents 53b22aa + ad6490d commit 3310b08

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

cmd/commands/todos.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/augmentable-dev/tickgit/pkg/comments"
88
"github.com/augmentable-dev/tickgit/pkg/todos"
99
"github.com/spf13/cobra"
10+
"gopkg.in/src-d/go-git.v4"
1011
)
1112

1213
func init() {
@@ -28,9 +29,21 @@ var todosCmd = &cobra.Command{
2829
handleError(err)
2930
}
3031

31-
comments, err := comments.SearchDir(dir)
32+
r, err := git.PlainOpen(dir)
3233
handleError(err)
3334

35+
ref, err := r.Head()
36+
handleError(err)
37+
38+
commit, err := r.CommitObject(ref.Hash())
39+
handleError(err)
40+
41+
comments, err := comments.SearchCommit(commit)
42+
handleError(err)
43+
44+
// comments, err := comments.SearchDir(dir)
45+
// handleError(err)
46+
3447
t := todos.NewToDos(comments)
3548
todos.WriteTodos(t, os.Stdout)
3649
},

pkg/comments/comments.go

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"path/filepath"
99
"strings"
10+
"sync"
1011

1112
"github.com/augmentable-dev/lege"
1213
"github.com/src-d/enry/v2"
@@ -139,25 +140,41 @@ func SearchDir(dirPath string) (Comments, error) {
139140

140141
// SearchCommit searches all files in the tree of a given commit
141142
func SearchCommit(commit *object.Commit) (Comments, error) {
142-
c := make(Comments, 0)
143+
found := make(Comments, 0)
143144
t, err := commit.Tree()
144145
if err != nil {
145146
return nil, err
146147
}
148+
149+
var wg sync.WaitGroup
150+
errs := make(chan error)
151+
147152
fileIter := t.Files()
148153
fileIter.ForEach(func(file *object.File) error {
149154
if file.Mode.IsFile() {
150-
r, err := file.Reader()
151-
if err != nil {
152-
return err
153-
}
154-
found, err := SearchFile(file.Name, r)
155-
if err != nil {
156-
return err
157-
}
158-
c = append(c, found...)
155+
wg.Add(1)
156+
go func() {
157+
defer wg.Done()
158+
159+
r, err := file.Reader()
160+
if err != nil {
161+
errs <- err
162+
return
163+
}
164+
c, err := SearchFile(file.Name, r)
165+
if err != nil {
166+
errs <- err
167+
return
168+
}
169+
170+
for _, comment := range c {
171+
found = append(found, comment)
172+
}
173+
}()
159174
}
160175
return nil
161176
})
162-
return c, nil
177+
178+
wg.Wait()
179+
return found, nil
163180
}

0 commit comments

Comments
 (0)