Mercurial > hg
annotate hgext/inotify/__init__.py @ 7217:9fa2f8dcb869
inotify: friendlier message when daemon not running
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 22 Oct 2008 17:41:41 -0500 |
parents | 9dcce703edb8 |
children | 1bd7f90465b3 |
rev | line source |
---|---|
6239 | 1 # __init__.py - inotify-based status acceleration for Linux |
2 # | |
3 # Copyright 2006, 2007, 2008 Bryan O'Sullivan <bos@serpentine.com> | |
4 # Copyright 2007, 2008 Brendan Cully <brendan@kublai.com> | |
5 # | |
6 # This software may be used and distributed according to the terms | |
7 # of the GNU General Public License, incorporated herein by reference. | |
8 | |
9 '''inotify-based status acceleration for Linux systems | |
10 ''' | |
11 | |
12 # todo: socket permissions | |
13 | |
14 from mercurial.i18n import gettext as _ | |
15 from mercurial import cmdutil, util | |
16 import client, errno, os, server, socket | |
17 from weakref import proxy | |
18 | |
19 def serve(ui, repo, **opts): | |
20 '''start an inotify server for this repository''' | |
21 timeout = opts.get('timeout') | |
22 if timeout: | |
23 timeout = float(timeout) * 1e3 | |
24 | |
25 class service: | |
26 def init(self): | |
6995
25619b72f86a
inotify: fix traceback when the server has been already started
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6239
diff
changeset
|
27 try: |
25619b72f86a
inotify: fix traceback when the server has been already started
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6239
diff
changeset
|
28 self.master = server.Master(ui, repo, timeout) |
25619b72f86a
inotify: fix traceback when the server has been already started
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6239
diff
changeset
|
29 except server.AlreadyStartedException, inst: |
25619b72f86a
inotify: fix traceback when the server has been already started
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6239
diff
changeset
|
30 raise util.Abort(str(inst)) |
6239 | 31 |
32 def run(self): | |
33 try: | |
34 self.master.run() | |
35 finally: | |
36 self.master.shutdown() | |
37 | |
38 service = service() | |
39 cmdutil.service(opts, initfn=service.init, runfn=service.run) | |
40 | |
41 def reposetup(ui, repo): | |
42 if not repo.local(): | |
43 return | |
44 | |
45 # XXX: weakref until hg stops relying on __del__ | |
46 repo = proxy(repo) | |
47 | |
48 class inotifydirstate(repo.dirstate.__class__): | |
49 # Set to True if we're the inotify server, so we don't attempt | |
50 # to recurse. | |
51 inotifyserver = False | |
52 | |
6753
ed5ffb2c12f3
repo.status: eliminate list_
Matt Mackall <mpm@selenic.com>
parents:
6603
diff
changeset
|
53 def status(self, match, ignored, clean, unknown=True): |
6603
41eb20cc1c02
match: remove files arg from repo.status and friends
Matt Mackall <mpm@selenic.com>
parents:
6239
diff
changeset
|
54 files = match.files() |
6239 | 55 try: |
6753
ed5ffb2c12f3
repo.status: eliminate list_
Matt Mackall <mpm@selenic.com>
parents:
6603
diff
changeset
|
56 if not ignored and not self.inotifyserver: |
6239 | 57 result = client.query(ui, repo, files, match, False, |
6753
ed5ffb2c12f3
repo.status: eliminate list_
Matt Mackall <mpm@selenic.com>
parents:
6603
diff
changeset
|
58 clean, unknown) |
6239 | 59 if result is not None: |
60 return result | |
6997
9c4e488f105e
inotify: workaround ENAMETOOLONG by using symlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6996
diff
changeset
|
61 except (OSError, socket.error), err: |
6239 | 62 if err[0] == errno.ECONNREFUSED: |
63 ui.warn(_('(found dead inotify server socket; ' | |
64 'removing it)\n')) | |
65 os.unlink(repo.join('inotify.sock')) | |
6996
fecf060f32a1
inotify: deactivate inotify status on failure
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6995
diff
changeset
|
66 if err[0] in (errno.ECONNREFUSED, errno.ENOENT) and \ |
fecf060f32a1
inotify: deactivate inotify status on failure
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6995
diff
changeset
|
67 ui.configbool('inotify', 'autostart'): |
6239 | 68 query = None |
69 ui.debug(_('(starting inotify server)\n')) | |
70 try: | |
71 server.start(ui, repo) | |
72 query = client.query | |
73 except server.AlreadyStartedException, inst: | |
74 # another process may have started its own | |
75 # inotify server while this one was starting. | |
76 ui.debug(str(inst)) | |
77 query = client.query | |
78 except Exception, inst: | |
79 ui.warn(_('could not start inotify server: ' | |
80 '%s\n') % inst) | |
81 if query: | |
82 try: | |
83 return query(ui, repo, files or [], match, | |
6753
ed5ffb2c12f3
repo.status: eliminate list_
Matt Mackall <mpm@selenic.com>
parents:
6603
diff
changeset
|
84 ignored, clean, unknown) |
6239 | 85 except socket.error, err: |
86 ui.warn(_('could not talk to new inotify ' | |
6996
fecf060f32a1
inotify: deactivate inotify status on failure
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6995
diff
changeset
|
87 'server: %s\n') % err[-1]) |
7217
9fa2f8dcb869
inotify: friendlier message when daemon not running
Matt Mackall <mpm@selenic.com>
parents:
7083
diff
changeset
|
88 elif err[0] == errno.ENOENT: |
9fa2f8dcb869
inotify: friendlier message when daemon not running
Matt Mackall <mpm@selenic.com>
parents:
7083
diff
changeset
|
89 ui.warn(_('(inotify server not running)\n')) |
6996
fecf060f32a1
inotify: deactivate inotify status on failure
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6995
diff
changeset
|
90 else: |
fecf060f32a1
inotify: deactivate inotify status on failure
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6995
diff
changeset
|
91 ui.warn(_('failed to contact inotify server: %s\n') |
fecf060f32a1
inotify: deactivate inotify status on failure
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6995
diff
changeset
|
92 % err[-1]) |
fecf060f32a1
inotify: deactivate inotify status on failure
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6995
diff
changeset
|
93 ui.print_exc() |
fecf060f32a1
inotify: deactivate inotify status on failure
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6995
diff
changeset
|
94 # replace by old status function |
fecf060f32a1
inotify: deactivate inotify status on failure
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6995
diff
changeset
|
95 self.status = super(inotifydirstate, self).status |
6239 | 96 |
97 return super(inotifydirstate, self).status( | |
6753
ed5ffb2c12f3
repo.status: eliminate list_
Matt Mackall <mpm@selenic.com>
parents:
6603
diff
changeset
|
98 match, ignored, clean, unknown) |
6239 | 99 |
100 repo.dirstate.__class__ = inotifydirstate | |
101 | |
102 cmdtable = { | |
103 '^inserve': | |
104 (serve, | |
105 [('d', 'daemon', None, _('run server in background')), | |
106 ('', 'daemon-pipefds', '', _('used internally by daemon mode')), | |
107 ('t', 'idle-timeout', '', _('minutes to sit idle before exiting')), | |
108 ('', 'pid-file', '', _('name of file to write process ID to'))], | |
109 _('hg inserve [OPT]...')), | |
110 } |