Class RepoWatcher
java.lang.Object
io.github.jbastgen.stemma.app.git.RepoWatcher
- All Implemented Interfaces:
AutoCloseable
Feature 53: tells when something changed in a repository, whoever changed it: files of the working tree, or Git's own state (
HEAD,
the index, the branches and tags, a merge or rebase in progress). Built on WatchService, so it is as good as the operating
system: inotify on Linux, the native service on Windows, and on macOS Java polls (every 2 seconds here, if the tree is small enough).
What is watched: every directory that Git does not ignore (the caller lists them; an ignored folder such as node_modules is
never entered), .git itself for the few files that matter, and .git/refs with its sub-directories. Changes are merged:
the callback comes once, DEBOUNCE_MILLIS after the last event. When the operating system cannot give as many watches as there
are directories, nothing is watched and the problem callback says why, once; the application then refreshes only when its window
is used again.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
RepoWatcher
public RepoWatcher(Path workTree, Supplier<List<String>> directories, Runnable changed, Consumer<String> problem) - Parameters:
directories- lists the directories to watch, relative to the work tree (""= the work tree itself); called off the JavaFX thread, at the start and after directories were createdchanged- called on a thread of its own, once per burst of changesproblem- called once, with a reason, if watching is not possible; the watcher is closed then
-
RepoWatcher
public RepoWatcher(Path workTree, Supplier<List<String>> directories, Runnable changed, Consumer<String> problem, int maxDirectories) - Parameters:
workTree- the work tree to watchdirectories- the folders to watch, relative to the work tree (""is the work tree itself)changed- called after a burst of changes, from the timer threadproblem- called once when watching has to be given up, with the reasonmaxDirectories- more folders than this are not watched
-
-
Method Details
-
start
public void start()Starts watching in the background; returns at once. -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-