author | Matt Mackall <mpm@selenic.com> |
Thu, 14 May 2009 13:21:17 -0500 | |
changeset 8409 | e84a8482c6f2 |
parent 8386 | 4aad982111b6 |
child 8551 | 7089d9727867 |
permissions | -rw-r--r-- |
6239 | 1 |
# client.py - inotify status client |
2 |
# |
|
3 |
# Copyright 2006, 2007, 2008 Bryan O'Sullivan <bos@serpentine.com> |
|
4 |
# Copyright 2007, 2008 Brendan Cully <brendan@kublai.com> |
|
5 |
# |
|
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8067
diff
changeset
|
6 |
# This software may be used and distributed according to the terms of the |
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8067
diff
changeset
|
7 |
# GNU General Public License version 2, incorporated herein by reference. |
6239 | 8 |
|
7225
59b4ae211584
i18n: import _ instead of gettext
Martin Geisler <mg@daimi.au.dk>
parents:
7145
diff
changeset
|
9 |
from mercurial.i18n import _ |
6239 | 10 |
import common |
7280
810ca383da9c
remove unused variables
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7225
diff
changeset
|
11 |
import os, socket, struct |
6239 | 12 |
|
6753
ed5ffb2c12f3
repo.status: eliminate list_
Matt Mackall <mpm@selenic.com>
parents:
6239
diff
changeset
|
13 |
def query(ui, repo, names, match, ignored, clean, unknown=True): |
6239 | 14 |
sock = socket.socket(socket.AF_UNIX) |
15 |
sockpath = repo.join('inotify.sock') |
|
7024
ee308d44ad76
inotify: add client code for long pathname handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6239
diff
changeset
|
16 |
try: |
ee308d44ad76
inotify: add client code for long pathname handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6239
diff
changeset
|
17 |
sock.connect(sockpath) |
ee308d44ad76
inotify: add client code for long pathname handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6239
diff
changeset
|
18 |
except socket.error, err: |
ee308d44ad76
inotify: add client code for long pathname handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6239
diff
changeset
|
19 |
if err[0] == "AF_UNIX path too long": |
ee308d44ad76
inotify: add client code for long pathname handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6239
diff
changeset
|
20 |
sockpath = os.readlink(sockpath) |
ee308d44ad76
inotify: add client code for long pathname handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6239
diff
changeset
|
21 |
sock.connect(sockpath) |
ee308d44ad76
inotify: add client code for long pathname handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6239
diff
changeset
|
22 |
else: |
ee308d44ad76
inotify: add client code for long pathname handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6239
diff
changeset
|
23 |
raise |
6239 | 24 |
|
25 |
def genquery(): |
|
8067
b084d6d6f345
inotify: files is always a list: 'files or []' is redundant
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7420
diff
changeset
|
26 |
for n in names: |
6239 | 27 |
yield n |
28 |
states = 'almrx!' |
|
6753
ed5ffb2c12f3
repo.status: eliminate list_
Matt Mackall <mpm@selenic.com>
parents:
6239
diff
changeset
|
29 |
if ignored: |
6239 | 30 |
raise ValueError('this is insanity') |
7145
6f4a253f2a64
inotify: fix status not showing "clean" files (issue907)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7027
diff
changeset
|
31 |
if clean: states += 'c' |
6753
ed5ffb2c12f3
repo.status: eliminate list_
Matt Mackall <mpm@selenic.com>
parents:
6239
diff
changeset
|
32 |
if unknown: states += '?' |
6239 | 33 |
yield states |
34 |
||
35 |
req = '\0'.join(genquery()) |
|
36 |
||
37 |
sock.sendall(chr(common.version)) |
|
38 |
sock.sendall(req) |
|
39 |
sock.shutdown(socket.SHUT_WR) |
|
40 |
||
41 |
cs = common.recvcs(sock) |
|
42 |
version = ord(cs.read(1)) |
|
43 |
||
44 |
if version != common.version: |
|
45 |
ui.warn(_('(inotify: received response from incompatible server ' |
|
46 |
'version %d)\n') % version) |
|
47 |
return None |
|
48 |
||
8386
4aad982111b6
inotify: Abstract the layer format and sizes to a inotify.common dictionary
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8225
diff
changeset
|
49 |
# only one type of request is supported for now |
4aad982111b6
inotify: Abstract the layer format and sizes to a inotify.common dictionary
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8225
diff
changeset
|
50 |
type = 'STAT' |
4aad982111b6
inotify: Abstract the layer format and sizes to a inotify.common dictionary
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8225
diff
changeset
|
51 |
hdrfmt = common.resphdrfmts[type] |
4aad982111b6
inotify: Abstract the layer format and sizes to a inotify.common dictionary
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8225
diff
changeset
|
52 |
hdrsize = common.resphdrsizes[type] |
6239 | 53 |
try: |
8386
4aad982111b6
inotify: Abstract the layer format and sizes to a inotify.common dictionary
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8225
diff
changeset
|
54 |
resphdr = struct.unpack(hdrfmt, cs.read(hdrsize)) |
6239 | 55 |
except struct.error: |
56 |
return None |
|
57 |
||
58 |
def readnames(nbytes): |
|
59 |
if nbytes: |
|
60 |
names = cs.read(nbytes) |
|
61 |
if names: |
|
62 |
return filter(match, names.split('\0')) |
|
63 |
return [] |
|
64 |
||
65 |
return map(readnames, resphdr) |