1 # __init__.py - inotify-based status acceleration for Linux
3 # Copyright 2006, 2007, 2008 Bryan O'Sullivan <bos@serpentine.com>
4 # Copyright 2007, 2008 Brendan Cully <brendan@kublai.com>
6 # This software may be used and distributed according to the terms of the
7 # GNU General Public License version 2, incorporated herein by reference.
9 '''accelerate status report using Linux's inotify service'''
11 # todo: socket permissions
13 from mercurial.i18n import _
14 from mercurial import cmdutil, util
16 from weakref import proxy
17 from client import client, QueryFailed
19 def serve(ui, repo, **opts):
20 '''start an inotify server for this repository'''
21 timeout = opts.get('timeout')
23 timeout = float(timeout) * 1e3
25 class service(object):
28 self.master = server.master(ui, repo.dirstate,
30 except server.AlreadyStartedException, inst:
31 raise util.Abort(str(inst))
37 self.master.shutdown()
40 logfile = ui.config('inotify', 'log')
41 cmdutil.service(opts, initfn=service.init, runfn=service.run,
44 def debuginotify(ui, repo, **opts):
45 '''debugging information for inotify extension
47 Prints the list of directories being watched by the inotify server.
49 cli = client(ui, repo)
50 response = cli.debugquery()
52 ui.write(_('directories being watched:\n'))
54 ui.write((' %s/\n') % path)
56 def reposetup(ui, repo):
57 if not hasattr(repo, 'dirstate'):
60 class inotifydirstate(repo.dirstate.__class__):
62 # We'll set this to false after an unsuccessful attempt so that
63 # next calls of status() within the same instance don't try again
64 # to start an inotify server if it won't start.
67 def status(self, match, ignored, clean, unknown=True):
71 if self._inotifyon and not ignored:
72 cli = client(ui, repo)
74 result = cli.statusquery(files, match, False,
76 except QueryFailed, instr:
78 # don't retry within the same hg instance
79 inotifydirstate._inotifyon = False
82 if ui.config('inotify', 'debug'):
83 r2 = super(inotifydirstate, self).status(
84 match, False, clean, unknown)
85 for c,a,b in zip('LMARDUIC', result, r2):
88 ui.warn('*** inotify: %s +%s\n' % (c, f))
91 ui.warn('*** inotify: %s -%s\n' % (c, f))
94 return super(inotifydirstate, self).status(
95 match, ignored, clean, unknown)
97 repo.dirstate.__class__ = inotifydirstate
101 (debuginotify, [], ('hg debuginotify')),
104 [('d', 'daemon', None, _('run server in background')),
105 ('', 'daemon-pipefds', '', _('used internally by daemon mode')),
106 ('t', 'idle-timeout', '', _('minutes to sit idle before exiting')),
107 ('', 'pid-file', '', _('name of file to write process ID to'))],
108 _('hg inserve [OPTION]...')),