From c7d367a791bf305b88dabf5a345f4f5e915ff2ed Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Wed, 8 Jan 2020 21:48:40 +1100 Subject: minor fixup --- pkg/gui/file_watching.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'pkg') diff --git a/pkg/gui/file_watching.go b/pkg/gui/file_watching.go index 9a7c8a9b2..b7ac080f6 100644 --- a/pkg/gui/file_watching.go +++ b/pkg/gui/file_watching.go @@ -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" @@ -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 @@ -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() { -- cgit v1.2.3