Skip to content

Commit

Permalink
minor fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Jan 8, 2020
1 parent ba42536 commit c7d367a
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pkg/gui/file_watching.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"os"
"path/filepath"

"github.com/davecgh/go-spew/spew"
"github.com/fsnotify/fsnotify"
"github.com/jesseduffield/lazygit/pkg/commands"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -67,13 +66,17 @@ func (w *fileWatcher) watchFilename(filename string) {
}

func (w *fileWatcher) addFilesToFileWatcher(files []*commands.File) error {
if len(files) == 0 {
return nil
}

// watch the files for changes
dirName, err := os.Getwd()
if err != nil {
return err
}

for _, file := range files {
for _, file := range files[0:min(MAX_WATCHED_FILES, len(files))] {
filename := filepath.Join(dirName, file.Name)
if w.watchingFilename(filename) {
continue
Expand All @@ -83,12 +86,18 @@ func (w *fileWatcher) addFilesToFileWatcher(files []*commands.File) error {
}

w.watchFilename(filename)
w.Log.Warn(spew.Sdump(w.WatchedFilenames))
}

return nil
}

func min(a int, b int) int {
if a < b {
return a
}
return b
}

// NOTE: given that we often edit files ourselves, this may make us end up refreshing files too often
// TODO: consider watching the whole directory recursively (could be more expensive)
func (gui *Gui) watchFilesForChanges() {
Expand Down

0 comments on commit c7d367a

Please sign in to comment.