Show More
@@ -1,110 +1,110 | |||||
1 | # __init__.py - inotify-based status acceleration for Linux |
|
1 | # __init__.py - inotify-based status acceleration for Linux | |
2 | # |
|
2 | # | |
3 | # Copyright 2006, 2007, 2008 Bryan O'Sullivan <bos@serpentine.com> |
|
3 | # Copyright 2006, 2007, 2008 Bryan O'Sullivan <bos@serpentine.com> | |
4 | # Copyright 2007, 2008 Brendan Cully <brendan@kublai.com> |
|
4 | # Copyright 2007, 2008 Brendan Cully <brendan@kublai.com> | |
5 | # |
|
5 | # | |
6 | # This software may be used and distributed according to the terms |
|
6 | # This software may be used and distributed according to the terms | |
7 | # of the GNU General Public License, incorporated herein by reference. |
|
7 | # of the GNU General Public License, incorporated herein by reference. | |
8 |
|
8 | |||
9 | '''inotify-based status acceleration for Linux systems |
|
9 | '''inotify-based status acceleration for Linux systems | |
10 | ''' |
|
10 | ''' | |
11 |
|
11 | |||
12 | # todo: socket permissions |
|
12 | # todo: socket permissions | |
13 |
|
13 | |||
14 | from mercurial.i18n import gettext as _ |
|
14 | from mercurial.i18n import gettext as _ | |
15 | from mercurial import cmdutil, util |
|
15 | from mercurial import cmdutil, util | |
16 | import client, errno, os, server, socket |
|
16 | import client, errno, os, server, socket | |
17 | from weakref import proxy |
|
17 | from weakref import proxy | |
18 |
|
18 | |||
19 | def serve(ui, repo, **opts): |
|
19 | def serve(ui, repo, **opts): | |
20 | '''start an inotify server for this repository''' |
|
20 | '''start an inotify server for this repository''' | |
21 | timeout = opts.get('timeout') |
|
21 | timeout = opts.get('timeout') | |
22 | if timeout: |
|
22 | if timeout: | |
23 | timeout = float(timeout) * 1e3 |
|
23 | timeout = float(timeout) * 1e3 | |
24 |
|
24 | |||
25 | class service: |
|
25 | class service: | |
26 | def init(self): |
|
26 | def init(self): | |
27 | try: |
|
27 | try: | |
28 | self.master = server.Master(ui, repo, timeout) |
|
28 | self.master = server.Master(ui, repo, timeout) | |
29 | except server.AlreadyStartedException, inst: |
|
29 | except server.AlreadyStartedException, inst: | |
30 | raise util.Abort(str(inst)) |
|
30 | raise util.Abort(str(inst)) | |
31 |
|
31 | |||
32 | def run(self): |
|
32 | def run(self): | |
33 | try: |
|
33 | try: | |
34 | self.master.run() |
|
34 | self.master.run() | |
35 | finally: |
|
35 | finally: | |
36 | self.master.shutdown() |
|
36 | self.master.shutdown() | |
37 |
|
37 | |||
38 | service = service() |
|
38 | service = service() | |
39 | cmdutil.service(opts, initfn=service.init, runfn=service.run) |
|
39 | cmdutil.service(opts, initfn=service.init, runfn=service.run) | |
40 |
|
40 | |||
41 | def reposetup(ui, repo): |
|
41 | def reposetup(ui, repo): | |
42 | if not repo.local(): |
|
42 | if not repo.local(): | |
43 | return |
|
43 | return | |
44 |
|
44 | |||
45 | # XXX: weakref until hg stops relying on __del__ |
|
45 | # XXX: weakref until hg stops relying on __del__ | |
46 | repo = proxy(repo) |
|
46 | repo = proxy(repo) | |
47 |
|
47 | |||
48 | class inotifydirstate(repo.dirstate.__class__): |
|
48 | class inotifydirstate(repo.dirstate.__class__): | |
49 | # Set to True if we're the inotify server, so we don't attempt |
|
49 | # Set to True if we're the inotify server, so we don't attempt | |
50 | # to recurse. |
|
50 | # to recurse. | |
51 | inotifyserver = False |
|
51 | inotifyserver = False | |
52 |
|
52 | |||
53 | def status(self, match, ignored, clean, unknown=True): |
|
53 | def status(self, match, ignored, clean, unknown=True): | |
54 | files = match.files() |
|
54 | files = match.files() | |
55 | try: |
|
55 | try: | |
56 | if not ignored and not self.inotifyserver: |
|
56 | if not ignored and not self.inotifyserver: | |
57 | result = client.query(ui, repo, files, match, False, |
|
57 | result = client.query(ui, repo, files, match, False, | |
58 | clean, unknown) |
|
58 | clean, unknown) | |
59 | if result is not None: |
|
59 | if result is not None: | |
60 | return result |
|
60 | return result | |
61 | except (OSError, socket.error), err: |
|
61 | except (OSError, socket.error), err: | |
62 | if err[0] == errno.ECONNREFUSED: |
|
62 | if err[0] == errno.ECONNREFUSED: | |
63 | ui.warn(_('(found dead inotify server socket; ' |
|
63 | ui.warn(_('(found dead inotify server socket; ' | |
64 | 'removing it)\n')) |
|
64 | 'removing it)\n')) | |
65 | os.unlink(repo.join('inotify.sock')) |
|
65 | os.unlink(repo.join('inotify.sock')) | |
66 | if err[0] in (errno.ECONNREFUSED, errno.ENOENT) and \ |
|
66 | if err[0] in (errno.ECONNREFUSED, errno.ENOENT) and \ | |
67 | ui.configbool('inotify', 'autostart'): |
|
67 | ui.configbool('inotify', 'autostart', True): | |
68 | query = None |
|
68 | query = None | |
69 | ui.debug(_('(starting inotify server)\n')) |
|
69 | ui.debug(_('(starting inotify server)\n')) | |
70 | try: |
|
70 | try: | |
71 | server.start(ui, repo) |
|
71 | server.start(ui, repo) | |
72 | query = client.query |
|
72 | query = client.query | |
73 | except server.AlreadyStartedException, inst: |
|
73 | except server.AlreadyStartedException, inst: | |
74 | # another process may have started its own |
|
74 | # another process may have started its own | |
75 | # inotify server while this one was starting. |
|
75 | # inotify server while this one was starting. | |
76 | ui.debug(str(inst)) |
|
76 | ui.debug(str(inst)) | |
77 | query = client.query |
|
77 | query = client.query | |
78 | except Exception, inst: |
|
78 | except Exception, inst: | |
79 | ui.warn(_('could not start inotify server: ' |
|
79 | ui.warn(_('could not start inotify server: ' | |
80 | '%s\n') % inst) |
|
80 | '%s\n') % inst) | |
81 | if query: |
|
81 | if query: | |
82 | try: |
|
82 | try: | |
83 | return query(ui, repo, files or [], match, |
|
83 | return query(ui, repo, files or [], match, | |
84 | ignored, clean, unknown) |
|
84 | ignored, clean, unknown) | |
85 | except socket.error, err: |
|
85 | except socket.error, err: | |
86 | ui.warn(_('could not talk to new inotify ' |
|
86 | ui.warn(_('could not talk to new inotify ' | |
87 | 'server: %s\n') % err[-1]) |
|
87 | 'server: %s\n') % err[-1]) | |
88 | elif err[0] == errno.ENOENT: |
|
88 | elif err[0] == errno.ENOENT: | |
89 | ui.warn(_('(inotify server not running)\n')) |
|
89 | ui.warn(_('(inotify server not running)\n')) | |
90 | else: |
|
90 | else: | |
91 | ui.warn(_('failed to contact inotify server: %s\n') |
|
91 | ui.warn(_('failed to contact inotify server: %s\n') | |
92 | % err[-1]) |
|
92 | % err[-1]) | |
93 | ui.print_exc() |
|
93 | ui.print_exc() | |
94 | # replace by old status function |
|
94 | # replace by old status function | |
95 | self.status = super(inotifydirstate, self).status |
|
95 | self.status = super(inotifydirstate, self).status | |
96 |
|
96 | |||
97 | return super(inotifydirstate, self).status( |
|
97 | return super(inotifydirstate, self).status( | |
98 | match, ignored, clean, unknown) |
|
98 | match, ignored, clean, unknown) | |
99 |
|
99 | |||
100 | repo.dirstate.__class__ = inotifydirstate |
|
100 | repo.dirstate.__class__ = inotifydirstate | |
101 |
|
101 | |||
102 | cmdtable = { |
|
102 | cmdtable = { | |
103 | '^inserve': |
|
103 | '^inserve': | |
104 | (serve, |
|
104 | (serve, | |
105 | [('d', 'daemon', None, _('run server in background')), |
|
105 | [('d', 'daemon', None, _('run server in background')), | |
106 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), |
|
106 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), | |
107 | ('t', 'idle-timeout', '', _('minutes to sit idle before exiting')), |
|
107 | ('t', 'idle-timeout', '', _('minutes to sit idle before exiting')), | |
108 | ('', 'pid-file', '', _('name of file to write process ID to'))], |
|
108 | ('', 'pid-file', '', _('name of file to write process ID to'))], | |
109 | _('hg inserve [OPT]...')), |
|
109 | _('hg inserve [OPT]...')), | |
110 | } |
|
110 | } |
@@ -1,6 +1,6 | |||||
1 | % fail |
|
1 | % fail | |
2 |
|
|
2 | could not talk to new inotify server: No such file or directory | |
3 | abort: could not start server: File exists |
|
3 | abort: could not start server: File exists | |
4 | % inserve |
|
4 | % inserve | |
5 | % status |
|
5 | % status | |
6 | ? hg.pid |
|
6 | ? hg.pid |
General Comments 0
You need to be logged in to leave comments.
Login now