__init__.py
86 lines
| 3.2 KiB
| text/x-python
|
PythonLexer
|
r6239 | # __init__.py - inotify-based status acceleration for Linux | ||
# | ||||
# Copyright 2006, 2007, 2008 Bryan O'Sullivan <bos@serpentine.com> | ||||
# Copyright 2007, 2008 Brendan Cully <brendan@kublai.com> | ||||
# | ||||
|
r8225 | # This software may be used and distributed according to the terms of the | ||
|
r10263 | # GNU General Public License version 2 or any later version. | ||
|
r6239 | |||
|
r8932 | '''accelerate status report using Linux's inotify service''' | ||
|
r6239 | |||
# todo: socket permissions | ||||
|
r7225 | from mercurial.i18n import _ | ||
|
r8656 | import server | ||
|
r8552 | from client import client, QueryFailed | ||
|
r6239 | |||
def serve(ui, repo, **opts): | ||||
'''start an inotify server for this repository''' | ||||
|
r9514 | server.start(ui, repo.dirstate, repo.root, opts) | ||
|
r6239 | |||
|
r8555 | 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) | ||||
|
r6239 | def reposetup(ui, repo): | ||
|
r7522 | if not hasattr(repo, 'dirstate'): | ||
|
r6239 | return | ||
class inotifydirstate(repo.dirstate.__class__): | ||||
|
r8556 | # We'll set this to false after an unsuccessful attempt so that | ||
# next calls of status() within the same instance don't try again | ||||
# to start an inotify server if it won't start. | ||||
_inotifyon = True | ||||
|
r10605 | def status(self, match, subrepos, ignored, clean, unknown): | ||
|
r6603 | files = match.files() | ||
|
r7393 | if '.' in files: | ||
|
r7434 | files = [] | ||
|
r10176 | if self._inotifyon and not ignored and not subrepos and not self._dirty: | ||
|
r8552 | cli = client(ui, repo) | ||
try: | ||||
|
r8551 | result = cli.statusquery(files, match, False, | ||
|
r8552 | clean, unknown) | ||
except QueryFailed, instr: | ||||
ui.debug(str(instr)) | ||||
|
r8556 | # don't retry within the same hg instance | ||
inotifydirstate._inotifyon = False | ||||
|
r8552 | pass | ||
else: | ||||
if ui.config('inotify', 'debug'): | ||||
|
r7219 | r2 = super(inotifydirstate, self).status( | ||
|
r10493 | match, [], False, clean, unknown) | ||
|
r10282 | for c, a, b in zip('LMARDUIC', result, r2): | ||
|
r7219 | for f in a: | ||
if f not in b: | ||||
ui.warn('*** inotify: %s +%s\n' % (c, f)) | ||||
for f in b: | ||||
if f not in a: | ||||
|
r7304 | ui.warn('*** inotify: %s -%s\n' % (c, f)) | ||
|
r7219 | result = r2 | ||
|
r8552 | return result | ||
|
r6239 | return super(inotifydirstate, self).status( | ||
|
r10176 | match, subrepos, ignored, clean, unknown) | ||
|
r6239 | |||
repo.dirstate.__class__ = inotifydirstate | ||||
cmdtable = { | ||||
|
r8555 | 'debuginotify': | ||
(debuginotify, [], ('hg debuginotify')), | ||||
|
r6239 | '^inserve': | ||
|
r8555 | (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'))], | ||||
|
r8947 | _('hg inserve [OPTION]...')), | ||
|
r6239 | } | ||