Show More
@@ -1,110 +1,112 b'' | |||||
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 of the |
|
6 | # This software may be used and distributed according to the terms of the | |
7 | # GNU General Public License version 2, incorporated herein by reference. |
|
7 | # GNU General Public License version 2, 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 _ |
|
14 | from mercurial.i18n import _ | |
15 | from mercurial import cmdutil, util |
|
15 | from mercurial import cmdutil, util | |
16 | import server |
|
16 | import server | |
17 | from weakref import proxy |
|
17 | from weakref import proxy | |
18 | from client import client, QueryFailed |
|
18 | from client import client, QueryFailed | |
19 |
|
19 | |||
20 | def serve(ui, repo, **opts): |
|
20 | def serve(ui, repo, **opts): | |
21 | '''start an inotify server for this repository''' |
|
21 | '''start an inotify server for this repository''' | |
22 | timeout = opts.get('timeout') |
|
22 | timeout = opts.get('timeout') | |
23 | if timeout: |
|
23 | if timeout: | |
24 | timeout = float(timeout) * 1e3 |
|
24 | timeout = float(timeout) * 1e3 | |
25 |
|
25 | |||
26 | class service(object): |
|
26 | class service(object): | |
27 | def init(self): |
|
27 | def init(self): | |
28 | try: |
|
28 | try: | |
29 | self.master = server.master(ui, repo, timeout) |
|
29 | self.master = server.master(ui, repo, timeout) | |
30 | except server.AlreadyStartedException, inst: |
|
30 | except server.AlreadyStartedException, inst: | |
31 | raise util.Abort(str(inst)) |
|
31 | raise util.Abort(str(inst)) | |
32 |
|
32 | |||
33 | def run(self): |
|
33 | def run(self): | |
34 | try: |
|
34 | try: | |
35 | self.master.run() |
|
35 | self.master.run() | |
36 | finally: |
|
36 | finally: | |
37 | self.master.shutdown() |
|
37 | self.master.shutdown() | |
38 |
|
38 | |||
39 | service = service() |
|
39 | service = service() | |
40 | cmdutil.service(opts, initfn=service.init, runfn=service.run) |
|
40 | logfile = ui.config('inotify', 'log') | |
|
41 | cmdutil.service(opts, initfn=service.init, runfn=service.run, | |||
|
42 | logfile=logfile) | |||
41 |
|
43 | |||
42 | def debuginotify(ui, repo, **opts): |
|
44 | def debuginotify(ui, repo, **opts): | |
43 | '''debugging information for inotify extension |
|
45 | '''debugging information for inotify extension | |
44 |
|
46 | |||
45 | Prints the list of directories being watched by the inotify server. |
|
47 | Prints the list of directories being watched by the inotify server. | |
46 | ''' |
|
48 | ''' | |
47 | cli = client(ui, repo) |
|
49 | cli = client(ui, repo) | |
48 | response = cli.debugquery() |
|
50 | response = cli.debugquery() | |
49 |
|
51 | |||
50 | ui.write(_('directories being watched:\n')) |
|
52 | ui.write(_('directories being watched:\n')) | |
51 | for path in response: |
|
53 | for path in response: | |
52 | ui.write((' %s/\n') % path) |
|
54 | ui.write((' %s/\n') % path) | |
53 |
|
55 | |||
54 | def reposetup(ui, repo): |
|
56 | def reposetup(ui, repo): | |
55 | if not hasattr(repo, 'dirstate'): |
|
57 | if not hasattr(repo, 'dirstate'): | |
56 | return |
|
58 | return | |
57 |
|
59 | |||
58 | # XXX: weakref until hg stops relying on __del__ |
|
60 | # XXX: weakref until hg stops relying on __del__ | |
59 | repo = proxy(repo) |
|
61 | repo = proxy(repo) | |
60 |
|
62 | |||
61 | class inotifydirstate(repo.dirstate.__class__): |
|
63 | class inotifydirstate(repo.dirstate.__class__): | |
62 |
|
64 | |||
63 | # We'll set this to false after an unsuccessful attempt so that |
|
65 | # We'll set this to false after an unsuccessful attempt so that | |
64 | # next calls of status() within the same instance don't try again |
|
66 | # next calls of status() within the same instance don't try again | |
65 | # to start an inotify server if it won't start. |
|
67 | # to start an inotify server if it won't start. | |
66 | _inotifyon = True |
|
68 | _inotifyon = True | |
67 |
|
69 | |||
68 | def status(self, match, ignored, clean, unknown=True): |
|
70 | def status(self, match, ignored, clean, unknown=True): | |
69 | files = match.files() |
|
71 | files = match.files() | |
70 | if '.' in files: |
|
72 | if '.' in files: | |
71 | files = [] |
|
73 | files = [] | |
72 | if self._inotifyon and not ignored: |
|
74 | if self._inotifyon and not ignored: | |
73 | cli = client(ui, repo) |
|
75 | cli = client(ui, repo) | |
74 | try: |
|
76 | try: | |
75 | result = cli.statusquery(files, match, False, |
|
77 | result = cli.statusquery(files, match, False, | |
76 | clean, unknown) |
|
78 | clean, unknown) | |
77 | except QueryFailed, instr: |
|
79 | except QueryFailed, instr: | |
78 | ui.debug(str(instr)) |
|
80 | ui.debug(str(instr)) | |
79 | # don't retry within the same hg instance |
|
81 | # don't retry within the same hg instance | |
80 | inotifydirstate._inotifyon = False |
|
82 | inotifydirstate._inotifyon = False | |
81 | pass |
|
83 | pass | |
82 | else: |
|
84 | else: | |
83 | if ui.config('inotify', 'debug'): |
|
85 | if ui.config('inotify', 'debug'): | |
84 | r2 = super(inotifydirstate, self).status( |
|
86 | r2 = super(inotifydirstate, self).status( | |
85 | match, False, clean, unknown) |
|
87 | match, False, clean, unknown) | |
86 | for c,a,b in zip('LMARDUIC', result, r2): |
|
88 | for c,a,b in zip('LMARDUIC', result, r2): | |
87 | for f in a: |
|
89 | for f in a: | |
88 | if f not in b: |
|
90 | if f not in b: | |
89 | ui.warn('*** inotify: %s +%s\n' % (c, f)) |
|
91 | ui.warn('*** inotify: %s +%s\n' % (c, f)) | |
90 | for f in b: |
|
92 | for f in b: | |
91 | if f not in a: |
|
93 | if f not in a: | |
92 | ui.warn('*** inotify: %s -%s\n' % (c, f)) |
|
94 | ui.warn('*** inotify: %s -%s\n' % (c, f)) | |
93 | result = r2 |
|
95 | result = r2 | |
94 | return result |
|
96 | return result | |
95 | return super(inotifydirstate, self).status( |
|
97 | return super(inotifydirstate, self).status( | |
96 | match, ignored, clean, unknown) |
|
98 | match, ignored, clean, unknown) | |
97 |
|
99 | |||
98 | repo.dirstate.__class__ = inotifydirstate |
|
100 | repo.dirstate.__class__ = inotifydirstate | |
99 |
|
101 | |||
100 | cmdtable = { |
|
102 | cmdtable = { | |
101 | 'debuginotify': |
|
103 | 'debuginotify': | |
102 | (debuginotify, [], ('hg debuginotify')), |
|
104 | (debuginotify, [], ('hg debuginotify')), | |
103 | '^inserve': |
|
105 | '^inserve': | |
104 | (serve, |
|
106 | (serve, | |
105 | [('d', 'daemon', None, _('run server in background')), |
|
107 | [('d', 'daemon', None, _('run server in background')), | |
106 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), |
|
108 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), | |
107 | ('t', 'idle-timeout', '', _('minutes to sit idle before exiting')), |
|
109 | ('t', 'idle-timeout', '', _('minutes to sit idle before exiting')), | |
108 | ('', 'pid-file', '', _('name of file to write process ID to'))], |
|
110 | ('', 'pid-file', '', _('name of file to write process ID to'))], | |
109 | _('hg inserve [OPT]...')), |
|
111 | _('hg inserve [OPT]...')), | |
110 | } |
|
112 | } |
General Comments 0
You need to be logged in to leave comments.
Login now