Mercurial > hg
annotate hgext/inotify/__init__.py @ 7772:88887054d277
fancyopts: Parse options that occur after arguments.
This changes the behavior of qguard in the case of setting negative guards, as -- will now always be required.
Fixes issue1402.
Doc fixes for mq by mpm.
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Tue, 10 Feb 2009 13:26:00 -0600 |
parents | 2f4a399a8787 |
children | b084d6d6f345 |
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 | |
7225
59b4ae211584
i18n: import _ instead of gettext
Martin Geisler <mg@daimi.au.dk>
parents:
7219
diff
changeset
|
14 from mercurial.i18n import _ |
6239 | 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): | |
7522
2f4a399a8787
inotify: do not attempt to monkeypatch bundlerepos
Brendan Cully <brendan@kublai.com>
parents:
7452
diff
changeset
|
42 if not hasattr(repo, 'dirstate'): |
6239 | 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() |
7393
92c952c4470c
inotify: fix status . in repo.root
Brendan Cully <brendan@kublai.com>
parents:
7329
diff
changeset
|
55 if '.' in files: |
7434
cf7741aa1e96
kill some trailing spaces
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7393
diff
changeset
|
56 files = [] |
6239 | 57 try: |
6753
ed5ffb2c12f3
repo.status: eliminate list_
Matt Mackall <mpm@selenic.com>
parents:
6603
diff
changeset
|
58 if not ignored and not self.inotifyserver: |
6239 | 59 result = client.query(ui, repo, files, match, False, |
6753
ed5ffb2c12f3
repo.status: eliminate list_
Matt Mackall <mpm@selenic.com>
parents:
6603
diff
changeset
|
60 clean, unknown) |
7219
1f6d2e487135
inotify: add debugging mode to inotify
Matt Mackall <mpm@selenic.com>
parents:
7218
diff
changeset
|
61 if ui.config('inotify', 'debug'): |
1f6d2e487135
inotify: add debugging mode to inotify
Matt Mackall <mpm@selenic.com>
parents:
7218
diff
changeset
|
62 r2 = super(inotifydirstate, self).status( |
1f6d2e487135
inotify: add debugging mode to inotify
Matt Mackall <mpm@selenic.com>
parents:
7218
diff
changeset
|
63 match, False, clean, unknown) |
1f6d2e487135
inotify: add debugging mode to inotify
Matt Mackall <mpm@selenic.com>
parents:
7218
diff
changeset
|
64 for c,a,b in zip('LMARDUIC', result, r2): |
1f6d2e487135
inotify: add debugging mode to inotify
Matt Mackall <mpm@selenic.com>
parents:
7218
diff
changeset
|
65 for f in a: |
1f6d2e487135
inotify: add debugging mode to inotify
Matt Mackall <mpm@selenic.com>
parents:
7218
diff
changeset
|
66 if f not in b: |
1f6d2e487135
inotify: add debugging mode to inotify
Matt Mackall <mpm@selenic.com>
parents:
7218
diff
changeset
|
67 ui.warn('*** inotify: %s +%s\n' % (c, f)) |
1f6d2e487135
inotify: add debugging mode to inotify
Matt Mackall <mpm@selenic.com>
parents:
7218
diff
changeset
|
68 for f in b: |
1f6d2e487135
inotify: add debugging mode to inotify
Matt Mackall <mpm@selenic.com>
parents:
7218
diff
changeset
|
69 if f not in a: |
7304
68374f1c8c87
inotify: fix bug in formatting
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7225
diff
changeset
|
70 ui.warn('*** inotify: %s -%s\n' % (c, f)) |
7219
1f6d2e487135
inotify: add debugging mode to inotify
Matt Mackall <mpm@selenic.com>
parents:
7218
diff
changeset
|
71 result = r2 |
1f6d2e487135
inotify: add debugging mode to inotify
Matt Mackall <mpm@selenic.com>
parents:
7218
diff
changeset
|
72 |
6239 | 73 if result is not None: |
74 return result | |
6997
9c4e488f105e
inotify: workaround ENAMETOOLONG by using symlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6996
diff
changeset
|
75 except (OSError, socket.error), err: |
7452
89c516430107
inotify: do not complain that inotify is not running if autostart is False
Brendan Cully <brendan@kublai.com>
parents:
7434
diff
changeset
|
76 autostart = ui.configbool('inotify', 'autostart', True) |
89c516430107
inotify: do not complain that inotify is not running if autostart is False
Brendan Cully <brendan@kublai.com>
parents:
7434
diff
changeset
|
77 |
6239 | 78 if err[0] == errno.ECONNREFUSED: |
79 ui.warn(_('(found dead inotify server socket; ' | |
80 'removing it)\n')) | |
81 os.unlink(repo.join('inotify.sock')) | |
7452
89c516430107
inotify: do not complain that inotify is not running if autostart is False
Brendan Cully <brendan@kublai.com>
parents:
7434
diff
changeset
|
82 if err[0] in (errno.ECONNREFUSED, errno.ENOENT) and autostart: |
6239 | 83 query = None |
84 ui.debug(_('(starting inotify server)\n')) | |
85 try: | |
7329
fd4bf5269733
Do not abort with inotify extension enabled, but not supported by the system.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7304
diff
changeset
|
86 try: |
fd4bf5269733
Do not abort with inotify extension enabled, but not supported by the system.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7304
diff
changeset
|
87 server.start(ui, repo) |
fd4bf5269733
Do not abort with inotify extension enabled, but not supported by the system.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7304
diff
changeset
|
88 query = client.query |
fd4bf5269733
Do not abort with inotify extension enabled, but not supported by the system.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7304
diff
changeset
|
89 except server.AlreadyStartedException, inst: |
fd4bf5269733
Do not abort with inotify extension enabled, but not supported by the system.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7304
diff
changeset
|
90 # another process may have started its own |
fd4bf5269733
Do not abort with inotify extension enabled, but not supported by the system.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7304
diff
changeset
|
91 # inotify server while this one was starting. |
fd4bf5269733
Do not abort with inotify extension enabled, but not supported by the system.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7304
diff
changeset
|
92 ui.debug(str(inst)) |
fd4bf5269733
Do not abort with inotify extension enabled, but not supported by the system.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
7304
diff
changeset
|
93 query = client.query |
6239 | 94 except Exception, inst: |
95 ui.warn(_('could not start inotify server: ' | |
96 '%s\n') % inst) | |
97 if query: | |
98 try: | |
99 return query(ui, repo, files or [], match, | |
6753
ed5ffb2c12f3
repo.status: eliminate list_
Matt Mackall <mpm@selenic.com>
parents:
6603
diff
changeset
|
100 ignored, clean, unknown) |
6239 | 101 except socket.error, err: |
102 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
|
103 'server: %s\n') % err[-1]) |
7452
89c516430107
inotify: do not complain that inotify is not running if autostart is False
Brendan Cully <brendan@kublai.com>
parents:
7434
diff
changeset
|
104 elif err[0] in (errno.ECONNREFUSED, errno.ENOENT): |
89c516430107
inotify: do not complain that inotify is not running if autostart is False
Brendan Cully <brendan@kublai.com>
parents:
7434
diff
changeset
|
105 # silently ignore normal errors if autostart is False |
89c516430107
inotify: do not complain that inotify is not running if autostart is False
Brendan Cully <brendan@kublai.com>
parents:
7434
diff
changeset
|
106 ui.debug(_('(inotify server not running)\n')) |
6996
fecf060f32a1
inotify: deactivate inotify status on failure
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6995
diff
changeset
|
107 else: |
fecf060f32a1
inotify: deactivate inotify status on failure
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6995
diff
changeset
|
108 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
|
109 % err[-1]) |
fecf060f32a1
inotify: deactivate inotify status on failure
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6995
diff
changeset
|
110 ui.print_exc() |
fecf060f32a1
inotify: deactivate inotify status on failure
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6995
diff
changeset
|
111 # replace by old status function |
fecf060f32a1
inotify: deactivate inotify status on failure
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6995
diff
changeset
|
112 self.status = super(inotifydirstate, self).status |
6239 | 113 |
114 return super(inotifydirstate, self).status( | |
6753
ed5ffb2c12f3
repo.status: eliminate list_
Matt Mackall <mpm@selenic.com>
parents:
6603
diff
changeset
|
115 match, ignored, clean, unknown) |
6239 | 116 |
117 repo.dirstate.__class__ = inotifydirstate | |
118 | |
119 cmdtable = { | |
120 '^inserve': | |
121 (serve, | |
122 [('d', 'daemon', None, _('run server in background')), | |
123 ('', 'daemon-pipefds', '', _('used internally by daemon mode')), | |
124 ('t', 'idle-timeout', '', _('minutes to sit idle before exiting')), | |
125 ('', 'pid-file', '', _('name of file to write process ID to'))], | |
126 _('hg inserve [OPT]...')), | |
127 } |