summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-01-08 21:48:40 +1100
committerJesse Duffield <jessedduffield@gmail.com>2020-01-08 21:55:52 +1100
commitc7d367a791bf305b88dabf5a345f4f5e915ff2ed (patch)
tree89f36a70da9b213c5c969249f90d38873e7622e1
parentba4253668de57e723c2692683cec6a0c889b3649 (diff)
minor fixup
-rw-r--r--pkg/gui/file_watching.go15
1 files changed, 12 insertions, 3 deletions
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() {