diff --git a/hgext/inotify/__init__.py b/hgext/inotify/__init__.py --- a/hgext/inotify/__init__.py +++ b/hgext/inotify/__init__.py @@ -39,6 +39,18 @@ def serve(ui, repo, **opts): service = service() cmdutil.service(opts, initfn=service.init, runfn=service.run) +def debuginotify(ui, repo, **opts): + '''debugging information for inotify extension + + Prints the list of directories being watched by the inotify server. + ''' + cli = client(ui, repo) + response = cli.debugquery() + + ui.write(_('directories being watched:\n')) + for path in response: + ui.write((' %s/\n') % path) + def reposetup(ui, repo): if not hasattr(repo, 'dirstate'): return @@ -82,11 +94,13 @@ def reposetup(ui, repo): repo.dirstate.__class__ = inotifydirstate cmdtable = { + 'debuginotify': + (debuginotify, [], ('hg debuginotify')), '^inserve': - (serve, - [('d', 'daemon', None, _('run server in background')), - ('', 'daemon-pipefds', '', _('used internally by daemon mode')), - ('t', 'idle-timeout', '', _('minutes to sit idle before exiting')), - ('', 'pid-file', '', _('name of file to write process ID to'))], - _('hg inserve [OPT]...')), + (serve, + [('d', 'daemon', None, _('run server in background')), + ('', 'daemon-pipefds', '', _('used internally by daemon mode')), + ('t', 'idle-timeout', '', _('minutes to sit idle before exiting')), + ('', 'pid-file', '', _('name of file to write process ID to'))], + _('hg inserve [OPT]...')), } diff --git a/hgext/inotify/client.py b/hgext/inotify/client.py --- a/hgext/inotify/client.py +++ b/hgext/inotify/client.py @@ -142,5 +142,12 @@ class client(object): if names: return filter(match, names.split('\0')) return [] + return map(readnames, resphdr) - return map(readnames, resphdr) + @start_server + def debugquery(self): + cs, resphdr = self.query('DBUG', '') + + nbytes = resphdr[0] + names = cs.read(nbytes) + return names.split('\0') diff --git a/hgext/inotify/common.py b/hgext/inotify/common.py --- a/hgext/inotify/common.py +++ b/hgext/inotify/common.py @@ -18,6 +18,7 @@ import cStringIO, socket, struct - For STAT, N+1 \0-separated strings: 1) N different names that need checking 2) 1 string containing all the status types to match + - No parameter needed for DBUG Server sending query answer: 1) send protocol version number @@ -31,7 +32,8 @@ import cStringIO, socket, struct version = 2 resphdrfmts = { - 'STAT': '>llllllll' # status requests + 'STAT': '>llllllll', # status requests + 'DBUG': '>l' # debugging queries } resphdrsizes = dict((k, struct.calcsize(v)) for k, v in resphdrfmts.iteritems()) diff --git a/hgext/inotify/server.py b/hgext/inotify/server.py --- a/hgext/inotify/server.py +++ b/hgext/inotify/server.py @@ -542,6 +542,13 @@ class repowatcher(object): def shutdown(self): self.watcher.close() + def debug(self): + """ + Returns a sorted list of relatives paths currently watched, + for debugging purposes. + """ + return sorted(tuple[0][len(self.wprefix):] for tuple in self.watcher) + class server(object): poll_events = select.POLLIN @@ -624,6 +631,9 @@ class server(object): 'c' in states and genresult('n', self.repowatcher.tree) or [], ]] + def answer_dbug_query(self): + return ['\0'.join(self.repowatcher.debug())] + def handle_event(self, fd, event): sock, addr = self.sock.accept() @@ -639,6 +649,8 @@ class server(object): if type == 'STAT': results = self.answer_stat_query(cs) + elif type == 'DBUG': + results = self.answer_dbug_query() else: self.ui.warn(_('unrecognized query type: %s\n') % type) return diff --git a/tests/test-inotify-debuginotify b/tests/test-inotify-debuginotify new file mode 100755 --- /dev/null +++ b/tests/test-inotify-debuginotify @@ -0,0 +1,32 @@ +#!/bin/sh + +"$TESTDIR/hghave" inotify || exit 80 + +hg init + +echo "[extensions]" >> $HGRCPATH +echo "inotify=" >> $HGRCPATH + +echo % inserve +hg inserve -d --pid-file=hg.pid +cat hg.pid >> "$DAEMON_PIDS" + +# let the daemon finish its stuff +sleep 1 + +echo % empty +hg debuginotify + +mkdir a +sleep 1 + +echo % only 'a' +hg debuginotify + +rmdir a +sleep 1 + +echo % empty again +hg debuginotify + +kill `cat hg.pid` diff --git a/tests/test-inotify-debuginotify.out b/tests/test-inotify-debuginotify.out new file mode 100644 --- /dev/null +++ b/tests/test-inotify-debuginotify.out @@ -0,0 +1,14 @@ +% inserve +% empty +directories being watched: + / + .hg/ +% only a +directories being watched: + / + .hg/ + a/ +% empty again +directories being watched: + / + .hg/