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