author | Nicolas Dumazet <nicdumz.commits@gmail.com> |
Tue, 07 Apr 2009 19:30:01 +0900 | |
changeset 8552 | 06561793778e |
parent 8551 | 7089d9727867 |
child 8555 | 3e09bc5fee12 |
permissions | -rw-r--r-- |
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 |
# |
|
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8206
diff
changeset
|
6 |
# This software may be used and distributed according to the terms of the |
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8206
diff
changeset
|
7 |
# GNU General Public License version 2, incorporated herein by reference. |
6239 | 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 |
8552
06561793778e
inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8551
diff
changeset
|
16 |
import os, server |
6239 | 17 |
from weakref import proxy |
8552
06561793778e
inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8551
diff
changeset
|
18 |
from client import client, QueryFailed |
6239 | 19 |
|
20 |
def serve(ui, repo, **opts): |
|
21 |
'''start an inotify server for this repository''' |
|
22 |
timeout = opts.get('timeout') |
|
23 |
if timeout: |
|
24 |
timeout = float(timeout) * 1e3 |
|
25 |
||
26 |
class service: |
|
27 |
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
|
28 |
try: |
8385
1536501ade62
inotify: Coding Style: name classes in lowercase.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8225
diff
changeset
|
29 |
self.master = server.master(ui, repo, timeout) |
6995
25619b72f86a
inotify: fix traceback when the server has been already started
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6239
diff
changeset
|
30 |
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
|
31 |
raise util.Abort(str(inst)) |
6239 | 32 |
|
33 |
def run(self): |
|
34 |
try: |
|
35 |
self.master.run() |
|
36 |
finally: |
|
37 |
self.master.shutdown() |
|
38 |
||
39 |
service = service() |
|
40 |
cmdutil.service(opts, initfn=service.init, runfn=service.run) |
|
41 |
||
42 |
def reposetup(ui, repo): |
|
7522
2f4a399a8787
inotify: do not attempt to monkeypatch bundlerepos
Brendan Cully <brendan@kublai.com>
parents:
7452
diff
changeset
|
43 |
if not hasattr(repo, 'dirstate'): |
6239 | 44 |
return |
45 |
||
46 |
# XXX: weakref until hg stops relying on __del__ |
|
47 |
repo = proxy(repo) |
|
48 |
||
49 |
class inotifydirstate(repo.dirstate.__class__): |
|
50 |
# Set to True if we're the inotify server, so we don't attempt |
|
51 |
# to recurse. |
|
52 |
inotifyserver = False |
|
53 |
||
6753
ed5ffb2c12f3
repo.status: eliminate list_
Matt Mackall <mpm@selenic.com>
parents:
6603
diff
changeset
|
54 |
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
|
55 |
files = match.files() |
7393
92c952c4470c
inotify: fix status . in repo.root
Brendan Cully <brendan@kublai.com>
parents:
7329
diff
changeset
|
56 |
if '.' in files: |
7434
cf7741aa1e96
kill some trailing spaces
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7393
diff
changeset
|
57 |
files = [] |
8552
06561793778e
inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8551
diff
changeset
|
58 |
if not ignored and not self.inotifyserver: |
06561793778e
inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8551
diff
changeset
|
59 |
cli = client(ui, repo) |
06561793778e
inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8551
diff
changeset
|
60 |
try: |
8551
7089d9727867
inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8385
diff
changeset
|
61 |
result = cli.statusquery(files, match, False, |
8552
06561793778e
inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8551
diff
changeset
|
62 |
clean, unknown) |
06561793778e
inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8551
diff
changeset
|
63 |
except QueryFailed, instr: |
06561793778e
inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8551
diff
changeset
|
64 |
ui.debug(str(instr)) |
06561793778e
inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8551
diff
changeset
|
65 |
pass |
06561793778e
inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8551
diff
changeset
|
66 |
else: |
06561793778e
inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8551
diff
changeset
|
67 |
if ui.config('inotify', 'debug'): |
7219
1f6d2e487135
inotify: add debugging mode to inotify
Matt Mackall <mpm@selenic.com>
parents:
7218
diff
changeset
|
68 |
r2 = super(inotifydirstate, self).status( |
1f6d2e487135
inotify: add debugging mode to inotify
Matt Mackall <mpm@selenic.com>
parents:
7218
diff
changeset
|
69 |
match, False, clean, unknown) |
1f6d2e487135
inotify: add debugging mode to inotify
Matt Mackall <mpm@selenic.com>
parents:
7218
diff
changeset
|
70 |
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
|
71 |
for f in a: |
1f6d2e487135
inotify: add debugging mode to inotify
Matt Mackall <mpm@selenic.com>
parents:
7218
diff
changeset
|
72 |
if f not in b: |
1f6d2e487135
inotify: add debugging mode to inotify
Matt Mackall <mpm@selenic.com>
parents:
7218
diff
changeset
|
73 |
ui.warn('*** inotify: %s +%s\n' % (c, f)) |
1f6d2e487135
inotify: add debugging mode to inotify
Matt Mackall <mpm@selenic.com>
parents:
7218
diff
changeset
|
74 |
for f in b: |
1f6d2e487135
inotify: add debugging mode to inotify
Matt Mackall <mpm@selenic.com>
parents:
7218
diff
changeset
|
75 |
if f not in a: |
7304
68374f1c8c87
inotify: fix bug in formatting
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7225
diff
changeset
|
76 |
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
|
77 |
result = r2 |
8552
06561793778e
inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8551
diff
changeset
|
78 |
return result |
6239 | 79 |
return super(inotifydirstate, self).status( |
6753
ed5ffb2c12f3
repo.status: eliminate list_
Matt Mackall <mpm@selenic.com>
parents:
6603
diff
changeset
|
80 |
match, ignored, clean, unknown) |
6239 | 81 |
|
82 |
repo.dirstate.__class__ = inotifydirstate |
|
83 |
||
84 |
cmdtable = { |
|
85 |
'^inserve': |
|
86 |
(serve, |
|
87 |
[('d', 'daemon', None, _('run server in background')), |
|
88 |
('', 'daemon-pipefds', '', _('used internally by daemon mode')), |
|
89 |
('t', 'idle-timeout', '', _('minutes to sit idle before exiting')), |
|
90 |
('', 'pid-file', '', _('name of file to write process ID to'))], |
|
91 |
_('hg inserve [OPT]...')), |
|
92 |
} |