changeset 539:3935a7e621ca fswatcher

Add setTrackedFilePaths, and comments
author Chris Cannam
date Fri, 10 Feb 2012 21:49:27 +0000
parents bdc9de794839
children fc2df97920e8
files src/fswatcher.cpp src/fswatcher.h
diffstat 2 files changed, 42 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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 <deque>
 
+/*
+ * 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
--- 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.
      */