SearchDir searches a directory for comments
(dirPath string, cb func(comment *Comment))
| 66 | |
| 67 | // SearchDir searches a directory for comments |
| 68 | func SearchDir(dirPath string, cb func(comment *Comment)) error { |
| 69 | err := godirwalk.Walk(dirPath, &godirwalk.Options{ |
| 70 | Callback: func(path string, de *godirwalk.Dirent) error { |
| 71 | localPath, err := filepath.Rel(dirPath, path) |
| 72 | if err != nil { |
| 73 | return err |
| 74 | } |
| 75 | pathComponents := strings.Split(localPath, string(os.PathSeparator)) |
| 76 | // let's ignore git directories TODO: figure out a more generic way to set ignores |
| 77 | matched, err := filepath.Match(".git", pathComponents[0]) |
| 78 | if err != nil { |
| 79 | return err |
| 80 | } |
| 81 | if matched { |
| 82 | return nil |
| 83 | } |
| 84 | if de.IsRegular() { |
| 85 | p, err := filepath.Abs(path) |
| 86 | if err != nil { |
| 87 | return err |
| 88 | } |
| 89 | f, err := os.Open(p) |
| 90 | if err != nil { |
| 91 | return err |
| 92 | } |
| 93 | err = SearchFile(localPath, f, cb) |
| 94 | if err != nil { |
| 95 | return err |
| 96 | } |
| 97 | f.Close() |
| 98 | } |
| 99 | return nil |
| 100 | }, |
| 101 | Unsorted: true, |
| 102 | }) |
| 103 | if err != nil { |
| 104 | return err |
| 105 | } |
| 106 | return nil |
| 107 | } |
| 108 | |
| 109 | // SearchCommit searches all files in the tree of a given commit |
| 110 | func SearchCommit(commit *object.Commit, cb func(*Comment)) error { |