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