annotate hgext/inotify/__init__.py @ 18437:358c23e8f1c6

histedit: record histedit source (issue3681) Have histedit record the hex of the original changeset as already done by: - graft - commit --amend - rebase My main motivation for adding this is to prevent the creation of obsolescence cycle (see issue3681). Note that commit created during edit are not affected yet.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Wed, 16 Jan 2013 19:14:22 +0100
parents 38caf405d010
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
1 # __init__.py - inotify-based status acceleration for Linux
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
2 #
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
3 # Copyright 2006, 2007, 2008 Bryan O'Sullivan <bos@serpentine.com>
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
4 # Copyright 2007, 2008 Brendan Cully <brendan@kublai.com>
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
5 #
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8206
diff changeset
6 # This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9855
diff changeset
7 # GNU General Public License version 2 or any later version.
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
8
8932
f87884329419 extensions: fix up description lines some more
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8894
diff changeset
9 '''accelerate status report using Linux's inotify service'''
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
10
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
11 # todo: socket permissions
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
12
7225
59b4ae211584 i18n: import _ instead of gettext
Martin Geisler <mg@daimi.au.dk>
parents: 7219
diff changeset
13 from mercurial.i18n import _
14945
11aad09a6370 hgext: replace uses of hasattr with util.safehasattr
Augie Fackler <durin42@gmail.com>
parents: 11321
diff changeset
14 from mercurial import util
8656
284fda4cd093 removed unused imports
Martin Geisler <mg@lazybytes.net>
parents: 8557
diff changeset
15 import server
8552
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
16 from client import client, QueryFailed
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
17
16743
38caf405d010 hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents: 16683
diff changeset
18 testedwith = 'internal'
38caf405d010 hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents: 16683
diff changeset
19
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
20 def serve(ui, repo, **opts):
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
21 '''start an inotify server for this repository'''
9514
7c01599dd340 inotify: use cmdutil.service instead of local daemonizing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 9355
diff changeset
22 server.start(ui, repo.dirstate, repo.root, opts)
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
23
8555
3e09bc5fee12 inotify: introduce debuginotify, which lists which paths are under watch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8552
diff changeset
24 def debuginotify(ui, repo, **opts):
3e09bc5fee12 inotify: introduce debuginotify, which lists which paths are under watch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8552
diff changeset
25 '''debugging information for inotify extension
3e09bc5fee12 inotify: introduce debuginotify, which lists which paths are under watch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8552
diff changeset
26
3e09bc5fee12 inotify: introduce debuginotify, which lists which paths are under watch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8552
diff changeset
27 Prints the list of directories being watched by the inotify server.
3e09bc5fee12 inotify: introduce debuginotify, which lists which paths are under watch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8552
diff changeset
28 '''
3e09bc5fee12 inotify: introduce debuginotify, which lists which paths are under watch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8552
diff changeset
29 cli = client(ui, repo)
3e09bc5fee12 inotify: introduce debuginotify, which lists which paths are under watch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8552
diff changeset
30 response = cli.debugquery()
3e09bc5fee12 inotify: introduce debuginotify, which lists which paths are under watch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8552
diff changeset
31
3e09bc5fee12 inotify: introduce debuginotify, which lists which paths are under watch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8552
diff changeset
32 ui.write(_('directories being watched:\n'))
3e09bc5fee12 inotify: introduce debuginotify, which lists which paths are under watch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8552
diff changeset
33 for path in response:
3e09bc5fee12 inotify: introduce debuginotify, which lists which paths are under watch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8552
diff changeset
34 ui.write((' %s/\n') % path)
3e09bc5fee12 inotify: introduce debuginotify, which lists which paths are under watch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8552
diff changeset
35
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
36 def reposetup(ui, repo):
14945
11aad09a6370 hgext: replace uses of hasattr with util.safehasattr
Augie Fackler <durin42@gmail.com>
parents: 11321
diff changeset
37 if not util.safehasattr(repo, 'dirstate'):
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
38 return
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
39
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
40 class inotifydirstate(repo.dirstate.__class__):
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
41
8556
f5fae700cc00 inotify: set a flag so a failed inotify query doesn't get repeated.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8555
diff changeset
42 # We'll set this to false after an unsuccessful attempt so that
f5fae700cc00 inotify: set a flag so a failed inotify query doesn't get repeated.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8555
diff changeset
43 # next calls of status() within the same instance don't try again
f5fae700cc00 inotify: set a flag so a failed inotify query doesn't get repeated.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8555
diff changeset
44 # to start an inotify server if it won't start.
f5fae700cc00 inotify: set a flag so a failed inotify query doesn't get repeated.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8555
diff changeset
45 _inotifyon = True
f5fae700cc00 inotify: set a flag so a failed inotify query doesn't get repeated.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8555
diff changeset
46
10605
3077ee5ca750 inotify: expose the same dirstate.status() interface as dirstate.
Greg Ward <greg-hg@gerg.ca>
parents: 10493
diff changeset
47 def status(self, match, subrepos, ignored, clean, unknown):
6603
41eb20cc1c02 match: remove files arg from repo.status and friends
Matt Mackall <mpm@selenic.com>
parents: 6239
diff changeset
48 files = match.files()
7393
92c952c4470c inotify: fix status . in repo.root
Brendan Cully <brendan@kublai.com>
parents: 7329
diff changeset
49 if '.' in files:
7434
cf7741aa1e96 kill some trailing spaces
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7393
diff changeset
50 files = []
16683
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 14945
diff changeset
51 if (self._inotifyon and not ignored and not subrepos and
525fdb738975 cleanup: eradicate long lines
Brodie Rao <brodie@sf.io>
parents: 14945
diff changeset
52 not self._dirty):
8552
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
53 cli = client(ui, repo)
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
54 try:
8551
7089d9727867 inotify: modular architecture for inotify clients
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8385
diff changeset
55 result = cli.statusquery(files, match, False,
8552
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
56 clean, unknown)
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
57 except QueryFailed, instr:
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
58 ui.debug(str(instr))
8556
f5fae700cc00 inotify: set a flag so a failed inotify query doesn't get repeated.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8555
diff changeset
59 # don't retry within the same hg instance
f5fae700cc00 inotify: set a flag so a failed inotify query doesn't get repeated.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8555
diff changeset
60 inotifydirstate._inotifyon = False
8552
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
61 pass
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
62 else:
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
63 if ui.config('inotify', 'debug'):
7219
1f6d2e487135 inotify: add debugging mode to inotify
Matt Mackall <mpm@selenic.com>
parents: 7218
diff changeset
64 r2 = super(inotifydirstate, self).status(
10493
283f3b413f19 regression: missing arg from 24ce8f0c0a39 dirstate.{walk,status} changes
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10463
diff changeset
65 match, [], False, clean, unknown)
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
66 for c, a, b in zip('LMARDUIC', result, r2):
7219
1f6d2e487135 inotify: add debugging mode to inotify
Matt Mackall <mpm@selenic.com>
parents: 7218
diff changeset
67 for f in a:
1f6d2e487135 inotify: add debugging mode to inotify
Matt Mackall <mpm@selenic.com>
parents: 7218
diff changeset
68 if f not in b:
1f6d2e487135 inotify: add debugging mode to inotify
Matt Mackall <mpm@selenic.com>
parents: 7218
diff changeset
69 ui.warn('*** inotify: %s +%s\n' % (c, f))
1f6d2e487135 inotify: add debugging mode to inotify
Matt Mackall <mpm@selenic.com>
parents: 7218
diff changeset
70 for f in b:
1f6d2e487135 inotify: add debugging mode to inotify
Matt Mackall <mpm@selenic.com>
parents: 7218
diff changeset
71 if f not in a:
7304
68374f1c8c87 inotify: fix bug in formatting
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 7225
diff changeset
72 ui.warn('*** inotify: %s -%s\n' % (c, f))
7219
1f6d2e487135 inotify: add debugging mode to inotify
Matt Mackall <mpm@selenic.com>
parents: 7218
diff changeset
73 result = r2
8552
06561793778e inotify: Separate query sending logic from Server starting.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8551
diff changeset
74 return result
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
75 return super(inotifydirstate, self).status(
10176
24ce8f0c0a39 dirstate: don't check state of subrepo directories
Augie Fackler <durin42@gmail.com>
parents: 9855
diff changeset
76 match, subrepos, ignored, clean, unknown)
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
77
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
78 repo.dirstate.__class__ = inotifydirstate
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
79
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
80 cmdtable = {
8555
3e09bc5fee12 inotify: introduce debuginotify, which lists which paths are under watch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8552
diff changeset
81 'debuginotify':
3e09bc5fee12 inotify: introduce debuginotify, which lists which paths are under watch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8552
diff changeset
82 (debuginotify, [], ('hg debuginotify')),
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
83 '^inserve':
8555
3e09bc5fee12 inotify: introduce debuginotify, which lists which paths are under watch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8552
diff changeset
84 (serve,
3e09bc5fee12 inotify: introduce debuginotify, which lists which paths are under watch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8552
diff changeset
85 [('d', 'daemon', None, _('run server in background')),
11321
40c06bbf58be help: show value requirement and multiple occurrence of options
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 10605
diff changeset
86 ('', 'daemon-pipefds', '',
40c06bbf58be help: show value requirement and multiple occurrence of options
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 10605
diff changeset
87 _('used internally by daemon mode'), _('NUM')),
40c06bbf58be help: show value requirement and multiple occurrence of options
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 10605
diff changeset
88 ('t', 'idle-timeout', '',
40c06bbf58be help: show value requirement and multiple occurrence of options
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 10605
diff changeset
89 _('minutes to sit idle before exiting'), _('NUM')),
40c06bbf58be help: show value requirement and multiple occurrence of options
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 10605
diff changeset
90 ('', 'pid-file', '',
40c06bbf58be help: show value requirement and multiple occurrence of options
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 10605
diff changeset
91 _('name of file to write process ID to'), _('FILE'))],
8947
9cda78218ab3 inotify: OPT -> OPTION in cmdline help string
Martin Geisler <mg@lazybytes.net>
parents: 8932
diff changeset
92 _('hg inserve [OPTION]...')),
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
93 }