# HG changeset patch # User Chris Cannam # Date 1328910567 0 # Node ID 3935a7e621ca2a1d011945569cc741fc8709776a # Parent bdc9de7948396f42632e0e2e9e79419ff6e6694c Add setTrackedFilePaths, and comments diff -r bdc9de794839 -r 3935a7e621ca src/fswatcher.cpp --- a/src/fswatcher.cpp Fri Feb 10 17:53:04 2012 +0000 +++ b/src/fswatcher.cpp Fri Feb 10 21:49:27 2012 +0000 @@ -22,6 +22,25 @@ #include +/* + * Watching the filesystem is trickier than it seems at first glance. + * + * We ideally should watch every directory, and every file that is + * tracked by Hg. If a new file is created in a directory, then we + * need to respond in order to show it as a potential candidate to be + * added. + * + * Complicating matters though is that Hg itself might modify the + * filesystem. This can happen even in "read-only" operations: for + * example, hg stat creates files called hg-checklink and hg-checkexec + * to test properties of the filesystem. So we need to know to ignore + * those files; unfortunately, when watching a directory (which is how + * we find out about the creation of new files) we are notified only + * that the directory has changed -- we aren't told what changed. So + * we need to rescan the directory merely to find out whether to + * ignore the change or not. + */ + FsWatcher::FsWatcher() : m_lastToken(0), m_lastCounter(0) @@ -47,6 +66,16 @@ } void +FsWatcher::setTrackedFilePaths(QStringList paths) +{ + QMutexLocker locker(&m_mutex); + m_watcher.removePaths(m_watcher.files()); + foreach (QString path, paths) { + m_watcher.addPath(path); + } +} + +void FsWatcher::addWorkDirectory(QString path) { // QFileSystemWatcher will refuse to add a file or directory to diff -r bdc9de794839 -r 3935a7e621ca src/fswatcher.h --- a/src/fswatcher.h Fri Feb 10 17:53:04 2012 +0000 +++ b/src/fswatcher.h Fri Feb 10 21:49:27 2012 +0000 @@ -36,11 +36,23 @@ virtual ~FsWatcher(); /** - * Set the root path of the work directory to be monitored. + * Set the root path of the work directory to be monitored. This + * directory and all its subdirectories (recursively) will be + * monitored for changes. + * + * Calling this also clears the tracked file path set. Call + * setTrackedFilePaths afterwards to ensure non-directory files + * are monitored. */ void setWorkDirPath(QString path); /** + * Provide a set of paths for files which should be tracked. These + * will be the only non-directory files monitored for changes. + */ + void setTrackedFilePaths(QStringList paths); + + /** * Provide a set of prefixes to ignore. Files whose names start * with a prefix in this set will be ignored when they change. */