Mercurial > public > mercurial-scm > hg
annotate hgext/inotify/server.py @ 10494:08064db9f005 stable
inotify/inserve: implement --timeout-idle option (issue885)
hg inserve was ignoring and miscomputing the --timeout-idle option (seconds
vs. minutes).
Thanks to Jesse Glick for the bugreport and the initial patch.
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Wed, 17 Feb 2010 20:44:49 +0100 |
parents | 08a0f04b56bd |
children | db9d16233787 |
rev | line source |
---|---|
9933
2e7902158af9
inotify: create a common, OS-independent server entry point
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9900
diff
changeset
|
1 # server.py - common entry point for inotify status server |
6239 | 2 # |
9933
2e7902158af9
inotify: create a common, OS-independent server entry point
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9900
diff
changeset
|
3 # Copyright 2009 Nicolas Dumazet <nicdumz@gmail.com> |
6239 | 4 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8209
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
10263 | 6 # GNU General Public License version 2 or any later version. |
6239 | 7 |
6961
12163fb21fce
i18n: mark strings for translation in inotify extension
Martin Geisler <mg@daimi.au.dk>
parents:
6909
diff
changeset
|
8 from mercurial.i18n import _ |
9514
7c01599dd340
inotify: use cmdutil.service instead of local daemonizing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9351
diff
changeset
|
9 from mercurial import cmdutil, osutil, util |
6239 | 10 import common |
11 | |
9933
2e7902158af9
inotify: create a common, OS-independent server entry point
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9900
diff
changeset
|
12 import errno |
2e7902158af9
inotify: create a common, OS-independent server entry point
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9900
diff
changeset
|
13 import os |
2e7902158af9
inotify: create a common, OS-independent server entry point
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9900
diff
changeset
|
14 import socket |
2e7902158af9
inotify: create a common, OS-independent server entry point
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9900
diff
changeset
|
15 import stat |
2e7902158af9
inotify: create a common, OS-independent server entry point
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9900
diff
changeset
|
16 import struct |
2e7902158af9
inotify: create a common, OS-independent server entry point
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9900
diff
changeset
|
17 import sys |
2e7902158af9
inotify: create a common, OS-independent server entry point
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9900
diff
changeset
|
18 import tempfile |
6239 | 19 |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
20 class AlreadyStartedException(Exception): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
21 pass |
10494
08064db9f005
inotify/inserve: implement --timeout-idle option (issue885)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
22 class TimeoutException(Exception): |
08064db9f005
inotify/inserve: implement --timeout-idle option (issue885)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
23 pass |
6239 | 24 |
25 def join(a, b): | |
26 if a: | |
27 if a[-1] == '/': | |
28 return a + b | |
29 return a + '/' + b | |
30 return b | |
31 | |
8787
9aca76502280
inotify: server: move split() out of server
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8786
diff
changeset
|
32 def split(path): |
9aca76502280
inotify: server: move split() out of server
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8786
diff
changeset
|
33 c = path.rfind('/') |
9aca76502280
inotify: server: move split() out of server
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8786
diff
changeset
|
34 if c == -1: |
9aca76502280
inotify: server: move split() out of server
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8786
diff
changeset
|
35 return '', path |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
36 return path[:c], path[c + 1:] |
8787
9aca76502280
inotify: server: move split() out of server
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8786
diff
changeset
|
37 |
6239 | 38 walk_ignored_errors = (errno.ENOENT, errno.ENAMETOOLONG) |
39 | |
9350
b789ea382fc0
inotify: server: use dirstate instead of repo
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9349
diff
changeset
|
40 def walk(dirstate, absroot, root): |
6239 | 41 '''Like os.walk, but only yields regular files.''' |
42 | |
43 # This function is critical to performance during startup. | |
44 | |
45 def walkit(root, reporoot): | |
46 files, dirs = [], [] | |
47 | |
48 try: | |
9350
b789ea382fc0
inotify: server: use dirstate instead of repo
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9349
diff
changeset
|
49 fullpath = join(absroot, root) |
6239 | 50 for name, kind in osutil.listdir(fullpath): |
51 if kind == stat.S_IFDIR: | |
52 if name == '.hg': | |
8325
f2559645643a
inotify: inotify.server.walk() simplify control flow
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8324
diff
changeset
|
53 if not reporoot: |
8323
589a82fb02a2
inotify: inotify.server.walk*() cleanup
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8322
diff
changeset
|
54 return |
8325
f2559645643a
inotify: inotify.server.walk() simplify control flow
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8324
diff
changeset
|
55 else: |
f2559645643a
inotify: inotify.server.walk() simplify control flow
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8324
diff
changeset
|
56 dirs.append(name) |
8381
f52fcc864df4
inotify: server.walk(): use yield instead of for
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8336
diff
changeset
|
57 path = join(root, name) |
9350
b789ea382fc0
inotify: server: use dirstate instead of repo
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9349
diff
changeset
|
58 if dirstate._ignore(path): |
8381
f52fcc864df4
inotify: server.walk(): use yield instead of for
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8336
diff
changeset
|
59 continue |
f52fcc864df4
inotify: server.walk(): use yield instead of for
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8336
diff
changeset
|
60 for result in walkit(path, False): |
f52fcc864df4
inotify: server.walk(): use yield instead of for
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8336
diff
changeset
|
61 yield result |
6239 | 62 elif kind in (stat.S_IFREG, stat.S_IFLNK): |
8334
0695288e8c37
inotify: inotify.server.walk() filetype is never used, do not yield it
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8325
diff
changeset
|
63 files.append(name) |
8324
b923d599c309
inotify: inotify.server.walk*() remove unnecessary var
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8323
diff
changeset
|
64 yield fullpath, dirs, files |
6239 | 65 |
66 except OSError, err: | |
9116
f90bbf1ea09f
inotify: fix issue1375, add a test.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9115
diff
changeset
|
67 if err.errno == errno.ENOTDIR: |
f90bbf1ea09f
inotify: fix issue1375, add a test.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9115
diff
changeset
|
68 # fullpath was a directory, but has since been replaced |
f90bbf1ea09f
inotify: fix issue1375, add a test.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9115
diff
changeset
|
69 # by a file. |
f90bbf1ea09f
inotify: fix issue1375, add a test.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9115
diff
changeset
|
70 yield fullpath, dirs, files |
f90bbf1ea09f
inotify: fix issue1375, add a test.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9115
diff
changeset
|
71 elif err.errno not in walk_ignored_errors: |
6239 | 72 raise |
8320
a1305c1c8d8e
inotify: inotify.server.walk() simplify algorithm
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8319
diff
changeset
|
73 |
a1305c1c8d8e
inotify: inotify.server.walk() simplify algorithm
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8319
diff
changeset
|
74 return walkit(root, root == '') |
6239 | 75 |
9115
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
76 class directory(object): |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
77 """ |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
78 Representing a directory |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
79 |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
80 * path is the relative path from repo root to this directory |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
81 * files is a dict listing the files in this directory |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
82 - keys are file names |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
83 - values are file status |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
84 * dirs is a dict listing the subdirectories |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
85 - key are subdirectories names |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
86 - values are directory objects |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
87 """ |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
88 def __init__(self, relpath=''): |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
89 self.path = relpath |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
90 self.files = {} |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
91 self.dirs = {} |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
92 |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
93 def dir(self, relpath): |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
94 """ |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
95 Returns the directory contained at the relative path relpath. |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
96 Creates the intermediate directories if necessary. |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
97 """ |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
98 if not relpath: |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
99 return self |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
100 l = relpath.split('/') |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
101 ret = self |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
102 while l: |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
103 next = l.pop(0) |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
104 try: |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
105 ret = ret.dirs[next] |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
106 except KeyError: |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
107 d = directory(join(ret.path, next)) |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
108 ret.dirs[next] = d |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
109 ret = d |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
110 return ret |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
111 |
9854
95e1867f765b
inotify: mark directories visited during lookup (issue1844)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9514
diff
changeset
|
112 def walk(self, states, visited=None): |
9115
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
113 """ |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
114 yield (filename, status) pairs for items in the trees |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
115 that have status in states. |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
116 filenames are relative to the repo root |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
117 """ |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
118 for file, st in self.files.iteritems(): |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
119 if st in states: |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
120 yield join(self.path, file), st |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
121 for dir in self.dirs.itervalues(): |
9854
95e1867f765b
inotify: mark directories visited during lookup (issue1844)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9514
diff
changeset
|
122 if visited is not None: |
95e1867f765b
inotify: mark directories visited during lookup (issue1844)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9514
diff
changeset
|
123 visited.add(dir.path) |
9115
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
124 for e in dir.walk(states): |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
125 yield e |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
126 |
9854
95e1867f765b
inotify: mark directories visited during lookup (issue1844)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9514
diff
changeset
|
127 def lookup(self, states, path, visited): |
9115
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
128 """ |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
129 yield root-relative filenames that match path, and whose |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
130 status are in states: |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
131 * if path is a file, yield path |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
132 * if path is a directory, yield directory files |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
133 * if path is not tracked, yield nothing |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
134 """ |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
135 if path[-1] == '/': |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
136 path = path[:-1] |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
137 |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
138 paths = path.split('/') |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
139 |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
140 # we need to check separately for last node |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
141 last = paths.pop() |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
142 |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
143 tree = self |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
144 try: |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
145 for dir in paths: |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
146 tree = tree.dirs[dir] |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
147 except KeyError: |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
148 # path is not tracked |
9854
95e1867f765b
inotify: mark directories visited during lookup (issue1844)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9514
diff
changeset
|
149 visited.add(tree.path) |
9115
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
150 return |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
151 |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
152 try: |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
153 # if path is a directory, walk it |
9854
95e1867f765b
inotify: mark directories visited during lookup (issue1844)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9514
diff
changeset
|
154 target = tree.dirs[last] |
95e1867f765b
inotify: mark directories visited during lookup (issue1844)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9514
diff
changeset
|
155 visited.add(target.path) |
95e1867f765b
inotify: mark directories visited during lookup (issue1844)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9514
diff
changeset
|
156 for file, st in target.walk(states, visited): |
9115
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
157 yield file |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
158 except KeyError: |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
159 try: |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
160 if tree.files[last] in states: |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
161 # path is a file |
9854
95e1867f765b
inotify: mark directories visited during lookup (issue1844)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9514
diff
changeset
|
162 visited.add(tree.path) |
9115
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
163 yield path |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
164 except KeyError: |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
165 # path is not tracked |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
166 pass |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
167 |
9933
2e7902158af9
inotify: create a common, OS-independent server entry point
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9900
diff
changeset
|
168 class repowatcher(object): |
8610
8ef1f63e554c
inotify: server: use a common 'pollable' interface for server & repowatcher
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8609
diff
changeset
|
169 """ |
8ef1f63e554c
inotify: server: use a common 'pollable' interface for server & repowatcher
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8609
diff
changeset
|
170 Watches inotify events |
8ef1f63e554c
inotify: server: use a common 'pollable' interface for server & repowatcher
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8609
diff
changeset
|
171 """ |
6239 | 172 statuskeys = 'almr!?' |
173 | |
9350
b789ea382fc0
inotify: server: use dirstate instead of repo
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9349
diff
changeset
|
174 def __init__(self, ui, dirstate, root): |
6239 | 175 self.ui = ui |
9350
b789ea382fc0
inotify: server: use dirstate instead of repo
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9349
diff
changeset
|
176 self.dirstate = dirstate |
b789ea382fc0
inotify: server: use dirstate instead of repo
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9349
diff
changeset
|
177 |
b789ea382fc0
inotify: server: use dirstate instead of repo
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9349
diff
changeset
|
178 self.wprefix = join(root, '') |
9349
56fb15ad8fb1
inotify: server: use wprefix everywhere, introduce prefixlen
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9348
diff
changeset
|
179 self.prefixlen = len(self.wprefix) |
6239 | 180 |
9115
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
181 self.tree = directory() |
6239 | 182 self.statcache = {} |
9115
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
183 self.statustrees = dict([(s, directory()) for s in self.statuskeys]) |
6239 | 184 |
9933
2e7902158af9
inotify: create a common, OS-independent server entry point
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9900
diff
changeset
|
185 self.ds_info = self.dirstate_info() |
2e7902158af9
inotify: create a common, OS-independent server entry point
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9900
diff
changeset
|
186 |
6239 | 187 self.last_event = None |
188 | |
189 | |
9933
2e7902158af9
inotify: create a common, OS-independent server entry point
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9900
diff
changeset
|
190 def handle_timeout(self): |
2e7902158af9
inotify: create a common, OS-independent server entry point
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9900
diff
changeset
|
191 pass |
6239 | 192 |
193 def dirstate_info(self): | |
194 try: | |
9350
b789ea382fc0
inotify: server: use dirstate instead of repo
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9349
diff
changeset
|
195 st = os.lstat(self.wprefix + '.hg/dirstate') |
6239 | 196 return st.st_mtime, st.st_ino |
197 except OSError, err: | |
198 if err.errno != errno.ENOENT: | |
199 raise | |
200 return 0, 0 | |
201 | |
202 def filestatus(self, fn, st): | |
203 try: | |
9350
b789ea382fc0
inotify: server: use dirstate instead of repo
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9349
diff
changeset
|
204 type_, mode, size, time = self.dirstate._map[fn][:4] |
6239 | 205 except KeyError: |
206 type_ = '?' | |
207 if type_ == 'n': | |
208 st_mode, st_size, st_mtime = st | |
7082
be81b4788115
inotify: fix confusion on files in lookup state
Matt Mackall <mpm@selenic.com>
parents:
6998
diff
changeset
|
209 if size == -1: |
be81b4788115
inotify: fix confusion on files in lookup state
Matt Mackall <mpm@selenic.com>
parents:
6998
diff
changeset
|
210 return 'l' |
6239 | 211 if size and (size != st_size or (mode ^ st_mode) & 0100): |
212 return 'm' | |
213 if time != int(st_mtime): | |
214 return 'l' | |
215 return 'n' | |
9350
b789ea382fc0
inotify: server: use dirstate instead of repo
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9349
diff
changeset
|
216 if type_ == '?' and self.dirstate._ignore(fn): |
6239 | 217 return 'i' |
218 return type_ | |
219 | |
8599
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
220 def updatefile(self, wfn, osstat): |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
221 ''' |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
222 update the file entry of an existing file. |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
223 |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
224 osstat: (mode, size, time) tuple, as returned by os.lstat(wfn) |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
225 ''' |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
226 |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
227 self._updatestatus(wfn, self.filestatus(wfn, osstat)) |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
228 |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
229 def deletefile(self, wfn, oldstatus): |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
230 ''' |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
231 update the entry of a file which has been deleted. |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
232 |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
233 oldstatus: char in statuskeys, status of the file before deletion |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
234 ''' |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
235 if oldstatus == 'r': |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
236 newstatus = 'r' |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
237 elif oldstatus in 'almn': |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
238 newstatus = '!' |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
239 else: |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
240 newstatus = None |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
241 |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
242 self.statcache.pop(wfn, None) |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
243 self._updatestatus(wfn, newstatus) |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
244 |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
245 def _updatestatus(self, wfn, newstatus): |
8382
6f44b1adc948
inotify: RepoWatcher.updatestatus: document & use meaningful parameter names
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8381
diff
changeset
|
246 ''' |
9115
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
247 Update the stored status of a file. |
8382
6f44b1adc948
inotify: RepoWatcher.updatestatus: document & use meaningful parameter names
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8381
diff
changeset
|
248 |
8599
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
249 newstatus: - char in (statuskeys + 'ni'), new status to apply. |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
250 - or None, to stop tracking wfn |
8382
6f44b1adc948
inotify: RepoWatcher.updatestatus: document & use meaningful parameter names
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8381
diff
changeset
|
251 ''' |
8787
9aca76502280
inotify: server: move split() out of server
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8786
diff
changeset
|
252 root, fn = split(wfn) |
9115
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
253 d = self.tree.dir(root) |
8599
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
254 |
9115
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
255 oldstatus = d.files.get(fn) |
8599
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
256 # oldstatus can be either: |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
257 # - None : fn is new |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
258 # - a char in statuskeys: fn is a (tracked) file |
1f706b1b62f3
inotify: server: refactor updatestatus()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8557
diff
changeset
|
259 |
8382
6f44b1adc948
inotify: RepoWatcher.updatestatus: document & use meaningful parameter names
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8381
diff
changeset
|
260 if self.ui.debugflag and oldstatus != newstatus: |
9115
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
261 self.ui.note(_('status: %r %s -> %s\n') % |
8382
6f44b1adc948
inotify: RepoWatcher.updatestatus: document & use meaningful parameter names
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8381
diff
changeset
|
262 (wfn, oldstatus, newstatus)) |
9115
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
263 |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
264 if oldstatus and oldstatus in self.statuskeys \ |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
265 and oldstatus != newstatus: |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
266 del self.statustrees[oldstatus].dir(root).files[fn] |
9348
954f7a879495
inotify: server._updatestatus: simplify control flow
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9117
diff
changeset
|
267 |
954f7a879495
inotify: server._updatestatus: simplify control flow
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9117
diff
changeset
|
268 if newstatus in (None, 'i'): |
954f7a879495
inotify: server._updatestatus: simplify control flow
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9117
diff
changeset
|
269 d.files.pop(fn, None) |
954f7a879495
inotify: server._updatestatus: simplify control flow
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9117
diff
changeset
|
270 elif oldstatus != newstatus: |
9115
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
271 d.files[fn] = newstatus |
9348
954f7a879495
inotify: server._updatestatus: simplify control flow
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9117
diff
changeset
|
272 if newstatus != 'n': |
954f7a879495
inotify: server._updatestatus: simplify control flow
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9117
diff
changeset
|
273 self.statustrees[newstatus].dir(root).files[fn] = newstatus |
7892
67e59a9886d5
Fixing issue1542, adding a relevant test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7451
diff
changeset
|
274 |
6239 | 275 def check_deleted(self, key): |
276 # Files that had been deleted but were present in the dirstate | |
277 # may have vanished from the dirstate; we must clean them up. | |
278 nuke = [] | |
9115
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
279 for wfn, ignore in self.statustrees[key].walk(key): |
9350
b789ea382fc0
inotify: server: use dirstate instead of repo
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9349
diff
changeset
|
280 if wfn not in self.dirstate: |
6239 | 281 nuke.append(wfn) |
282 for wfn in nuke: | |
8787
9aca76502280
inotify: server: move split() out of server
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8786
diff
changeset
|
283 root, fn = split(wfn) |
9115
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
284 del self.statustrees[key].dir(root).files[fn] |
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
285 del self.tree.dir(root).files[fn] |
6287
c86207d41512
Spacing cleanup
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6239
diff
changeset
|
286 |
6239 | 287 def update_hgignore(self): |
288 # An update of the ignore file can potentially change the | |
289 # states of all unknown and ignored files. | |
290 | |
291 # XXX If the user has other ignore files outside the repo, or | |
292 # changes their list of ignore files at run time, we'll | |
293 # potentially never see changes to them. We could get the | |
294 # client to report to us what ignore data they're using. | |
295 # But it's easier to do nothing than to open that can of | |
296 # worms. | |
297 | |
9350
b789ea382fc0
inotify: server: use dirstate instead of repo
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9349
diff
changeset
|
298 if '_ignore' in self.dirstate.__dict__: |
b789ea382fc0
inotify: server: use dirstate instead of repo
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9349
diff
changeset
|
299 delattr(self.dirstate, '_ignore') |
6961
12163fb21fce
i18n: mark strings for translation in inotify extension
Martin Geisler <mg@daimi.au.dk>
parents:
6909
diff
changeset
|
300 self.ui.note(_('rescanning due to .hgignore change\n')) |
8604
578f2a0049cd
inotify: do not recurse in handle_timeout(): call it explicitely, not in scan()
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8600
diff
changeset
|
301 self.handle_timeout() |
6239 | 302 self.scan() |
6287
c86207d41512
Spacing cleanup
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6239
diff
changeset
|
303 |
6239 | 304 def getstat(self, wpath): |
305 try: | |
306 return self.statcache[wpath] | |
307 except KeyError: | |
308 try: | |
309 return self.stat(wpath) | |
310 except OSError, err: | |
311 if err.errno != errno.ENOENT: | |
312 raise | |
6287
c86207d41512
Spacing cleanup
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6239
diff
changeset
|
313 |
6239 | 314 def stat(self, wpath): |
315 try: | |
316 st = os.lstat(join(self.wprefix, wpath)) | |
317 ret = st.st_mode, st.st_size, st.st_mtime | |
318 self.statcache[wpath] = ret | |
319 return ret | |
7280
810ca383da9c
remove unused variables
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7220
diff
changeset
|
320 except OSError: |
6239 | 321 self.statcache.pop(wpath, None) |
322 raise | |
6287
c86207d41512
Spacing cleanup
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6239
diff
changeset
|
323 |
9933
2e7902158af9
inotify: create a common, OS-independent server entry point
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9900
diff
changeset
|
324 class socketlistener(object): |
8610
8ef1f63e554c
inotify: server: use a common 'pollable' interface for server & repowatcher
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8609
diff
changeset
|
325 """ |
8ef1f63e554c
inotify: server: use a common 'pollable' interface for server & repowatcher
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8609
diff
changeset
|
326 Listens for client queries on unix socket inotify.sock |
8ef1f63e554c
inotify: server: use a common 'pollable' interface for server & repowatcher
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8609
diff
changeset
|
327 """ |
9350
b789ea382fc0
inotify: server: use dirstate instead of repo
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9349
diff
changeset
|
328 def __init__(self, ui, root, repowatcher, timeout): |
6239 | 329 self.ui = ui |
8335
713ec3f9c9de
inotify: Clarify the use of "watcher" name.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8334
diff
changeset
|
330 self.repowatcher = repowatcher |
6239 | 331 self.sock = socket.socket(socket.AF_UNIX) |
9350
b789ea382fc0
inotify: server: use dirstate instead of repo
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9349
diff
changeset
|
332 self.sockpath = join(root, '.hg/inotify.sock') |
6997
9c4e488f105e
inotify: workaround ENAMETOOLONG by using symlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6994
diff
changeset
|
333 self.realsockpath = None |
6239 | 334 try: |
335 self.sock.bind(self.sockpath) | |
336 except socket.error, err: | |
337 if err[0] == errno.EADDRINUSE: | |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
338 raise AlreadyStartedException(_('cannot start: socket is ' |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
339 'already bound')) |
6997
9c4e488f105e
inotify: workaround ENAMETOOLONG by using symlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6994
diff
changeset
|
340 if err[0] == "AF_UNIX path too long": |
9900
8939900073a8
inotify: improve error messages
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9897
diff
changeset
|
341 if os.path.islink(self.sockpath) and \ |
8939900073a8
inotify: improve error messages
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9897
diff
changeset
|
342 not os.path.exists(self.sockpath): |
8939900073a8
inotify: improve error messages
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9897
diff
changeset
|
343 raise util.Abort('inotify-server: cannot start: ' |
8939900073a8
inotify: improve error messages
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9897
diff
changeset
|
344 '.hg/inotify.sock is a broken symlink') |
6997
9c4e488f105e
inotify: workaround ENAMETOOLONG by using symlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6994
diff
changeset
|
345 tempdir = tempfile.mkdtemp(prefix="hg-inotify-") |
9c4e488f105e
inotify: workaround ENAMETOOLONG by using symlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6994
diff
changeset
|
346 self.realsockpath = os.path.join(tempdir, "inotify.sock") |
9c4e488f105e
inotify: workaround ENAMETOOLONG by using symlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6994
diff
changeset
|
347 try: |
9c4e488f105e
inotify: workaround ENAMETOOLONG by using symlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6994
diff
changeset
|
348 self.sock.bind(self.realsockpath) |
9c4e488f105e
inotify: workaround ENAMETOOLONG by using symlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6994
diff
changeset
|
349 os.symlink(self.realsockpath, self.sockpath) |
9c4e488f105e
inotify: workaround ENAMETOOLONG by using symlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6994
diff
changeset
|
350 except (OSError, socket.error), inst: |
9c4e488f105e
inotify: workaround ENAMETOOLONG by using symlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6994
diff
changeset
|
351 try: |
9c4e488f105e
inotify: workaround ENAMETOOLONG by using symlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6994
diff
changeset
|
352 os.unlink(self.realsockpath) |
9c4e488f105e
inotify: workaround ENAMETOOLONG by using symlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6994
diff
changeset
|
353 except: |
9c4e488f105e
inotify: workaround ENAMETOOLONG by using symlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6994
diff
changeset
|
354 pass |
9c4e488f105e
inotify: workaround ENAMETOOLONG by using symlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6994
diff
changeset
|
355 os.rmdir(tempdir) |
9c4e488f105e
inotify: workaround ENAMETOOLONG by using symlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6994
diff
changeset
|
356 if inst.errno == errno.EEXIST: |
9900
8939900073a8
inotify: improve error messages
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9897
diff
changeset
|
357 raise AlreadyStartedException(_('cannot start: tried ' |
8939900073a8
inotify: improve error messages
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9897
diff
changeset
|
358 'linking .hg/inotify.sock to a temporary socket but' |
8939900073a8
inotify: improve error messages
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9897
diff
changeset
|
359 ' .hg/inotify.sock already exists')) |
6997
9c4e488f105e
inotify: workaround ENAMETOOLONG by using symlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6994
diff
changeset
|
360 raise |
9c4e488f105e
inotify: workaround ENAMETOOLONG by using symlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6994
diff
changeset
|
361 else: |
9c4e488f105e
inotify: workaround ENAMETOOLONG by using symlinks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6994
diff
changeset
|
362 raise |
6239 | 363 self.sock.listen(5) |
364 self.fileno = self.sock.fileno | |
365 | |
8554
47d7347484f5
inotify: put STAT-specific query answer generation part in its own method
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8553
diff
changeset
|
366 def answer_stat_query(self, cs): |
6239 | 367 names = cs.read().split('\0') |
6287
c86207d41512
Spacing cleanup
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6239
diff
changeset
|
368 |
6239 | 369 states = names.pop() |
370 | |
371 self.ui.note(_('answering query for %r\n') % states) | |
372 | |
9854
95e1867f765b
inotify: mark directories visited during lookup (issue1844)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9514
diff
changeset
|
373 visited = set() |
6239 | 374 if not names: |
375 def genresult(states, tree): | |
9115
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
376 for fn, state in tree.walk(states): |
6239 | 377 yield fn |
378 else: | |
379 def genresult(states, tree): | |
380 for fn in names: | |
9854
95e1867f765b
inotify: mark directories visited during lookup (issue1844)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9514
diff
changeset
|
381 for f in tree.lookup(states, fn, visited): |
9115
b55d44719b47
inotify: server: new data structure to keep track of changes.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8953
diff
changeset
|
382 yield f |
6239 | 383 |
8554
47d7347484f5
inotify: put STAT-specific query answer generation part in its own method
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8553
diff
changeset
|
384 return ['\0'.join(r) for r in [ |
8335
713ec3f9c9de
inotify: Clarify the use of "watcher" name.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8334
diff
changeset
|
385 genresult('l', self.repowatcher.statustrees['l']), |
713ec3f9c9de
inotify: Clarify the use of "watcher" name.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8334
diff
changeset
|
386 genresult('m', self.repowatcher.statustrees['m']), |
713ec3f9c9de
inotify: Clarify the use of "watcher" name.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8334
diff
changeset
|
387 genresult('a', self.repowatcher.statustrees['a']), |
713ec3f9c9de
inotify: Clarify the use of "watcher" name.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8334
diff
changeset
|
388 genresult('r', self.repowatcher.statustrees['r']), |
713ec3f9c9de
inotify: Clarify the use of "watcher" name.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8334
diff
changeset
|
389 genresult('!', self.repowatcher.statustrees['!']), |
713ec3f9c9de
inotify: Clarify the use of "watcher" name.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8334
diff
changeset
|
390 '?' in states |
713ec3f9c9de
inotify: Clarify the use of "watcher" name.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8334
diff
changeset
|
391 and genresult('?', self.repowatcher.statustrees['?']) |
713ec3f9c9de
inotify: Clarify the use of "watcher" name.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8334
diff
changeset
|
392 or [], |
6239 | 393 [], |
8335
713ec3f9c9de
inotify: Clarify the use of "watcher" name.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8334
diff
changeset
|
394 'c' in states and genresult('n', self.repowatcher.tree) or [], |
9854
95e1867f765b
inotify: mark directories visited during lookup (issue1844)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9514
diff
changeset
|
395 visited |
6239 | 396 ]] |
397 | |
8555
3e09bc5fee12
inotify: introduce debuginotify, which lists which paths are under watch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8554
diff
changeset
|
398 def answer_dbug_query(self): |
3e09bc5fee12
inotify: introduce debuginotify, which lists which paths are under watch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8554
diff
changeset
|
399 return ['\0'.join(self.repowatcher.debug())] |
3e09bc5fee12
inotify: introduce debuginotify, which lists which paths are under watch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8554
diff
changeset
|
400 |
9933
2e7902158af9
inotify: create a common, OS-independent server entry point
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9900
diff
changeset
|
401 def accept_connection(self): |
8554
47d7347484f5
inotify: put STAT-specific query answer generation part in its own method
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8553
diff
changeset
|
402 sock, addr = self.sock.accept() |
47d7347484f5
inotify: put STAT-specific query answer generation part in its own method
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8553
diff
changeset
|
403 |
47d7347484f5
inotify: put STAT-specific query answer generation part in its own method
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8553
diff
changeset
|
404 cs = common.recvcs(sock) |
47d7347484f5
inotify: put STAT-specific query answer generation part in its own method
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8553
diff
changeset
|
405 version = ord(cs.read(1)) |
47d7347484f5
inotify: put STAT-specific query answer generation part in its own method
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8553
diff
changeset
|
406 |
47d7347484f5
inotify: put STAT-specific query answer generation part in its own method
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8553
diff
changeset
|
407 if version != common.version: |
47d7347484f5
inotify: put STAT-specific query answer generation part in its own method
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8553
diff
changeset
|
408 self.ui.warn(_('received query from incompatible client ' |
47d7347484f5
inotify: put STAT-specific query answer generation part in its own method
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8553
diff
changeset
|
409 'version %d\n') % version) |
8952
7c7a672e9db7
inotify: return version to client even when not matching
Simon Heimberg <simohe@besonet.ch>
parents:
8794
diff
changeset
|
410 try: |
7c7a672e9db7
inotify: return version to client even when not matching
Simon Heimberg <simohe@besonet.ch>
parents:
8794
diff
changeset
|
411 # try to send back our version to the client |
7c7a672e9db7
inotify: return version to client even when not matching
Simon Heimberg <simohe@besonet.ch>
parents:
8794
diff
changeset
|
412 # this way, the client too is informed of the mismatch |
7c7a672e9db7
inotify: return version to client even when not matching
Simon Heimberg <simohe@besonet.ch>
parents:
8794
diff
changeset
|
413 sock.sendall(chr(common.version)) |
7c7a672e9db7
inotify: return version to client even when not matching
Simon Heimberg <simohe@besonet.ch>
parents:
8794
diff
changeset
|
414 except: |
7c7a672e9db7
inotify: return version to client even when not matching
Simon Heimberg <simohe@besonet.ch>
parents:
8794
diff
changeset
|
415 pass |
8554
47d7347484f5
inotify: put STAT-specific query answer generation part in its own method
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8553
diff
changeset
|
416 return |
47d7347484f5
inotify: put STAT-specific query answer generation part in its own method
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8553
diff
changeset
|
417 |
47d7347484f5
inotify: put STAT-specific query answer generation part in its own method
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8553
diff
changeset
|
418 type = cs.read(4) |
47d7347484f5
inotify: put STAT-specific query answer generation part in its own method
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8553
diff
changeset
|
419 |
47d7347484f5
inotify: put STAT-specific query answer generation part in its own method
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8553
diff
changeset
|
420 if type == 'STAT': |
47d7347484f5
inotify: put STAT-specific query answer generation part in its own method
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8553
diff
changeset
|
421 results = self.answer_stat_query(cs) |
8555
3e09bc5fee12
inotify: introduce debuginotify, which lists which paths are under watch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8554
diff
changeset
|
422 elif type == 'DBUG': |
3e09bc5fee12
inotify: introduce debuginotify, which lists which paths are under watch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8554
diff
changeset
|
423 results = self.answer_dbug_query() |
8554
47d7347484f5
inotify: put STAT-specific query answer generation part in its own method
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8553
diff
changeset
|
424 else: |
47d7347484f5
inotify: put STAT-specific query answer generation part in its own method
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8553
diff
changeset
|
425 self.ui.warn(_('unrecognized query type: %s\n') % type) |
47d7347484f5
inotify: put STAT-specific query answer generation part in its own method
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8553
diff
changeset
|
426 return |
47d7347484f5
inotify: put STAT-specific query answer generation part in its own method
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8553
diff
changeset
|
427 |
6239 | 428 try: |
429 try: | |
8386
4aad982111b6
inotify: Abstract the layer format and sizes to a inotify.common dictionary
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8385
diff
changeset
|
430 v = chr(common.version) |
4aad982111b6
inotify: Abstract the layer format and sizes to a inotify.common dictionary
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8385
diff
changeset
|
431 |
8553
e387ecd7a6ed
inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8386
diff
changeset
|
432 sock.sendall(v + type + struct.pack(common.resphdrfmts[type], |
e387ecd7a6ed
inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8386
diff
changeset
|
433 *map(len, results))) |
6239 | 434 sock.sendall(''.join(results)) |
435 finally: | |
436 sock.shutdown(socket.SHUT_WR) | |
437 except socket.error, err: | |
438 if err[0] != errno.EPIPE: | |
439 raise | |
440 | |
9933
2e7902158af9
inotify: create a common, OS-independent server entry point
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9900
diff
changeset
|
441 if sys.platform == 'linux2': |
2e7902158af9
inotify: create a common, OS-independent server entry point
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9900
diff
changeset
|
442 import linuxserver as _server |
2e7902158af9
inotify: create a common, OS-independent server entry point
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9900
diff
changeset
|
443 else: |
2e7902158af9
inotify: create a common, OS-independent server entry point
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9900
diff
changeset
|
444 raise ImportError |
6239 | 445 |
9933
2e7902158af9
inotify: create a common, OS-independent server entry point
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9900
diff
changeset
|
446 master = _server.master |
6239 | 447 |
9514
7c01599dd340
inotify: use cmdutil.service instead of local daemonizing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9351
diff
changeset
|
448 def start(ui, dirstate, root, opts): |
10494
08064db9f005
inotify/inserve: implement --timeout-idle option (issue885)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
449 timeout = opts.get('idle_timeout') |
9514
7c01599dd340
inotify: use cmdutil.service instead of local daemonizing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9351
diff
changeset
|
450 if timeout: |
10494
08064db9f005
inotify/inserve: implement --timeout-idle option (issue885)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
451 timeout = float(timeout) * 60000 |
08064db9f005
inotify/inserve: implement --timeout-idle option (issue885)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
452 else: |
08064db9f005
inotify/inserve: implement --timeout-idle option (issue885)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
453 timeout = None |
9514
7c01599dd340
inotify: use cmdutil.service instead of local daemonizing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9351
diff
changeset
|
454 |
7c01599dd340
inotify: use cmdutil.service instead of local daemonizing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9351
diff
changeset
|
455 class service(object): |
7c01599dd340
inotify: use cmdutil.service instead of local daemonizing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9351
diff
changeset
|
456 def init(self): |
7451
fca9947652ce
inotify: close most file descriptors when autostarting
Brendan Cully <brendan@kublai.com>
parents:
7420
diff
changeset
|
457 try: |
9514
7c01599dd340
inotify: use cmdutil.service instead of local daemonizing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9351
diff
changeset
|
458 self.master = master(ui, dirstate, root, timeout) |
7c01599dd340
inotify: use cmdutil.service instead of local daemonizing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9351
diff
changeset
|
459 except AlreadyStartedException, inst: |
9900
8939900073a8
inotify: improve error messages
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9897
diff
changeset
|
460 raise util.Abort("inotify-server: %s" % inst) |
6239 | 461 |
9514
7c01599dd340
inotify: use cmdutil.service instead of local daemonizing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9351
diff
changeset
|
462 def run(self): |
7c01599dd340
inotify: use cmdutil.service instead of local daemonizing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9351
diff
changeset
|
463 try: |
10494
08064db9f005
inotify/inserve: implement --timeout-idle option (issue885)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
464 try: |
08064db9f005
inotify/inserve: implement --timeout-idle option (issue885)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
465 self.master.run() |
08064db9f005
inotify/inserve: implement --timeout-idle option (issue885)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
466 except TimeoutException: |
08064db9f005
inotify/inserve: implement --timeout-idle option (issue885)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
467 pass |
9514
7c01599dd340
inotify: use cmdutil.service instead of local daemonizing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9351
diff
changeset
|
468 finally: |
7c01599dd340
inotify: use cmdutil.service instead of local daemonizing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9351
diff
changeset
|
469 self.master.shutdown() |
6239 | 470 |
9514
7c01599dd340
inotify: use cmdutil.service instead of local daemonizing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9351
diff
changeset
|
471 if 'inserve' not in sys.argv: |
10239
8e4be44a676f
Find right hg command for detached process
Patrick Mezard <pmezard@gmail.com>
parents:
10090
diff
changeset
|
472 runargs = util.hgcmd() + ['inserve', '-R', root] |
9897
97eda2133a9b
inotify: add a inotify.pidfile configuration possibility
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9854
diff
changeset
|
473 else: |
10239
8e4be44a676f
Find right hg command for detached process
Patrick Mezard <pmezard@gmail.com>
parents:
10090
diff
changeset
|
474 runargs = util.hgcmd() + sys.argv[1:] |
9897
97eda2133a9b
inotify: add a inotify.pidfile configuration possibility
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9854
diff
changeset
|
475 |
97eda2133a9b
inotify: add a inotify.pidfile configuration possibility
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9854
diff
changeset
|
476 pidfile = ui.config('inotify', 'pidfile') |
97eda2133a9b
inotify: add a inotify.pidfile configuration possibility
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9854
diff
changeset
|
477 if opts['daemon'] and pidfile is not None and 'pid-file' not in runargs: |
97eda2133a9b
inotify: add a inotify.pidfile configuration possibility
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9854
diff
changeset
|
478 runargs.append("--pid-file=%s" % pidfile) |
6239 | 479 |
9514
7c01599dd340
inotify: use cmdutil.service instead of local daemonizing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9351
diff
changeset
|
480 service = service() |
7c01599dd340
inotify: use cmdutil.service instead of local daemonizing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9351
diff
changeset
|
481 logfile = ui.config('inotify', 'log') |
10013
b2e87fde6806
run-tests: --inotify: use inotify.appendpid to append pids to $DAEMON_PIDS
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9933
diff
changeset
|
482 |
b2e87fde6806
run-tests: --inotify: use inotify.appendpid to append pids to $DAEMON_PIDS
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9933
diff
changeset
|
483 appendpid = ui.configbool('inotify', 'appendpid', False) |
b2e87fde6806
run-tests: --inotify: use inotify.appendpid to append pids to $DAEMON_PIDS
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9933
diff
changeset
|
484 |
9514
7c01599dd340
inotify: use cmdutil.service instead of local daemonizing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9351
diff
changeset
|
485 cmdutil.service(opts, initfn=service.init, runfn=service.run, |
10013
b2e87fde6806
run-tests: --inotify: use inotify.appendpid to append pids to $DAEMON_PIDS
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9933
diff
changeset
|
486 logfile=logfile, runargs=runargs, appendpid=appendpid) |