author | Sune Foldager <cryo@cyanite.org> |
Tue, 10 Feb 2009 14:21:27 +0100 | |
changeset 7749 | f32af51aaee5 |
parent 7420 | b4ac1e2cd38c |
child 8067 | b084d6d6f345 |
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 |
# |
|
6 |
# This software may be used and distributed according to the terms |
|
7 |
# of the GNU General Public License, incorporated herein by reference. |
|
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(): |
|
26 |
for n in names or []: |
|
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 |
||
49 |
try: |
|
50 |
resphdr = struct.unpack(common.resphdrfmt, cs.read(common.resphdrsize)) |
|
51 |
except struct.error: |
|
52 |
return None |
|
53 |
||
54 |
def readnames(nbytes): |
|
55 |
if nbytes: |
|
56 |
names = cs.read(nbytes) |
|
57 |
if names: |
|
58 |
return filter(match, names.split('\0')) |
|
59 |
return [] |
|
60 |
||
61 |
return map(readnames, resphdr) |