annotate hgext/inotify/client.py @ 7166:fb3df69aa785

hgweb: nodeids should be aligned in raw changesets If they aren't it breaks hg import --exact Thanks to Jesper Noehr for noticing it.
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Sun, 19 Oct 2008 12:23:58 +0200
parents 6f4a253f2a64
children 59b4ae211584
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 # client.py - inotify status client
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 #
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
6 # This software may be used and distributed according to the terms
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
7 # of the GNU General Public License, incorporated herein by reference.
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
8
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
9 from mercurial.i18n import gettext as _
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
10 from mercurial import ui
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
11 import common
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
12 import os, select, socket, stat, struct, sys
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
13
6753
ed5ffb2c12f3 repo.status: eliminate list_
Matt Mackall <mpm@selenic.com>
parents: 6239
diff changeset
14 def query(ui, repo, names, match, ignored, clean, unknown=True):
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
15 sock = socket.socket(socket.AF_UNIX)
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
16 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
17 try:
ee308d44ad76 inotify: add client code for long pathname handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6239
diff changeset
18 sock.connect(sockpath)
ee308d44ad76 inotify: add client code for long pathname handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6239
diff changeset
19 except socket.error, err:
ee308d44ad76 inotify: add client code for long pathname handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6239
diff changeset
20 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
21 sockpath = os.readlink(sockpath)
ee308d44ad76 inotify: add client code for long pathname handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6239
diff changeset
22 sock.connect(sockpath)
ee308d44ad76 inotify: add client code for long pathname handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6239
diff changeset
23 else:
ee308d44ad76 inotify: add client code for long pathname handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6239
diff changeset
24 raise
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
25
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
26 def genquery():
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
27 for n in names or []:
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
28 yield n
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
29 states = 'almrx!'
6753
ed5ffb2c12f3 repo.status: eliminate list_
Matt Mackall <mpm@selenic.com>
parents: 6239
diff changeset
30 if ignored:
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
31 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
32 if clean: states += 'c'
6753
ed5ffb2c12f3 repo.status: eliminate list_
Matt Mackall <mpm@selenic.com>
parents: 6239
diff changeset
33 if unknown: states += '?'
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
34 yield states
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
35
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
36 req = '\0'.join(genquery())
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
37
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
38 sock.sendall(chr(common.version))
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
39 sock.sendall(req)
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
40 sock.shutdown(socket.SHUT_WR)
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
41
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
42 cs = common.recvcs(sock)
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
43 version = ord(cs.read(1))
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
44
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
45 if version != common.version:
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
46 ui.warn(_('(inotify: received response from incompatible server '
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
47 'version %d)\n') % version)
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
48 return None
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
49
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
50 try:
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
51 resphdr = struct.unpack(common.resphdrfmt, cs.read(common.resphdrsize))
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
52 except struct.error:
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
53 return None
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
54
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
55 def readnames(nbytes):
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
56 if nbytes:
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
57 names = cs.read(nbytes)
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
58 if names:
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
59 return filter(match, names.split('\0'))
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
60 return []
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
61
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
62 return map(readnames, resphdr)