Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@altsem
Copy link
Owner

@altsem altsem commented Oct 11, 2025

@jonathanj put this back in a thread, I can't see how it wouldn't work on Mac. 🤔
This time around the watcher doesn't move around threads.

previously reverted in: #360
related: #358, #374

@altsem altsem force-pushed the feat/start-watcher-async branch from e84d8f0 to f23e15c Compare October 11, 2025 12:49
@altsem altsem force-pushed the feat/start-watcher-async branch from f23e15c to cf21bd1 Compare October 11, 2025 12:49
@jonathanj
Copy link
Contributor

The thing I noticed last time, and maybe the improved gitignore stuff I added helps, was that starting it in an async thread caused a surge of file change events in the initial check, for whatever reason.

I'm happy to build this branch on macOS and check that the FS change events work.

@jonathanj
Copy link
Contributor

Seems to be fine to me. Was starting this on the main thread the cause of a startup delay?

@jonathanj
Copy link
Contributor

Here's my gitu.log for this session:

gitu.log
[00:00:00.000] (2018c60c0) DEBUG  Initializing terminal backend
[00:00:00.003] (2018c60c0) DEBUG  Starting app
[00:00:00.003] (2018c60c0) DEBUG  Finding git dir
[00:00:00.040] (2018c60c0) DEBUG  Opening repo
[00:00:00.042] (2018c60c0) INFO   Loading config file at "/Users/jonathan/.config/gitu/config.toml"
[00:00:00.066] (2018c60c0) WARN   Couldn't read /Users/jonathan/Coding/gitu/.git/rebase-merge/onto, due to No such file or directory (os error 2)
[00:00:00.066] (2018c60c0) WARN   Couldn't read /Users/jonathan/Coding/gitu/.git/MERGE_HEAD, due to No such file or directory (os error 2)
[00:00:00.066] (2018c60c0) WARN   Couldn't read /Users/jonathan/Coding/gitu/.git/REVERT_HEAD, due to No such file or directory (os error 2)
[00:00:00.114] (16b897000) DEBUG  Opening repo
[00:00:00.118] (16b897000) INFO   File watcher started (kind: Fsevent)
[00:05:31.051] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/4913" (Create(File))
[00:05:31.052] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/4913" (Remove(File))
[00:05:31.052] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/4913" (Modify(Metadata(Ownership)))
[00:05:31.053] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/4913" (Modify(Metadata(Extended)))
[00:05:31.053] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/codecov.yml" (Modify(Name(Any)))
[00:05:31.053] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/codecov.yml" (Create(File))
[00:05:31.053] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/codecov.yml" (Modify(Metadata(Ownership)))
[00:05:31.053] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/codecov.yml" (Modify(Metadata(Extended)))
[00:05:31.054] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/codecov.yml" (Modify(Data(Content)))
[00:05:31.054] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/codecov.yml~" (Remove(File))
[00:05:31.054] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/codecov.yml~" (Modify(Name(Any)))
[00:05:31.167] (2018c60c0) WARN   Couldn't read /Users/jonathan/Coding/gitu/.git/rebase-merge/onto, due to No such file or directory (os error 2)
[00:05:31.167] (2018c60c0) WARN   Couldn't read /Users/jonathan/Coding/gitu/.git/MERGE_HEAD, due to No such file or directory (os error 2)
[00:05:31.167] (2018c60c0) WARN   Couldn't read /Users/jonathan/Coding/gitu/.git/REVERT_HEAD, due to No such file or directory (os error 2)
[00:05:37.724] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/4913" (Create(File))
[00:05:37.728] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/4913" (Remove(File))
[00:05:37.729] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/4913" (Modify(Metadata(Ownership)))
[00:05:37.729] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/4913" (Modify(Metadata(Extended)))
[00:05:37.730] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/codecov.yml" (Create(File))
[00:05:37.730] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/codecov.yml" (Modify(Name(Any)))
[00:05:37.730] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/codecov.yml" (Modify(Metadata(Ownership)))
[00:05:37.731] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/codecov.yml" (Modify(Metadata(Extended)))
[00:05:37.731] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/codecov.yml" (Modify(Data(Content)))
[00:05:37.731] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/codecov.yml" (Create(File))
[00:05:37.731] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/codecov.yml" (Modify(Metadata(Ownership)))
[00:05:37.731] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/codecov.yml" (Modify(Metadata(Extended)))
[00:05:37.731] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/codecov.yml" (Modify(Data(Content)))
[00:05:37.731] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/codecov.yml~" (Remove(File))
[00:05:37.732] (16baa3000) INFO   File changed: "/Users/jonathan/Coding/gitu/codecov.yml~" (Modify(Name(Any)))
[00:05:37.792] (2018c60c0) WARN   Couldn't read /Users/jonathan/Coding/gitu/.git/rebase-merge/onto, due to No such file or directory (os error 2)
[00:05:37.793] (2018c60c0) WARN   Couldn't read /Users/jonathan/Coding/gitu/.git/MERGE_HEAD, due to No such file or directory (os error 2)
[00:05:37.793] (2018c60c0) WARN   Couldn't read /Users/jonathan/Coding/gitu/.git/REVERT_HEAD, due to No such file or directory (os error 2)

There are a couple of interesting things:

  • Changes to whatever gitu/4913 is, that's not the file I modified. I don't think this is my editor, this file is immediately deleted but gitu incurs the cost of processing it
  • Errors reading .git/… which happens before I even make any changes, which is a bit curious: I'm not sure how the cost of this might vary from system to system, or how many of these could be for a large and old checkout, maybe it's nothing but it seems a bit odd regardless.
  • Events for metadata: Every one of these events potentially incurs some amount of processing for gitu, which may produce no visible UI changes in any way

Maybe none of these are interesting to #374 but I can't really tell since I don't have a repo/system that has these issues, unfortunately.

@altsem
Copy link
Owner Author

altsem commented Oct 11, 2025

Nice! It seem like it is a pretty significant amount in larger repos. I found this in the man-page:

       Inotify monitoring of directories is not recursive: to monitor
       subdirectories under a directory, additional watches must be
       created.  This can take a significant amount time for large
       directory trees.

The filtering done: repo.status_should_ignore(&path) is after already having registered watches on every single file.
Feels like not watching everything could be a win as well.

@jonathanj
Copy link
Contributor

The filtering done: repo.status_should_ignore(&path) is after already having registered watches on every single file. Feels like not watching everything could be a win as well.

Do you have any idea of how to approach this? Browsing around the docs for notify I don't see a way to cause the watcher to not watch certain paths.

@jonathanj
Copy link
Contributor

Nice! It seem like it is a pretty significant amount in larger repos. I found this in the man-page:

I noticed you asked this same question on the other thread, but how does magit (or is it emacs?) manage not to run into the same issue?

@jonathanj
Copy link
Contributor

Also, in this comment the log shows FsEvents not INotify as the watcher kind, so is the inotify manpage still relevant in this case?

@altsem
Copy link
Owner Author

altsem commented Oct 11, 2025

True. But perhaps he tested it on a Mac as well.
FsEvents seems to be unique for Mac, the Linux impl relies on INotify. And INotify doesn't natively support watching recursively.

It'd be perfect if the notify crate supported filters on files, but it doesn't seem to.
I'll keep digging.

@altsem
Copy link
Owner Author

altsem commented Oct 18, 2025

I'll merge this in and create a new issue:

  • File-watcher listening on gitignored files

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Refactors the file watcher to run in a separate thread to prevent blocking the main thread during initialization. The watcher is now started asynchronously and uses std::mem::forget to prevent it from being dropped.

  • Moved file watching logic into a separate watch function that runs in a spawned thread
  • Removed the _watcher field from the FileWatcher struct since the watcher now runs independently
  • Added error logging for file watcher failures in the background thread

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@altsem altsem merged commit 3b589c6 into master Oct 18, 2025
3 checks passed
@altsem altsem deleted the feat/start-watcher-async branch October 18, 2025 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants