Mercurial > hg
annotate hgext/inotify/__init__.py @ 6603:41eb20cc1c02
match: remove files arg from repo.status and friends
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 12 May 2008 11:37:08 -0500 |
parents | 39cfcef4f463 |
children | ed5ffb2c12f3 |
rev | line source |
---|---|
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 # | |
6 # This software may be used and distributed according to the terms | |
7 # of the GNU General Public License, incorporated herein by reference. | |
8 | |
9 '''inotify-based status acceleration for Linux systems | |
10 ''' | |
11 | |
12 # todo: socket permissions | |
13 | |
14 from mercurial.i18n import gettext as _ | |
15 from mercurial import cmdutil, util | |
16 import client, errno, os, server, socket | |
17 from weakref import proxy | |
18 | |
19 def serve(ui, repo, **opts): | |
20 '''start an inotify server for this repository''' | |
21 timeout = opts.get('timeout') | |
22 if timeout: | |
23 timeout = float(timeout) * 1e3 | |
24 | |
25 class service: | |
26 def init(self): | |
27 self.master = server.Master(ui, repo, timeout) | |
28 | |
29 def run(self): | |
30 try: | |
31 self.master.run() | |
32 finally: | |
33 self.master.shutdown() | |
34 | |
35 service = service() | |
36 cmdutil.service(opts, initfn=service.init, runfn=service.run) | |
37 | |
38 def reposetup(ui, repo): | |
39 if not repo.local(): | |
40 return | |
41 | |
42 # XXX: weakref until hg stops relying on __del__ | |
43 repo = proxy(repo) | |
44 | |
45 class inotifydirstate(repo.dirstate.__class__): | |
46 # Set to True if we're the inotify server, so we don't attempt | |
47 # to recurse. | |
48 inotifyserver = False | |
49 | |
6603
41eb20cc1c02
match: remove files arg from repo.status and friends
Matt Mackall <mpm@selenic.com>
parents:
6239
diff
changeset
|
50 def status(self, match, list_ignored, list_clean, |
6239 | 51 list_unknown=True): |
6603
41eb20cc1c02
match: remove files arg from repo.status and friends
Matt Mackall <mpm@selenic.com>
parents:
6239
diff
changeset
|
52 files = match.files() |
6239 | 53 try: |
54 if not list_ignored and not self.inotifyserver: | |
55 result = client.query(ui, repo, files, match, False, | |
56 list_clean, list_unknown) | |
57 if result is not None: | |
58 return result | |
59 except socket.error, err: | |
60 if err[0] == errno.ECONNREFUSED: | |
61 ui.warn(_('(found dead inotify server socket; ' | |
62 'removing it)\n')) | |
63 os.unlink(repo.join('inotify.sock')) | |
64 elif err[0] != errno.ENOENT: | |
65 raise | |
66 if ui.configbool('inotify', 'autostart'): | |
67 query = None | |
68 ui.debug(_('(starting inotify server)\n')) | |
69 try: | |
70 server.start(ui, repo) | |
71 query = client.query | |
72 except server.AlreadyStartedException, inst: | |
73 # another process may have started its own | |
74 # inotify server while this one was starting. | |
75 ui.debug(str(inst)) | |
76 query = client.query | |
77 except Exception, inst: | |
78 ui.warn(_('could not start inotify server: ' | |
79 '%s\n') % inst) | |
80 ui.print_exc() | |
81 | |
82 if query: | |
83 try: | |
84 return query(ui, repo, files or [], match, | |
85 list_ignored, list_clean, list_unknown) | |
86 except socket.error, err: | |
87 ui.warn(_('could not talk to new inotify ' | |
88 'server: %s\n') % err[1]) | |
89 ui.print_exc() | |
90 | |
91 return super(inotifydirstate, self).status( | |
6603
41eb20cc1c02
match: remove files arg from repo.status and friends
Matt Mackall <mpm@selenic.com>
parents:
6239
diff
changeset
|
92 match, list_ignored, list_clean, |
6239 | 93 list_unknown) |
94 | |
95 repo.dirstate.__class__ = inotifydirstate | |
96 | |
97 cmdtable = { | |
98 '^inserve': | |
99 (serve, | |
100 [('d', 'daemon', None, _('run server in background')), | |
101 ('', 'daemon-pipefds', '', _('used internally by daemon mode')), | |
102 ('t', 'idle-timeout', '', _('minutes to sit idle before exiting')), | |
103 ('', 'pid-file', '', _('name of file to write process ID to'))], | |
104 _('hg inserve [OPT]...')), | |
105 } |