annotate hgext/inotify/common.py @ 20501:8a9e0b523d2d

discovery: improve "note: unsynced remote changes!" warning This message frequently caused confusion. "unsynced" is not a well established user-facing concept in Mercurial and the message was not very specific or helpful. Instead, show a message like: remote has heads on branch 'default' that are not known locally: 6c0482d977a3 This message will also (when relevant) be shown before aborting on "push creates new remote head". A similar (but actually very different) message was addressed in 6b618aa08b6e.
author Mads Kiilerich <madski@unity3d.com>
date Thu, 06 Feb 2014 02:19:38 +0100
parents 25e572394f5c
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 # server.py - inotify common protocol code
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: 6239
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: 9854
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
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
9 import cStringIO, socket, struct
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
10
8553
e387ecd7a6ed inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
11 """
e387ecd7a6ed inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
12 Protocol between inotify clients and server:
e387ecd7a6ed inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
13
e387ecd7a6ed inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
14 Client sending query:
e387ecd7a6ed inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
15 1) send protocol version number
e387ecd7a6ed inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
16 2) send query type (string, 4 letters long)
e387ecd7a6ed inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
17 3) send query parameters:
e387ecd7a6ed inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
18 - For STAT, N+1 \0-separated strings:
e387ecd7a6ed inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
19 1) N different names that need checking
e387ecd7a6ed inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
20 2) 1 string containing all the status types to match
8555
3e09bc5fee12 inotify: introduce debuginotify, which lists which paths are under watch
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8553
diff changeset
21 - No parameter needed for DBUG
8553
e387ecd7a6ed inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
22
e387ecd7a6ed inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
23 Server sending query answer:
e387ecd7a6ed inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
24 1) send protocol version number
e387ecd7a6ed inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
25 2) send query type
e387ecd7a6ed inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
26 3) send struct.pack'ed headers describing the length of the content:
9854
95e1867f765b inotify: mark directories visited during lookup (issue1844)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8555
diff changeset
27 e.g. for STAT, receive 9 integers describing the length of the
95e1867f765b inotify: mark directories visited during lookup (issue1844)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8555
diff changeset
28 9 \0-separated string lists to be read:
95e1867f765b inotify: mark directories visited during lookup (issue1844)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8555
diff changeset
29 * one file list for each lmar!?ic status type
95e1867f765b inotify: mark directories visited during lookup (issue1844)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8555
diff changeset
30 * one list containing the directories visited during lookup
8553
e387ecd7a6ed inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
31
e387ecd7a6ed inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
32 """
e387ecd7a6ed inotify: change protocol so that different query types can be supported.
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8386
diff changeset
33
9854
95e1867f765b inotify: mark directories visited during lookup (issue1844)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8555
diff changeset
34 version = 3
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
35
8386
4aad982111b6 inotify: Abstract the layer format and sizes to a inotify.common dictionary
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8225
diff changeset
36 resphdrfmts = {
9854
95e1867f765b inotify: mark directories visited during lookup (issue1844)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8555
diff changeset
37 'STAT': '>lllllllll', # status requests
95e1867f765b inotify: mark directories visited during lookup (issue1844)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8555
diff changeset
38 'DBUG': '>l' # debugging queries
8386
4aad982111b6 inotify: Abstract the layer format and sizes to a inotify.common dictionary
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8225
diff changeset
39 }
4aad982111b6 inotify: Abstract the layer format and sizes to a inotify.common dictionary
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8225
diff changeset
40 resphdrsizes = dict((k, struct.calcsize(v))
4aad982111b6 inotify: Abstract the layer format and sizes to a inotify.common dictionary
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8225
diff changeset
41 for k, v in resphdrfmts.iteritems())
6239
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
42
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
43 def recvcs(sock):
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
44 cs = cStringIO.StringIO()
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
45 s = True
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
46 try:
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
47 while s:
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
48 s = sock.recv(65536)
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
49 cs.write(s)
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
50 finally:
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
51 sock.shutdown(socket.SHUT_RD)
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
52 cs.seek(0)
39cfcef4f463 Add inotify extension
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
53 return cs